diff --git a/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/PublicationsConfig.java b/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/PublicationsConfig.java index a098360bc..c224d40ab 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/PublicationsConfig.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/PublicationsConfig.java @@ -26,6 +26,7 @@ public class PublicationsConfig extends AbstractConfig { private final Parameter defaultProceedingsFolder; private final Parameter defaultInProceedingsFolder; private final Parameter defaultArticlesInJournalFolder; + private final Parameter defaultPublicationsFolder; public PublicationsConfig() { attachOrgaUnitsStep = @@ -90,6 +91,11 @@ public class PublicationsConfig extends AbstractConfig { Parameter.OPTIONAL, null); + defaultPublicationsFolder = new IntegerParameter( + "com.arsdigita.cms.contenttypes.publications.default_publications_folder", + Parameter.OPTIONAL, + null); + register(attachOrgaUnitsStep); register(attachPublicationsStepTo); register(defaultAuthorsFolder); @@ -102,6 +108,7 @@ public class PublicationsConfig extends AbstractConfig { register(defaultProceedingsFolder); register(defaultInProceedingsFolder); register(defaultArticlesInJournalFolder); + register(defaultPublicationsFolder); loadInfo(); } @@ -129,7 +136,7 @@ public class PublicationsConfig extends AbstractConfig { return (Integer) get(defaultSeriesFolder); } } - + public Integer getDefaultPublisherFolder() { if (get(defaultPublisherFolder) == null) { return null; @@ -137,7 +144,7 @@ public class PublicationsConfig extends AbstractConfig { return (Integer) get(defaultPublisherFolder); } } - + public Integer getDefaultCollectedVolumesFolder() { if (get(defaultCollectedVolumesFolder) == null) { return null; @@ -145,7 +152,7 @@ public class PublicationsConfig extends AbstractConfig { return (Integer) get(defaultCollectedVolumesFolder); } } - + public Integer getDefaultJournalsFolder() { if (get(defaultJournalsFolder) == null) { return null; @@ -161,7 +168,7 @@ public class PublicationsConfig extends AbstractConfig { return (Integer) get(defaultArticlesInCollectedVolumeFolder); } } - + public Integer getDefaultOrganizationsFolder() { if (get(defaultOrganizationsFolder) == null) { return null; @@ -169,7 +176,7 @@ public class PublicationsConfig extends AbstractConfig { return (Integer) get(defaultOrganizationsFolder); } } - + public Integer getDefaultProceedingsFolder() { if (get(defaultProceedingsFolder) == null) { return null; @@ -177,7 +184,7 @@ public class PublicationsConfig extends AbstractConfig { return (Integer) get(defaultProceedingsFolder); } } - + public Integer getDefaultInProceedingsFolder() { if (get(defaultInProceedingsFolder) == null) { return null; @@ -185,12 +192,21 @@ public class PublicationsConfig extends AbstractConfig { return (Integer) get(defaultInProceedingsFolder); } } - - public Integer getDefaultArticlesInJournalFolder() { + + public Integer getDefaultArticlesInJournalFolder() { if (get(defaultArticlesInJournalFolder) == null) { return null; } else { return (Integer) get(defaultArticlesInJournalFolder); } } + + public Integer getDefaultPublicationsFolder() { + if (get(defaultPublicationsFolder) == null) { + return null; + } else { + return (Integer) get(defaultPublicationsFolder); + } + } + } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/PublicationsConfig_parameter.properties b/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/PublicationsConfig_parameter.properties index 0ac794325..e977a0e57 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/PublicationsConfig_parameter.properties +++ b/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/PublicationsConfig_parameter.properties @@ -56,4 +56,9 @@ com.arsdigita.cms.contenttypes.publications.default_inproceedings_folder.format com.arsdigita.cms.contenttypes.publications.default_articlesinjournal_folder.title = ID of the default folder for items created using the create pane of the ItemSearchWidget com.arsdigita.cms.contenttypes.publications.default_articlesinjournal_folder.purpose = Default folder for items created using the create pane of the ItemSearchWidget com.arsdigita.cms.contenttypes.publications.default_articlesinjournal_folder.example = 10002 -com.arsdigita.cms.contenttypes.publications.default_articlesinjournal_folder.format = Integer \ No newline at end of file +com.arsdigita.cms.contenttypes.publications.default_articlesinjournal_folder.format = Integer + +com.arsdigita.cms.contenttypes.publications.default_publications_folder.title = Default publications folder +com.arsdigita.cms.contenttypes.publications.default_publications_folder.purpose = Folder to put publications created using an importer in +com.arsdigita.cms.contenttypes.publications.default_publications_folder.example = 10002 +com.arsdigita.cms.contenttypes.publications.default_publications_folder.format = Integer \ No newline at end of file diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/ImporterCli.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/ImporterCli.java index 4a7e7cb4a..1d30429cf 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/ImporterCli.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/ImporterCli.java @@ -19,15 +19,16 @@ package com.arsdigita.cms.scipublications.importer; import com.arsdigita.cms.scipublications.imexporter.PublicationFormat; +import com.arsdigita.cms.scipublications.importer.report.ImportReport; import com.arsdigita.util.cmd.Program; import java.io.File; import java.io.IOException; +import java.io.PrintWriter; import java.util.List; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.apache.commons.io.FileUtils; -import org.apache.log4j.Logger; /** * @@ -36,7 +37,7 @@ import org.apache.log4j.Logger; */ public class ImporterCli extends Program { - private static final Logger LOGGER = Logger.getLogger(ImporterCli.class); + //private static final Logger LOGGER = Logger.getLogger(ImporterCli.class); private static final String PRETEND = "pretend"; private static final String PUBLISH = "publish"; private static final String LIST = "list"; @@ -57,7 +58,7 @@ public class ImporterCli extends Program { options.addOption(OptionBuilder .withLongOpt(LIST) .withDescription("List all available importers and exit") - .create()); + .create()); } public static void main(final String args[]) { @@ -66,23 +67,26 @@ public class ImporterCli extends Program { @Override protected void doRun(final CommandLine cmdLine) { - LOGGER.info("Publications Importer CLI tool."); + final PrintWriter writer = new PrintWriter(System.out); + final PrintWriter errWriter = new PrintWriter(System.err); + + writer.printf("Publications Importer CLI tool.\n"); if (cmdLine.hasOption(LIST)) { final List formats = SciPublicationsImporters.getInstance().getSupportedFormats(); - LOGGER.info("Supported formats:"); - for(PublicationFormat format : formats) { - LOGGER.info(String.format("%s, MIME type: %s, file extension: %s", format.getName(), - format.getMimeType().toString(), - format.getFileExtension())); + writer.printf("Supported formats:\n"); + for (PublicationFormat format : formats) { + writer.printf("%s, MIME type: %s, file extension: %s\n", format.getName(), + format.getMimeType().toString(), + format.getFileExtension()); } return; } - + final boolean pretend = cmdLine.hasOption(PRETEND); final boolean publish = cmdLine.hasOption(PUBLISH); if (cmdLine.getArgs().length != 1) { - LOGGER.error("Missing file/directory to import."); + errWriter.printf("Missing file/directory to import.\n"); help(System.err); return; } @@ -93,6 +97,9 @@ public class ImporterCli extends Program { } protected void importFile(final File file, final boolean pretend, final boolean publish) { + final PrintWriter writer = new PrintWriter(System.out); + final PrintWriter errWriter = new PrintWriter(System.err); + if (file == null) { throw new IllegalArgumentException("File object is null."); } @@ -107,25 +114,28 @@ public class ImporterCli extends Program { final String extension = fileName.substring(fileName.lastIndexOf('.')); final PublicationFormat format = findFormatForExtension(extension); if (format == null) { - LOGGER.error(String.format("No importer for publication format identified " - + "by file extension '%s' available.", - extension)); + errWriter.printf(String.format("No importer for publication format identified " + + "by file extension '%s' available.\n", + extension)); return; } - + final SciPublicationsImporter importer = SciPublicationsImporters.getInstance().getImporterForFormat( - format.getName()); + format.getName()); final String data; try { data = FileUtils.readFileToString(file); } catch (IOException ex) { - LOGGER.error(String.format("Failed to read file '%s'.", file.getAbsolutePath()), ex); + errWriter.printf(String.format("Failed to read file '%s'.\n", file.getAbsolutePath()), ex); return; } - LOGGER.info(String.format("Importing publications from file '%s'...", file.getAbsolutePath())); - importer.importPublications(data, pretend, publish); + writer.printf("Importing publications from file '%s'...\n", file.getAbsolutePath()); + final ImportReport report = importer.importPublications(data, pretend, publish); + + writer.printf("Import finished. Report:\n\n"); + writer.print(report.toString()); } else { - LOGGER.info(String.format("File %s does not exist.", file.getAbsolutePath())); + errWriter.printf("File %s does not exist.\n", file.getAbsolutePath()); } } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/SciPublicationsImporter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/SciPublicationsImporter.java index 77b17dcc5..3cf3becbf 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/SciPublicationsImporter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/SciPublicationsImporter.java @@ -19,6 +19,7 @@ package com.arsdigita.cms.scipublications.importer; import com.arsdigita.cms.scipublications.imexporter.PublicationFormat; +import com.arsdigita.cms.scipublications.importer.report.ImportReport; /** * Interface for publication importers @@ -40,8 +41,8 @@ public interface SciPublicationsImporter { * @param pretend If set to {@code true} no publications will be created. This can be used for debugging purposes * or to check an file containing publications. * @param publishNewItems If set to {@code true} the items created by the importer will also be published. - * @return A report describing what the importer has done + * @return A report describing what the importer has done. */ - String importPublications(String publications, boolean pretend, boolean publishNewItems); + ImportReport importPublications(String publications, boolean pretend, boolean publishNewItems); } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/AuthorImportReport.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/AuthorImportReport.java new file mode 100644 index 000000000..00378d9a9 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/AuthorImportReport.java @@ -0,0 +1,65 @@ +package com.arsdigita.cms.scipublications.importer.report; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class AuthorImportReport { + + private String surname; + private String givenName; + private boolean editor; + private boolean created; + + public String getSurname() { + return surname; + } + + public void setSurname(final String surname) { + this.surname = surname; + } + + public String getGivenName() { + return givenName; + } + + public void setGivenName(final String givenName) { + this.givenName = givenName; + } + + public boolean isEditor() { + return editor; + } + + public void setEditor(final boolean editor) { + this.editor = editor; + } + + public boolean isCreated() { + return created; + } + + public void setCreated(final boolean created) { + this.created = created; + } + + @Override + public String toString() { + final String authorType; + if (editor) { + authorType = "editor"; + } else { + authorType = "author"; + } + + if (created) { + return String.format("Created author '%s, %s'. Linked to publication as %s.", + surname, givenName, authorType); + } else { + return String.format("Found author '%s, %s' in database. Linked to publication as %s.", + surname, givenName, authorType); + } + } + +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/CollectedVolumeImportReport.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/CollectedVolumeImportReport.java new file mode 100644 index 000000000..5e420e232 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/CollectedVolumeImportReport.java @@ -0,0 +1,74 @@ +package com.arsdigita.cms.scipublications.importer.report; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class CollectedVolumeImportReport { + + private String collectedVolumeTitle; + private List authors = new ArrayList(); + private boolean created; + + public String getCollectedVolumeTitle() { + return collectedVolumeTitle; + } + + public void setCollectedVolumeTitle(final String collectedVolumeTitle) { + this.collectedVolumeTitle = collectedVolumeTitle; + } + + public List getAuthors() { + return Collections.unmodifiableList(authors); + } + + public void addAuthor(final AuthorImportReport author) { + authors.add(author); + } + + public void setAuthors(final List authors) { + this.authors = authors; + } + + public boolean isCreated() { + return created; + } + + public void setCreated(final boolean created) { + this.created = created; + } + + @Override + public String toString() { + if (created) { + final StringWriter strWriter = new StringWriter(); + final PrintWriter writer = new PrintWriter(strWriter); + + for(int i = 0; i < 40; i++) { + writer.append("- "); + } + + writer.printf("Created collected volume '%s' and linked it with publication.\n"); + writer.print("Author of collected volume:\n"); + for(AuthorImportReport author : authors) { + writer.printf("%s\n", author.toString()); + } + + for(int i = 0; i < 40; i++) { + writer.append("- "); + } + + return strWriter.toString(); + } else { + return String.format("Found collected volume '%s' and linked it with publications.", collectedVolumeTitle); + } + } + +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/FieldImportReport.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/FieldImportReport.java new file mode 100644 index 000000000..ddfcf662b --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/FieldImportReport.java @@ -0,0 +1,44 @@ +package com.arsdigita.cms.scipublications.importer.report; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class FieldImportReport { + + private String name; + private String value; + + public FieldImportReport() { + //Nothing + } + + public FieldImportReport(final String name, final String value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(final String value) { + this.value = value; + } + + @Override + public String toString() { + return String.format("%24s: %s", name, value); + } + + +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/ImportReport.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/ImportReport.java new file mode 100644 index 000000000..8ead4459c --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/ImportReport.java @@ -0,0 +1,75 @@ +package com.arsdigita.cms.scipublications.importer.report; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class ImportReport { + + private String importer; + private boolean pretend; + private List publications = new ArrayList(); + + public String getImporter() { + return importer; + } + + public void setImporter(final String importer) { + this.importer = importer; + } + + public List getPublications() { + return Collections.unmodifiableList(publications); + } + + public void addPublication(final PublicationImportReport publication) { + publications.add(publication); + } + + public void setPublications(final List publications) { + this.publications = publications; + } + + public boolean isPretend() { + return pretend; + } + + public void setPretend(final boolean pretend) { + this.pretend = pretend; + } + + @Override + public String toString() { + final StringWriter strWriter = new StringWriter(); + final PrintWriter writer = new PrintWriter(strWriter); + + writer.printf("Importer.......................: %s\n", importer); + writer.printf("Number of publications imported: %d\n", publications.size()); + writer.printf("Pretend mode: %b\n", pretend); + if (pretend) { + writer.printf("Pretend mode is active. None of the publications in this report have been imported. The" + + "import only shown what would be done if the publications are truly imported."); + } + for(PublicationImportReport publication: publications) { + for(int i = 0; i < 80; i++) { + writer.append('-'); + } + + writer.append(publication.toString()); + + for(int i = 0; i < 80; i++) { + writer.append('-'); + } + } + + return strWriter.toString(); + } + +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/JournalImportReport.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/JournalImportReport.java new file mode 100644 index 000000000..7bb5558bb --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/JournalImportReport.java @@ -0,0 +1,38 @@ +package com.arsdigita.cms.scipublications.importer.report; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class JournalImportReport { + + private String journalTitle; + private boolean created; + + public String getJournalTitle() { + return journalTitle; + } + + public void setJournalTitle(final String journalTitle) { + this.journalTitle = journalTitle; + } + + public boolean isCreated() { + return created; + } + + public void setCreated(final boolean created) { + this.created = created; + } + + @Override + public String toString() { + if (created) { + return String.format("Created journal '%s' and linked it to publication."); + } else { + return String.format("Found journal '%s' in database and linked it to publication."); + } + } + +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/OrganizationalUnitImportReport.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/OrganizationalUnitImportReport.java new file mode 100644 index 000000000..0472db1db --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/OrganizationalUnitImportReport.java @@ -0,0 +1,51 @@ +package com.arsdigita.cms.scipublications.importer.report; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class OrganizationalUnitImportReport { + + private String name; + private String type; + private boolean created; + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(final String type) { + this.type = type; + } + + public boolean isCreated() { + return created; + } + + public void setCreated(final boolean created) { + this.created = created; + } + + @Override + public String toString() { + if (created) { + return String.format("Created organizationalunit '%s' of type '%s' and linked it with publication.", + name, + type); + } else { + return String.format("Found organizational unit '%s' of type '%s' in database and linked it " + + "with publication.", + name, type); + } + } + +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/ProceedingsImportReport.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/ProceedingsImportReport.java new file mode 100644 index 000000000..724d05a47 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/ProceedingsImportReport.java @@ -0,0 +1,106 @@ +package com.arsdigita.cms.scipublications.importer.report; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class ProceedingsImportReport { + + private String proceedingsTitle; + private String conference; + private Date dateFromOfConference; + private Date dateToOfConference; + private List authors = new ArrayList(); + private boolean created; + + public String getProceedingsTitle() { + return proceedingsTitle; + } + + public void setProceedingsTitle(final String proceedingsTitle) { + this.proceedingsTitle = proceedingsTitle; + } + + public String getConference() { + return conference; + } + + public void setConference(final String conference) { + this.conference = conference; + } + + public Date getDateFromOfConference() { + return dateFromOfConference; + } + + public void setDateFromOfConference(final Date dateFromOfConference) { + this.dateFromOfConference = dateFromOfConference; + } + + public Date getDateToOfConference() { + return dateToOfConference; + } + + public void setDateToOfConference(final Date dateToOfConference) { + this.dateToOfConference = dateToOfConference; + } + + public List getAuthors() { + return Collections.unmodifiableList(authors); + } + + public void addAuthor(final AuthorImportReport author) { + authors.add(author); + } + + public void setAuthors(final List authors) { + this.authors = authors; + } + + public boolean isCreated() { + return created; + } + + public void setCreated(final boolean created) { + this.created = created; + } + + @Override + public String toString() { + if (created) { + final StringWriter strWriter = new StringWriter(); + final PrintWriter writer = new PrintWriter(strWriter); + + for (int i = 0; i < 40; i++) { + writer.append("- "); + } + + writer.printf("Created proceedings '%s' and linked them with publication."); + writer.printf("Conference.............: %s\n", conference); + writer.printf("Date from of conference: %s\n", dateToOfConference.toString()); + writer.printf("Date to of conference..: %s\n", dateToOfConference.toString()); + writer.print("Authors:\n"); + for(AuthorImportReport author : authors) { + writer.printf("%s\n", author.toString()); + } + + for (int i = 0; i < 40; i++) { + writer.append("- "); + } + + return strWriter.toString(); + } else { + return String.format("Found procceedings '%s' in database and linked them with publications.", + proceedingsTitle); + } + } + +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/PublicationImportReport.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/PublicationImportReport.java new file mode 100644 index 000000000..1c47e374a --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/PublicationImportReport.java @@ -0,0 +1,189 @@ +package com.arsdigita.cms.scipublications.importer.report; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class PublicationImportReport { + + private String title; + private String type; + private boolean alreadyInDatabase; + private List fields = new ArrayList(); + private List authors = new ArrayList(); + private PublisherImportReport publisher; + private CollectedVolumeImportReport collectedVolume; + private JournalImportReport journal; + private ProceedingsImportReport proceedings; + private List orgaUnits = new ArrayList(); + private boolean successful; + private List messages = new ArrayList(); + + public String getTitle() { + return title; + } + + public void setTitle(final String title) { + this.title = title; + } + + public String getType() { + return type; + } + + public void setType(final String type) { + this.type = type; + } + + public boolean isAlreadyInDatabase() { + return alreadyInDatabase; + } + + public void setAlreadyInDatabase(final boolean alreadyInDatabase) { + this.alreadyInDatabase = alreadyInDatabase; + } + + public List getFields() { + return Collections.unmodifiableList(fields); + } + + public void addField(final FieldImportReport field) { + fields.add(field); + } + + public void setFields(final List fields) { + this.fields = fields; + } + + public List getAuthors() { + return Collections.unmodifiableList(authors); + } + + public void addAuthor(final AuthorImportReport author) { + authors.add(author); + } + + public void setAuthors(final List authors) { + this.authors = authors; + } + + public PublisherImportReport getPublisher() { + return publisher; + } + + public void setPublisher(final PublisherImportReport publisher) { + this.publisher = publisher; + } + + public CollectedVolumeImportReport getCollectedVolume() { + return collectedVolume; + } + + public void setCollectedVolume(final CollectedVolumeImportReport collectedVolume) { + this.collectedVolume = collectedVolume; + } + + public JournalImportReport getJournal() { + return journal; + } + + public void setJournal(final JournalImportReport journal) { + this.journal = journal; + } + + public ProceedingsImportReport getProceedings() { + return proceedings; + } + + public void setProceedings(final ProceedingsImportReport proceedings) { + this.proceedings = proceedings; + } + + public List getOrgaUnits() { + return Collections.unmodifiableList(orgaUnits); + } + + public void addOrgaUnit(final OrganizationalUnitImportReport orgaUnit) { + orgaUnits.add(orgaUnit); + } + + public void setOrgaUnits(final List orgaUnits) { + this.orgaUnits = orgaUnits; + } + + public boolean isSuccessful() { + return successful; + } + + public void setSuccessful(final boolean successful) { + this.successful = successful; + } + + public List getMessages() { + return Collections.unmodifiableList(messages); + } + + public void addMessage(final String message) { + messages.add(message); + } + + public void setMessage(final List messages) { + this.messages = messages; + } + + @Override + public String toString() { + final StringWriter strWriter = new StringWriter(); + final PrintWriter writer = new PrintWriter(strWriter); + + writer.printf("%24s: %s\n", "title", title); + writer.printf("%24s: %s\n", "type", type); + writer.printf("%24s: %b\n", successful); + if (!successful) { + writer.printf("Import failed. Messages from importer:\n "); + for(String message : messages) { + writer.printf("%s\n", message); + } + return strWriter.toString(); + } + writer.printf("%24s: %b\n", "Already in database", alreadyInDatabase); + writer.printf("Authors:"); + for(AuthorImportReport author: authors) { + writer.printf("%s\n", author.toString()); + } + if (publisher != null) { + writer.printf("%s\n", publisher.toString()); + } + if (collectedVolume != null) { + writer.printf("Collected volume:\n%s\n", collectedVolume.toString()); + } + if (journal != null) { + writer.printf("Journal: %s\n", journal.toString()); + } + if (proceedings != null) { + writer.printf("Proceedings:\n%s\n", proceedings.toString()); + } + for(FieldImportReport field : fields) { + writer.printf("%s\n", field.toString()); + } + for(OrganizationalUnitImportReport orgaUnit : orgaUnits) { + writer.printf("%s\n", orgaUnit.toString()); + } + + writer.printf("Messages:\n"); + for(String message : messages) { + writer.printf("%s\n", message); + } + + return strWriter.toString(); + } + + +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/PublisherImportReport.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/PublisherImportReport.java new file mode 100644 index 000000000..401a9b20b --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/report/PublisherImportReport.java @@ -0,0 +1,49 @@ +package com.arsdigita.cms.scipublications.importer.report; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class PublisherImportReport { + + private String publisherName; + private String place; + private boolean created; + + public String getPublisherName() { + return publisherName; + } + + public void setPublisherName(final String publisherName) { + this.publisherName = publisherName; + } + + public String getPlace() { + return place; + } + + public void setPlace(final String place) { + this.place = place; + } + + public boolean isCreated() { + return created; + } + + public void setCreated(final boolean created) { + this.created = created; + } + + @Override + public String toString() { + if (created) { + return String.format("Created publisher '%s: %s' and linked publisher to publication.", + place, publisherName); + } else { + return String.format("Found publisher '%s: %s' in database and linked publisher to publication.", + place, publisherName); + } + } + +} diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/util/AuthorData.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/util/AuthorData.java new file mode 100644 index 000000000..23756ad7a --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/util/AuthorData.java @@ -0,0 +1,62 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.arsdigita.cms.scipublications.importer.util; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class AuthorData { + + private static final String DR_TITLE = "Dr."; + private static final String PROF_DR = "Prof. Dr."; + private String surname; + private String givenName; + private boolean editor; + + public AuthorData() { + //Nothing + } + + public String getSurname() { + if (surname == null) { + return ""; + } else { + return surname.trim(); + } + } + + public void setSurname(final String surname) { + if (surname.startsWith(DR_TITLE)) { + this.surname = surname.substring(DR_TITLE.length()); + } else if (surname.startsWith(PROF_DR)) { + this.surname = surname.substring(PROF_DR.length()); + } else { + this.surname = surname; + } + } + + public String getGivenName() { + if (givenName == null) { + return ""; + } else { + return givenName.trim(); + } + } + + public void setGivenName(final String givenName) { + this.givenName = givenName; + } + + public boolean isEditor() { + return editor; + } + + public void setEditor(final boolean editor) { + this.editor = editor; + } + +} \ No newline at end of file diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/util/ImporterUtil.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/util/ImporterUtil.java new file mode 100644 index 000000000..5f65fd021 --- /dev/null +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/importer/util/ImporterUtil.java @@ -0,0 +1,288 @@ +package com.arsdigita.cms.scipublications.importer.util; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.ArticleInCollectedVolume; +import com.arsdigita.cms.contenttypes.ArticleInJournal; +import com.arsdigita.cms.contenttypes.CollectedVolume; +import com.arsdigita.cms.contenttypes.CollectedVolumeBundle; +import com.arsdigita.cms.contenttypes.GenericPerson; +import com.arsdigita.cms.contenttypes.GenericPersonBundle; +import com.arsdigita.cms.contenttypes.InProceedings; +import com.arsdigita.cms.contenttypes.Journal; +import com.arsdigita.cms.contenttypes.JournalBundle; +import com.arsdigita.cms.contenttypes.Proceedings; +import com.arsdigita.cms.contenttypes.ProceedingsBundle; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.PublicationWithPublisher; +import com.arsdigita.cms.contenttypes.Publisher; +import com.arsdigita.cms.contenttypes.PublisherBundle; +import com.arsdigita.cms.contenttypes.SciAuthor; +import com.arsdigita.cms.scipublications.importer.report.AuthorImportReport; +import com.arsdigita.cms.scipublications.importer.report.CollectedVolumeImportReport; +import com.arsdigita.cms.scipublications.importer.report.JournalImportReport; +import com.arsdigita.cms.scipublications.importer.report.ProceedingsImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublisherImportReport; +import com.arsdigita.kernel.Kernel; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.Session; +import com.arsdigita.persistence.SessionManager; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class ImporterUtil { + + public AuthorImportReport processAuthor(final Publication publication, final AuthorData authorData) { + final AuthorImportReport report = new AuthorImportReport(); + + final Session session = SessionManager.getSession(); + final DataCollection collection = session.retrieve(GenericPerson.BASE_DATA_OBJECT_TYPE); + collection.addEqualsFilter("surname", authorData.getSurname()); + collection.addEqualsFilter("givenname", authorData.getGivenName()); + + final GenericPerson author; + report.setSurname(authorData.getSurname()); + report.setGivenName(authorData.getGivenName()); + report.setEditor(authorData.isEditor()); + + if (collection.isEmpty()) { + final Integer folderId = Publication.getConfig().getDefaultAuthorsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + if (folder == null) { + throw new IllegalArgumentException("Error getting folders for authors."); + } + + final SciAuthor newAuthor = new SciAuthor(); + newAuthor.setSurname(authorData.getSurname()); + newAuthor.setGivenName(authorData.getGivenName()); + newAuthor.setName(GenericPerson.urlSave(String.format("%s %s", + authorData.getSurname(), + authorData.getGivenName()))); + newAuthor.setContentSection(folder.getContentSection()); + newAuthor.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + newAuthor.save(); + + final GenericPersonBundle bundle = new GenericPersonBundle(newAuthor); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + bundle.save(); + + report.setCreated(true); + author = newAuthor; + } else { + collection.next(); + author = new GenericPerson(collection.getDataObject()); + report.setCreated(false); + } + + publication.addAuthor(author, authorData.isEditor()); + + return report; + } + + public PublisherImportReport processPublisher(final PublicationWithPublisher publication, + final String place, + final String publisherName) { + final PublisherImportReport report = new PublisherImportReport(); + + final Session session = SessionManager.getSession(); + final DataCollection collection = session.retrieve(Publisher.BASE_DATA_OBJECT_TYPE); + collection.addEqualsFilter("title", publisherName); + collection.addEqualsFilter("place", place); + final Publisher publisher; + report.setPublisherName(publisherName); + report.setPlace(place); + if (collection.isEmpty()) { + final Integer folderId = Publication.getConfig().getDefaultPublisherFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + if (folder == null) { + throw new IllegalArgumentException("Error getting folders for publishers"); + } + + final Publisher newPublisher = new Publisher(); + newPublisher.setPublisherName(publisherName); + newPublisher.setPlace(place); + newPublisher.setTitle(String.format("%s %s", publisherName, place)); + newPublisher.setName(Publisher.urlSave(String.format("%s %s", publisherName, place))); + newPublisher.setContentSection(folder.getContentSection()); + newPublisher.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + newPublisher.save(); + + final PublisherBundle bundle = new PublisherBundle(newPublisher); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + bundle.save(); + + report.setCreated(true); + publisher = newPublisher; + } else { + collection.next(); + publisher = new Publisher(collection.getDataObject()); + report.setCreated(false); + } + + publication.setPublisher(publisher); + + return report; + } + + public CollectedVolumeImportReport processCollectedVolume(final ArticleInCollectedVolume article, + final String title, + final int year, + final List authors) { + final CollectedVolumeImportReport report = new CollectedVolumeImportReport(); + + final Session session = SessionManager.getSession(); + final DataCollection collection = session.retrieve(CollectedVolume.BASE_DATA_OBJECT_TYPE); + collection.addEqualsFilter("title", title); + collection.addEqualsFilter("yearOfPublication", year); + final CollectedVolume collectedVolume; + report.setCollectedVolumeTitle(title); + if (collection.isEmpty()) { + final Integer folderId = Publication.getConfig().getDefaultCollectedVolumesFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + if (folder == null) { + throw new IllegalArgumentException("Error getting foldes for collected volumes."); + } + + final CollectedVolume newCollectedVolume = new CollectedVolume(); + newCollectedVolume.setTitle(title); + newCollectedVolume.setName(normalizeString(title)); + newCollectedVolume.setContentSection(folder.getContentSection()); + newCollectedVolume.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + newCollectedVolume.save(); + + final CollectedVolumeBundle bundle = new CollectedVolumeBundle(newCollectedVolume); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + bundle.save(); + + newCollectedVolume.setYearOfPublication(year); + for(AuthorData author : authors) { + report.addAuthor(processAuthor(newCollectedVolume, author)); + } + + newCollectedVolume.save(); + + report.setCreated(true); + collectedVolume = newCollectedVolume; + } else { + collection.next(); + collectedVolume = new CollectedVolume(collection.getDataObject()); + report.setCreated(false); + } + + article.setCollectedVolume(collectedVolume); + + return report; + } + + public ProceedingsImportReport processProceedings(final InProceedings inProceedings, + final String title, + final int year, + final String conference, + final List authors) { + final ProceedingsImportReport report = new ProceedingsImportReport(); + + final Session session = SessionManager.getSession(); + final DataCollection collection = session.retrieve(Proceedings.BASE_DATA_OBJECT_TYPE); + collection.addEqualsFilter("title", title); + collection.addEqualsFilter("yearOfPublication", year); + final Proceedings proceedings; + report.setProceedingsTitle(title); + if (collection.isEmpty()) { + final Integer folderId = Publication.getConfig().getDefaultProceedingsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + if (folder == null) { + throw new IllegalArgumentException("Failed to get folder for proceedings."); + } + + final Proceedings newProceedings = new Proceedings(); + newProceedings.setTitle(title); + newProceedings.setName(normalizeString(title)); + newProceedings.setNameOfConference(conference); + report.setConference(conference); + newProceedings.setContentSection(folder.getContentSection()); + newProceedings.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + newProceedings.save(); + + final ProceedingsBundle bundle = new ProceedingsBundle(newProceedings); + bundle.setContentSection(folder.getContentSection()); + bundle.setParent(folder); + bundle.save(); + + newProceedings.setYearOfPublication(year); + for(AuthorData author : authors) { + report.addAuthor(processAuthor(newProceedings, author)); + } + + report.setCreated(true); + proceedings = newProceedings; + } else { + collection.next(); + proceedings = new Proceedings(collection.getDataObject()); + report.setCreated(false); + } + + inProceedings.setProceedings(proceedings); + + return report; + } + + public JournalImportReport processJournal(final ArticleInJournal article, final String title) { + final JournalImportReport report = new JournalImportReport(); + + final Session session = SessionManager.getSession(); + final DataCollection collection = session.retrieve(Journal.BASE_DATA_OBJECT_TYPE); + collection.addEqualsFilter("title", title); + final Journal journal; + report.setJournalTitle(title); + if (collection.isEmpty()) { + final Integer folderId = Publication.getConfig().getDefaultJournalsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + if (folder == null) { + throw new IllegalArgumentException("Error getting folder for journals"); + } + + final Journal newJournal = new Journal(); + newJournal.setTitle(title); + newJournal.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + newJournal.setContentSection(folder.getContentSection()); + newJournal.save(); + + final JournalBundle bundle = new JournalBundle(newJournal); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + bundle.save(); + + report.setCreated(true); + journal = newJournal; + } else { + collection.next(); + journal = new Journal(collection.getDataObject()); + report.setCreated(false); + } + + article.setJournal(journal); + + return report; + } + + protected final String normalizeString(final String str) { + if (str == null) { + return "null"; + } + return str.replace("ä", "ae").replace("ö", "oe").replace("ü", "ue"). + replace( + "Ä", "Ae").replace("Ü", "Ue").replace("Ö", "Oe").replace("ß", + "ss"). + replace(" ", "-"). + replaceAll("[^a-zA-Z0-9\\-]", "").toLowerCase().trim(); + } + +} diff --git a/ccm-sci-publicationscsvimporter/application.xml b/ccm-sci-publicationscsvimporter/application.xml new file mode 100644 index 000000000..1515e37c1 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/application.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + Importer for Publications using a CSV file. Only used for internal purposes + at the University of Bremen. + + + \ No newline at end of file diff --git a/ccm-sci-publicationscsvimporter/src/META-INF/services/com.arsdigita.cms.scipublications.importer.SciPublicationsImporter b/ccm-sci-publicationscsvimporter/src/META-INF/services/com.arsdigita.cms.scipublications.importer.SciPublicationsImporter new file mode 100644 index 000000000..ed4260492 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/META-INF/services/com.arsdigita.cms.scipublications.importer.SciPublicationsImporter @@ -0,0 +1 @@ +com.arsdigita.cms.scipublications.importer.csv.PublicationsImporter \ No newline at end of file diff --git a/ccm-sci-publicationscsvimporter/src/ccm-sci-publicationscsvimporter.config b/ccm-sci-publicationscsvimporter/src/ccm-sci-publicationscsvimporter.config new file mode 100644 index 000000000..f68f37732 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/ccm-sci-publicationscsvimporter.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ccm-sci-publicationscsvimporter/src/ccm-sci-publicationscsvimporter.load b/ccm-sci-publicationscsvimporter/src/ccm-sci-publicationscsvimporter.load new file mode 100644 index 000000000..f03fcff5f --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/ccm-sci-publicationscsvimporter.load @@ -0,0 +1,17 @@ + + + +
+
+
+ + + + + + + + + + + \ No newline at end of file diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/AbstractPublicationImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/AbstractPublicationImporter.java new file mode 100644 index 000000000..e50ffb4e2 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/AbstractPublicationImporter.java @@ -0,0 +1,189 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.lifecycle.LifecycleDefinition; +import com.arsdigita.cms.lifecycle.LifecycleDefinitionCollection; +import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.cms.scipublications.importer.util.AuthorData; +import com.arsdigita.cms.scipublications.importer.util.ImporterUtil; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.List; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +abstract class AbstractPublicationImporter { + + private static final String AUTHORS_SEP = ";"; + private static final String AUTHOR_NAME_SEP = ","; + private static final String EDITOR_STR = "(Hrsg.)"; + private final CsvLine data; + private final PublicationImportReport report; + private final ImporterUtil importerUtil = new ImporterUtil(); + + public AbstractPublicationImporter(final CsvLine data, final PublicationImportReport report) { + this.data = data; + this.report = report; + } + + protected CsvLine getData() { + return data; + } + + protected ImporterUtil getImporterUtil() { + return importerUtil; + } + + protected PublicationImportReport getReport() { + return report; + } + + /** + * This method is called by {@link PublicationsImporter}. + */ + public final void doImport(final boolean publishNewItems) { + final T publication = importPublication(); + publication.save(); + if (publishNewItems) { + final Calendar now = new GregorianCalendar(); + final LifecycleDefinitionCollection lifecycles = publication.getContentSection().getLifecycleDefinitions(); + lifecycles.next(); + final LifecycleDefinition lifecycleDef = lifecycles.getLifecycleDefinition(); + publication.publish(lifecycleDef, now.getTime()); + } + } + + /** + * Overwrite to set the properites for the content type, using this pattern: + *
    
+     * public T importPublication() {
+     *     final T publication = super.importPublication();
+     * 
+     *     //Set additional properites of the publication type
+     *     publication.set...
+     * 
+     *     //Output properties of publication. 
+     *    super.printPublication(publication);  
+     *  
+     *    return publication;
+     * }
+     * 
+ * + * @return + */ + protected T importPublication() { + final T publication = createPublication(); + + processTitleAndName(publication); + publication.setAbstract(data.getAbstract()); + publication.setMisc(data.getMisc()); + processReviewed(publication); + processAuthors(publication); + + return publication; + } + + /** + * Overwrite this method to create an instance of an publication type. + * + * @return + */ + protected abstract T createPublication(); + + private void processTitleAndName(final T publication) { + publication.setTitle(data.getTitle()); + publication.setName(normalizeString(data.getTitle())); + report.setTitle(publication.getTitle()); + } + + private void processReviewed(final T publication) { + final String reviewedStr = data.getReviewed(); + final boolean reviewed; + + if ("y".equalsIgnoreCase(reviewedStr)) { + reviewed = true; + } else if ("j".equalsIgnoreCase(reviewedStr)) { + reviewed = true; + } else if ("yes".equalsIgnoreCase(reviewedStr)) { + reviewed = true; + } else if ("ja".equalsIgnoreCase(reviewedStr)) { + reviewed = true; + } else if ("t".equalsIgnoreCase(reviewedStr)) { + reviewed = true; + } else if ("true".equalsIgnoreCase(reviewedStr)) { + reviewed = true; + } else { + reviewed = false; + } + + publication.setReviewed(reviewed); + report.addField(new FieldImportReport("reviewed", Boolean.toString(reviewed))); + } + + private void processAuthors(final T publication) { + final List authorsData = parseAuthors(data.getAuthors()); + + for (AuthorData authorData : authorsData) { + importerUtil.processAuthor(publication, authorData); + } + } + + protected final String normalizeString(final String str) { + if (str == null) { + return "null"; + } + return str.replace("ä", "ae").replace("ö", "oe").replace("ü", "ue"). + replace( + "Ä", "Ae").replace("Ü", "Ue").replace("Ö", "Oe").replace("ß", + "ss"). + replace(" ", "-"). + replaceAll("[^a-zA-Z0-9\\-]", "").toLowerCase().trim(); + } + + protected List parseAuthors(final String authorsStr) { + final List authors = new ArrayList(); + + final String[] tokens = authorsStr.split(AUTHORS_SEP); + for (String token : tokens) { + parseAuthor(token, authors); + } + + return authors; + } + + private void parseAuthor(final String authorToken, final List authors) { + final String[] nameTokens = authorToken.split(AUTHOR_NAME_SEP); + + if (nameTokens.length == 1) { + final AuthorData author = new AuthorData(); + author.setSurname(nameTokens[0]); + authors.add(author); + } else if (nameTokens.length == 2) { + final AuthorData author = new AuthorData(); + author.setSurname(nameTokens[0]); + if (nameTokens[1].endsWith(EDITOR_STR)) { + author.setEditor(true); + author.setGivenName(nameTokens[1].substring(0, nameTokens[1].length() - EDITOR_STR.length())); + } else { + author.setGivenName(nameTokens[1]); + } + authors.add(author); + } else { + final AuthorData author = new AuthorData(); + author.setSurname(nameTokens[0]); + if (nameTokens[1].endsWith(EDITOR_STR)) { + author.setEditor(true); + author.setGivenName(nameTokens[1].substring(0, nameTokens[1].length() - EDITOR_STR.length())); + } else { + author.setGivenName(nameTokens[1]); + } + authors.add(author); + } + } + +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/AbstractPublicationWithPublisherImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/AbstractPublicationWithPublisherImporter.java new file mode 100644 index 000000000..68bef09ed --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/AbstractPublicationWithPublisherImporter.java @@ -0,0 +1,128 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.contenttypes.PublicationWithPublisher; +import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +abstract class AbstractPublicationWithPublisherImporter + extends AbstractPublicationImporter { + + public AbstractPublicationWithPublisherImporter(final CsvLine data, + final PublicationImportReport report) { + super(data, report); + } + + @Override + protected T importPublication() { + final T publication = super.importPublication(); + final CsvLine data = getData(); + + if ((data.getIsbn() != null) && !data.getIsbn().isEmpty()) { + publication.setISBN(data.getIsbn()); + getReport().addField(new FieldImportReport("isbn", data.getIsbn())); + } + + processVolume(publication); + processNumberOfVolumes(publication); + processNumberOfPages(publication); + if ((data.getEdition() != null) && !data.getEdition().isEmpty()) { + publication.setEdition(data.getEdition()); + } + + getImporterUtil().processPublisher(publication, getData().getPlace(), getData().getPublisher()); + + return publication; + } + + private void processVolume(final T publication) { + if ((getData().getVolume() != null) && !getData().getVolume().isEmpty()) { + try { + final int volume = Integer.parseInt(getData().getVolume()); + publication.setVolume(volume); + getReport().addField(new FieldImportReport("Volume", getData().getVolume())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse volume data in line %d.", getData(). + getLineNumber())); + } + } + } + + private void processNumberOfVolumes(final T publication) { + if ((getData().getNumberOfVolumes() != null) && !getData().getNumberOfVolumes().isEmpty()) { + try { + final int volume = Integer.parseInt(getData().getNumberOfVolumes()); + publication.setNumberOfVolumes(volume); + getReport().addField(new FieldImportReport("Number of volumes", getData().getNumberOfVolumes())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format( + "Failed to parse number of volumes data in line %d.", getData().getLineNumber())); + } + } + } + + private void processNumberOfPages(final T publication) { + if ((getData().getNumberOfPages() != null) && !getData().getNumberOfPages().isEmpty()) { + try { + final int volume = Integer.parseInt(getData().getNumberOfPages()); + publication.setNumberOfPages(volume); + getReport().addField(new FieldImportReport("Number of pages", getData().getNumberOfPages())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse numberOfPages data in line %d.", + getData().getLineNumber())); + } + } + } + +// private void processPublisher(final T publication) { +// final String publisherName = getData().getPublisher(); +// final String place = getData().getPlace(); +// +// final Session session = SessionManager.getSession(); +// final DataCollection collection = session.retrieve(Publisher.BASE_DATA_OBJECT_TYPE); +// collection.addEqualsFilter("title", publisherName); +// collection.addEqualsFilter("place", place); +// final Publisher publisher; +// if (collection.isEmpty()) { +// getReportWriter().printf("Publisher %s: %s not found in database. Creating...\n", +// getData().getPlace(), +// getData().getPublisher()); +// +// final Integer folderId = Publication.getConfig().getDefaultPublisherFolder(); +// final Folder folder = new Folder(new BigDecimal(folderId)); +// if (folder == null) { +// throw new IllegalArgumentException("Error getting folders for publishers"); +// } +// +// final Publisher newPublisher = new Publisher(); +// newPublisher.setPublisherName(publisherName); +// newPublisher.setPlace(place); +// newPublisher.setTitle(String.format("%s %s", publisherName, place)); +// newPublisher.setName(Publisher.urlSave(String.format("%s %s", publisherName, place))); +// newPublisher.setContentSection(folder.getContentSection()); +// newPublisher.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); +// newPublisher.save(); +// +// final PublisherBundle bundle = new PublisherBundle(newPublisher); +// bundle.setParent(folder); +// bundle.setContentSection(folder.getContentSection()); +// bundle.save(); +// +// publisher = newPublisher; +// } else { +// getReportWriter().printf("Publisher %s: %s found in database. Using existing item.\n", +// getData().getPlace(), +// getData().getPublisher()); +// collection.next(); +// final DataObject dobj = collection.getDataObject(); +// publisher = new Publisher(dobj); +// } +// +// publication.setPublisher(publisher); +// } + +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/AbstractUnPublishedImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/AbstractUnPublishedImporter.java new file mode 100644 index 000000000..d6822577b --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/AbstractUnPublishedImporter.java @@ -0,0 +1,48 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.contenttypes.UnPublished; +import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +abstract class AbstractUnPublishedImporter extends AbstractPublicationImporter { + + protected AbstractUnPublishedImporter(final CsvLine data, + final PublicationImportReport report) { + super(data, report); + } + + @Override + protected T importPublication() { + final T publication = super.importPublication(); + final CsvLine data = getData(); + final PublicationImportReport report = getReport(); + + if ((data.getPlace() != null) && !data.getPlace().isEmpty()) { + publication.setPlace(data.getPlace()); + report.addField(new FieldImportReport("place", data.getPlace())); + } + + processNumberOfPages(publication); + + return publication; + } + + private void processNumberOfPages(final T publication) { + if ((getData().getNumberOfPages() != null) && !getData().getNumberOfPages().isEmpty()) { + try { + final int volume = Integer.parseInt(getData().getNumberOfPages()); + publication.setNumberOfPages(volume); + getReport().addField(new FieldImportReport("Number of pages", getData().getNumberOfPages())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse numberOfPages data in line %d.", + getData().getLineNumber())); + } + } + } + +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ArticleInCollectedVolumeImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ArticleInCollectedVolumeImporter.java new file mode 100644 index 000000000..736370068 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ArticleInCollectedVolumeImporter.java @@ -0,0 +1,87 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.ArticleInCollectedVolume; +import com.arsdigita.cms.contenttypes.ArticleInCollectedVolumeBundle; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.cms.scipublications.importer.util.ImporterUtil; +import com.arsdigita.kernel.Kernel; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class ArticleInCollectedVolumeImporter extends AbstractPublicationImporter { + + public ArticleInCollectedVolumeImporter(CsvLine data, PublicationImportReport report) { + super(data, report); + } + + @Override + public ArticleInCollectedVolume importPublication() { + final ArticleInCollectedVolume article = importPublication(); + final CsvLine data = getData(); + final PublicationImportReport report = getReport(); + final ImporterUtil importerUtil = getImporterUtil(); + + processPagesFrom(article); + processPagesTo(article); + + if ((data.getChapter() != null) && !data.getChapter().isEmpty()) { + article.setChapter(data.getChapter()); + report.addField(new FieldImportReport("Chapter", data.getChapter())); + } + + report.setCollectedVolume(importerUtil.processCollectedVolume(article, + data.getCollectedVolume(), + article.getYearOfPublication(), + parseAuthors(data.getAuthors()))); + + + return article; + } + + private void processPagesFrom(final ArticleInCollectedVolume publication) { + if ((getData().getPageFrom() != null) && !getData().getPageFrom().isEmpty()) { + try { + final int pagesFrom = Integer.parseInt(getData().getPageFrom()); + publication.setPagesFrom(pagesFrom); + getReport().addField(new FieldImportReport("Pages from", getData().getPageFrom())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse pageFrom data in line '%d'.", + getData().getLineNumber())); + } + } + } + + private void processPagesTo(final ArticleInCollectedVolume publication) { + try { + final int pagesTo = Integer.parseInt(getData().getPageTo()); + publication.setPagesFrom(pagesTo); + getReport().addField(new FieldImportReport("Pages to", getData().getPageFrom())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse pageTo data in line '%d'.", + getData().getLineNumber())); + } + } + + @Override + protected ArticleInCollectedVolume createPublication() { + final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + + final ArticleInCollectedVolume article = new ArticleInCollectedVolume(); + article.setContentSection(folder.getContentSection()); + article.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + + final ArticleInCollectedVolumeBundle bundle = new ArticleInCollectedVolumeBundle(article); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + + return article; + } +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ArticleInJournalImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ArticleInJournalImporter.java new file mode 100644 index 000000000..7231b9187 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ArticleInJournalImporter.java @@ -0,0 +1,118 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.ArticleInJournal; +import com.arsdigita.cms.contenttypes.ArticleInJournalBundle; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.cms.scipublications.importer.util.ImporterUtil; +import com.arsdigita.kernel.Kernel; +import java.math.BigDecimal; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class ArticleInJournalImporter extends AbstractPublicationImporter { + + protected ArticleInJournalImporter(final CsvLine data, final PublicationImportReport report) { + super(data, report); + } + + @Override + public ArticleInJournal importPublication() { + final ArticleInJournal article = super.importPublication(); + final CsvLine data = getData(); + final PublicationImportReport report = getReport(); + final ImporterUtil importerUtil = getImporterUtil(); + + processVolume(article); + if ((data.getIssue() != null) && !data.getIssue().isEmpty()) { + article.setIssue(data.getIssue()); + report.addField(new FieldImportReport("Issue", data.getIssue())); + } + processPagesFrom(article); + processPagesTo(article); + processPublicationDate(article); + + if ((data.getJournal() != null) && !data.getJournal().isEmpty()) { + importerUtil.processJournal(article, data.getJournal()); + } + + + return article; + } + + private void processVolume(final ArticleInJournal article) { + if ((getData().getVolume() != null) && !getData().getVolume().isEmpty()) { + try { + final int volume = Integer.parseInt(getData().getVolume()); + article.setVolume(volume); + getReport().addField(new FieldImportReport("Volume", getData().getVolume())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse volume data in line '%d'.", + getData().getLineNumber())); + } + } + } + + private void processPagesFrom(final ArticleInJournal publication) { + if ((getData().getPageFrom() != null) && !getData().getPageFrom().isEmpty()) { + try { + final int pagesFrom = Integer.parseInt(getData().getPageFrom()); + publication.setPagesFrom(pagesFrom); + getReport().addField(new FieldImportReport("Pages from", getData().getPageFrom())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse pageFrom data in line '%d'.", + getData().getLineNumber())); + } + } + } + + private void processPagesTo(final ArticleInJournal publication) { + try { + final int pagesTo = Integer.parseInt(getData().getPageTo()); + publication.setPagesFrom(pagesTo); + getReport().addField(new FieldImportReport("Pages to", getData().getPageFrom())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse pageTo data in line '%d'.", + getData().getLineNumber())); + } + } + + private void processPublicationDate(final ArticleInJournal article) { + if ((getData().getPublicationDate() != null) && !getData().getPublicationDate().isEmpty()) { + final DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd"); + try { + final Date date = dateFormat.parse(getData().getPublicationDate()); + article.setPublicationDate(date); + getReport().addField(new FieldImportReport("Publication date", getData().getPublicationDate())); + } catch (java.text.ParseException ex) { + getReport().addMessage(String.format("Failed to parse publication date in line %d.", + getData().getLineNumber())); + } + } + } + + @Override + protected ArticleInJournal createPublication() { + final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + + final ArticleInJournal article = new ArticleInJournal(); + article.setContentSection(folder.getContentSection()); + article.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + + final ArticleInJournalBundle bundle = new ArticleInJournalBundle(article); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + + return article; + } + +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/CollectedVolumeImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/CollectedVolumeImporter.java new file mode 100644 index 000000000..e20ccdc6d --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/CollectedVolumeImporter.java @@ -0,0 +1,37 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.CollectedVolume; +import com.arsdigita.cms.contenttypes.CollectedVolumeBundle; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.kernel.Kernel; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class CollectedVolumeImporter extends AbstractPublicationWithPublisherImporter { + + protected CollectedVolumeImporter(final CsvLine data, final PublicationImportReport report) { + super(data, report); + } + + @Override + protected CollectedVolume createPublication() { + final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + + final CollectedVolume collectedVolume = new CollectedVolume(); + collectedVolume.setContentSection(folder.getContentSection()); + collectedVolume.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + + final CollectedVolumeBundle bundle = new CollectedVolumeBundle(collectedVolume); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + + return collectedVolume; + } +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/CsvLine.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/CsvLine.java new file mode 100644 index 000000000..f57bddb83 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/CsvLine.java @@ -0,0 +1,147 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import java.util.Arrays; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class CsvLine { + + private final String[] cols; + private final int lineNumber; + + public CsvLine(final String[] cols, final int lineNumber) { + if (cols.length != 30) { + throw new IllegalArgumentException(String.format("Unexpected number of columns. Expected 30 columns, " + + "but provided array has %d entries.", cols.length)); + } + this.cols = Arrays.copyOf(cols, cols.length); + this.lineNumber = lineNumber; + } + + public int getLineNumber() { + return lineNumber; + } + + public String getTitle() { + return cols[0].trim(); + } + + public String getYear() { + return cols[1].trim(); + } + + public String getAuthors() { + return cols[2].trim(); + } + + public String getType() { + return cols[3].trim(); + } + + public String getAbstract() { + return cols[4].trim(); + } + + public String getMisc() { + return cols[5].trim(); + } + + public String getReviewed() { + return cols[6].trim(); + } + + public String getDepartment() { + return cols[7].trim(); + } + + public String getPlace() { + return cols[8].trim(); + } + + public String getPublisher() { + return cols[9].trim(); + } + + public String getVolume() { + return cols[10].trim(); + } + + public String getNumberOfVolumes() { + return cols[11].trim(); + } + + public String getNumberOfPages() { + return cols[12].trim(); + } + + public String getEdition() { + return cols[13].trim(); + } + + public String getPageFrom() { + return cols[14].trim(); + } + + public String getPageTo() { + return cols[15].trim(); + } + + public String getChapter() { + return cols[16].trim(); + } + + public String getIssue() { + return cols[17].trim(); + } + + public String getPublicationDate() { + return cols[18].trim(); + } + + public String getJournal() { + return cols[19].trim(); + } + + public String getCollectedVolume() { + return cols[20].trim(); + } + + public String getCollectedVolumeAuthors() { + return cols[21].trim(); + } + + public String getIsbn() { + return cols[22].trim(); + } + + public String getIssn() { + return cols[23].trim(); + } + + public String getLastAccess() { + return cols[24].trim(); + } + + public String getUrl() { + return cols[25].trim(); + } + + public String getUrn() { + return cols[26].trim(); + } + + public String getDoi() { + return cols[27].trim(); + } + + public String getConference() { + return cols[28].trim(); + } + + public String getScope() { + return cols[29].trim(); + } +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ExpertiseImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ExpertiseImporter.java new file mode 100644 index 000000000..3c15d067a --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ExpertiseImporter.java @@ -0,0 +1,67 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.Expertise; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.PublicationBundle; +import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.kernel.Kernel; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class ExpertiseImporter extends AbstractPublicationImporter { + + protected ExpertiseImporter(final CsvLine data, final PublicationImportReport report) { + super(data, report); + } + + @Override + protected Expertise importPublication() { + final Expertise expertise = super.importPublication(); + final CsvLine data = getData(); + final PublicationImportReport report = getReport(); + + if ((data.getPlace() != null) && !data.getPlace().isEmpty()) { + expertise.setPlace(data.getPlace()); + report.addField(new FieldImportReport("Place", data.getPlace())); + } + + processNumberOfPages(expertise); + + return expertise; + } + + @Override + protected Expertise createPublication() { + final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + + final Expertise expertise = new Expertise(); + expertise.setContentSection(folder.getContentSection()); + expertise.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + + final PublicationBundle bundle = new PublicationBundle(expertise); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + + return expertise; + } + + private void processNumberOfPages(final Expertise publication) { + if ((getData().getNumberOfPages() != null) && !getData().getNumberOfPages().isEmpty()) { + try { + final int volume = Integer.parseInt(getData().getNumberOfPages()); + publication.setNumberOfPages(volume); + getReport().addField(new FieldImportReport("Number of pages", getData().getNumberOfPages())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse numberOfPages data in line %d.", + getData().getLineNumber())); + } + } + } +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/GreyLiteratureImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/GreyLiteratureImporter.java new file mode 100644 index 000000000..ee80bf564 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/GreyLiteratureImporter.java @@ -0,0 +1,73 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.GreyLiterature; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.PublicationBundle; +import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.kernel.Kernel; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class GreyLiteratureImporter extends AbstractUnPublishedImporter { + + protected GreyLiteratureImporter(final CsvLine data, final PublicationImportReport report) { + super(data, report); + } + + @Override + protected GreyLiterature importPublication() { + final GreyLiterature publication = super.importPublication(); + + processPagesFrom(publication); + processPagesTo(publication); + + return publication; + } + + @Override + protected GreyLiterature createPublication() { + final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + + final GreyLiterature greyLiterature = new GreyLiterature(); + greyLiterature.setContentSection(folder.getContentSection()); + greyLiterature.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + + final PublicationBundle bundle = new PublicationBundle(greyLiterature); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + + return greyLiterature; + } + + private void processPagesFrom(final GreyLiterature publication) { + if ((getData().getPageFrom() != null) && !getData().getPageFrom().isEmpty()) { + try { + final int pagesFrom = Integer.parseInt(getData().getPageFrom()); + publication.setPagesFrom(pagesFrom); + getReport().addField(new FieldImportReport("Pages from", getData().getPageFrom())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse pageFrom data in line '%d'.", + getData().getLineNumber())); + } + } + } + + private void processPagesTo(final GreyLiterature publication) { + try { + final int pagesTo = Integer.parseInt(getData().getPageTo()); + publication.setPagesFrom(pagesTo); + getReport().addField(new FieldImportReport("Pages to", getData().getPageFrom())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse pageTo data in line '%d'.", + getData().getLineNumber())); + } + } + +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/InProceedingsImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/InProceedingsImporter.java new file mode 100644 index 000000000..b8505edf5 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/InProceedingsImporter.java @@ -0,0 +1,83 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.InProceedings; +import com.arsdigita.cms.contenttypes.InProceedingsBundle; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.cms.scipublications.importer.util.ImporterUtil; +import com.arsdigita.kernel.Kernel; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class InProceedingsImporter extends AbstractPublicationImporter { + + public InProceedingsImporter(final CsvLine data, final PublicationImportReport report) { + super(data, report); + } + + @Override + protected InProceedings importPublication() { + final InProceedings inProceedings = super.importPublication(); + final CsvLine data = getData(); + final PublicationImportReport report = getReport(); + final ImporterUtil importerUtil = getImporterUtil(); + + processPagesFrom(inProceedings); + processPagesTo(inProceedings); + + importerUtil.processProceedings(inProceedings, + data.getCollectedVolume(), + inProceedings.getYearOfPublication(), + data.getConference(), + parseAuthors(data.getCollectedVolumeAuthors())); + + return inProceedings; + } + + private void processPagesFrom(final InProceedings publication) { + if ((getData().getPageFrom() != null) && !getData().getPageFrom().isEmpty()) { + try { + final int pagesFrom = Integer.parseInt(getData().getPageFrom()); + publication.setPagesFrom(pagesFrom); + getReport().addField(new FieldImportReport("Pages from", getData().getPageFrom())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse pageFrom data in line '%d'.", + getData().getLineNumber())); + } + } + } + + private void processPagesTo(final InProceedings publication) { + try { + final int pagesTo = Integer.parseInt(getData().getPageTo()); + publication.setPagesFrom(pagesTo); + getReport().addField(new FieldImportReport("Pages to", getData().getPageFrom())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse pageTo data in line '%d'.", + getData().getLineNumber())); + } + } + + @Override + protected InProceedings createPublication() { + final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + + final InProceedings inProceedings = new InProceedings(); + inProceedings.setContentSection(folder.getContentSection()); + inProceedings.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + + final InProceedingsBundle bundle = new InProceedingsBundle(inProceedings); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + + return inProceedings; + } + +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/InternetArticleImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/InternetArticleImporter.java new file mode 100644 index 000000000..56bb7b501 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/InternetArticleImporter.java @@ -0,0 +1,127 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.InternetArticle; +import com.arsdigita.cms.contenttypes.InternetArticleBundle; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.kernel.Kernel; +import java.math.BigDecimal; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class InternetArticleImporter extends AbstractPublicationImporter { + + public InternetArticleImporter(final CsvLine data, final PublicationImportReport report) { + super(data, report); + } + + @Override + public InternetArticle importPublication() { + final InternetArticle article = super.importPublication(); + final CsvLine data = getData(); + final PublicationImportReport report = getReport(); + + if ((data.getPlace() != null) && !data.getPlace().isEmpty()) { + article.setPlace(data.getPlace()); + report.addField(new FieldImportReport("Place", data.getPlace())); + } + + processNumberOfPages(article); + + if ((data.getEdition() != null) && !data.getEdition().isEmpty()) { + article.setEdition(data.getEdition()); + report.addField(new FieldImportReport("Edition", data.getEdition())); + } + + if ((data.getIssn() != null) && !data.getIssn().isEmpty()) { + article.setISSN(data.getIssn()); + report.addField(new FieldImportReport("ISSN", data.getIssn())); + } + + processLastAccessed(article); + processPublicationDate(article); + + if ((data.getUrl() != null) && !data.getUrl().isEmpty()) { + article.setUrl(data.getUrl()); + report.addField(new FieldImportReport("URL", data.getUrl())); + } + + if ((data.getUrn() != null) && !data.getUrn().isEmpty()) { + article.setUrn(data.getUrn()); + report.addField(new FieldImportReport("URN", data.getUrn())); + } + + if ((data.getDoi() != null) && !data.getDoi().isEmpty()) { + article.setDoi(data.getDoi()); + report.addField(new FieldImportReport("DOI", data.getDoi())); + } + + return article; + } + + private void processNumberOfPages(final InternetArticle publication) { + if ((getData().getNumberOfPages() != null) && !getData().getNumberOfPages().isEmpty()) { + try { + final int volume = Integer.parseInt(getData().getNumberOfPages()); + publication.setNumberOfPages(volume); + getReport().addField(new FieldImportReport("Number of pages", getData().getNumberOfPages())); + } catch (NumberFormatException ex) { + getReport().addMessage(String.format("Failed to parse numberOfPages data in line %d.", + getData().getLineNumber())); + } + } + } + + private void processLastAccessed(final InternetArticle article) { + if ((getData().getLastAccess() != null) && !getData().getLastAccess().isEmpty()) { + final DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd"); + try { + final Date date = dateFormat.parse(getData().getLastAccess()); + article.setLastAccessed(date); + getReport().addField(new FieldImportReport("Last access", getData().getLastAccess())); + } catch (java.text.ParseException ex) { + getReport().addMessage(String.format("Failed to parse date of last access in line %d.", + getData().getLineNumber())); + } + } + } + + private void processPublicationDate(final InternetArticle article) { + if ((getData().getPublicationDate() != null) && !getData().getPublicationDate().isEmpty()) { + final DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd"); + try { + final Date date = dateFormat.parse(getData().getPublicationDate()); + article.setPublicationDate(date); + getReport().addField(new FieldImportReport("Publication date", getData().getPublicationDate())); + } catch (java.text.ParseException ex) { + getReport().addMessage(String.format("Failed to parse publication date in line %d.", + getData().getLineNumber())); + } + } + } + + @Override + public InternetArticle createPublication() { + final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + + final InternetArticle article = new InternetArticle(); + article.setContentSection(folder.getContentSection()); + article.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + + final InternetArticleBundle bundle = new InternetArticleBundle(article); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + + return article; + } + +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/MonographImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/MonographImporter.java new file mode 100644 index 000000000..c33c25325 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/MonographImporter.java @@ -0,0 +1,38 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.Monograph; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.PublicationWithPublisherBundle; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.kernel.Kernel; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class MonographImporter extends AbstractPublicationWithPublisherImporter { + + protected MonographImporter(final CsvLine data, final PublicationImportReport report) { + super(data, report); + } + + @Override + protected Monograph createPublication() { + final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + + final Monograph monograph = new Monograph(); + monograph.setContentSection(folder.getContentSection()); + monograph.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + + final PublicationWithPublisherBundle bundle = new PublicationWithPublisherBundle(monograph); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + + return monograph; + } + +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ProceedingsImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ProceedingsImporter.java new file mode 100644 index 000000000..6b6f48434 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ProceedingsImporter.java @@ -0,0 +1,52 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.Proceedings; +import com.arsdigita.cms.contenttypes.ProceedingsBundle; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.kernel.Kernel; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class ProceedingsImporter extends AbstractPublicationWithPublisherImporter { + + public ProceedingsImporter(final CsvLine data, final PublicationImportReport report) { + super(data, report); + } + + @Override + public Proceedings importPublication() { + final Proceedings proceedings = super.importPublication(); + final CsvLine data = getData(); + final PublicationImportReport report = getReport(); + + if ((data.getConference() != null) && !data.getConference().isEmpty()) { + proceedings.setNameOfConference(data.getConference()); + report.addField(new FieldImportReport("Name of conference", data.getConference())); + } + + return proceedings; + } + + @Override + protected Proceedings createPublication() { + final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + + final Proceedings proceedings = new Proceedings(); + proceedings.setContentSection(folder.getContentSection()); + proceedings.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + + final ProceedingsBundle bundle = new ProceedingsBundle(proceedings); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + + return proceedings; + } +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/PublicationsImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/PublicationsImporter.java new file mode 100644 index 000000000..0797be640 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/PublicationsImporter.java @@ -0,0 +1,411 @@ +/* + * Copyright (c) 2012 Jens Pelzetter, ScientificCMS.org team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.contenttypes.ArticleInCollectedVolume; +import com.arsdigita.cms.contenttypes.ArticleInJournal; +import com.arsdigita.cms.contenttypes.CollectedVolume; +import com.arsdigita.cms.contenttypes.Expertise; +import com.arsdigita.cms.contenttypes.GreyLiterature; +import com.arsdigita.cms.contenttypes.InProceedings; +import com.arsdigita.cms.contenttypes.InternetArticle; +import com.arsdigita.cms.contenttypes.Monograph; +import com.arsdigita.cms.contenttypes.Proceedings; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.Review; +import com.arsdigita.cms.contenttypes.WorkingPaper; +import com.arsdigita.cms.scipublications.imexporter.PublicationFormat; +import com.arsdigita.cms.scipublications.importer.SciPublicationsImporter; +import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; +import com.arsdigita.cms.scipublications.importer.report.ImportReport; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.Filter; +import com.arsdigita.persistence.FilterFactory; +import com.arsdigita.persistence.Session; +import com.arsdigita.persistence.SessionManager; +import com.arsdigita.persistence.TransactionContext; +import java.util.Arrays; +import javax.activation.MimeType; +import javax.activation.MimeTypeParseException; +import org.apache.log4j.Logger; + +public class PublicationsImporter implements SciPublicationsImporter { + + private static final Logger LOGGER = Logger.getLogger(PublicationsImporter.class); + private static final String LINE_SEP = "\n"; + private static final String COL_SEP = "\t"; +// private static final String AUTHORS_SEP = ";"; +// private static final String AUTHOR_NAME_SEP = ","; +// private static final String DR_TITLE = "Dr."; +// private static final String PROF_DR = "Prof. Dr."; + + public PublicationFormat getSupportedFormat() { + try { + return new PublicationFormat("CSV", + new MimeType("text", "csv"), + "csv"); + } catch (MimeTypeParseException ex) { + LOGGER.warn("Failed to create MimeType for PublicationFormat." + + "Using null mimetype instead. Cause: ", ex); + return new PublicationFormat("CSV", + null, + "csv"); + + } + } + + public ImportReport importPublications(final String publications, + final boolean pretend, + final boolean publishNewItems) { + final String[] linesWithHeader = publications.split(LINE_SEP); + final String[] lines = Arrays.copyOfRange(linesWithHeader, 1, linesWithHeader.length); + final ImportReport report = new ImportReport(); + + report.setImporter("CSV Importer"); + report.setPretend(pretend); + + final Session session = SessionManager.getSession(); + final TransactionContext tctx = session.getTransactionContext(); + tctx.beginTxn(); + + int lineNumber = 2; //Because we are starting at line 2 of the CSV file (line 1 contains the column headers) + for (String line : lines) { + final PublicationImportReport result = importPublication(line, lineNumber, publishNewItems); + report.addPublication(result); + lineNumber++; + } + + if (pretend) { + tctx.abortTxn(); + } else { + tctx.commitTxn(); + } + + return report; + } + + private PublicationImportReport importPublication(final String line, + final int lineNumber, + final boolean publishNewItems) { + final PublicationImportReport report = new PublicationImportReport(); + + final String[] cols = line.split(COL_SEP); + //Check number of cols + if (cols.length == 30) { + report.setSuccessful(false); + report.addMessage(String.format("!!! Wrong number of columns. Exepcted 30 columns but found %d columns. " + + "Skiping line %d!\n", cols.length, lineNumber)); + } + + final CsvLine data = new CsvLine(cols, lineNumber); + + if (ArticleInCollectedVolume.class.getSimpleName().equals(data.getType())) { + processArticleInCollectedVolume(publishNewItems, data, report); + } else if (ArticleInCollectedVolume.class.getSimpleName().equals(data.getType())) { + processArticleInJournal(publishNewItems, data, report); + } else if (CollectedVolume.class.getSimpleName().equals(data.getType())) { + processCollectedVolume(publishNewItems, data, report); + } else if (Expertise.class.getSimpleName().equals(data.getType())) { + processExpertise(publishNewItems, data, report); + } else if (GreyLiterature.class.getSimpleName().equals(data.getType())) { + processGreyLiterature(publishNewItems, data, report); + } else if (InProceedings.class.getSimpleName().equals(data.getType())) { + processInProceedings(publishNewItems, data, report); + } else if (InternetArticle.class.getSimpleName().equals(data.getType())) { + processInternetArticle(publishNewItems, data, report); + } else if (Monograph.class.getSimpleName().equals(data.getType())) { + processMonograph(publishNewItems, data, report); + } else if (Proceedings.class.getSimpleName().equals(data.getType())) { + processProceedings(publishNewItems, data, report); + } else if (Review.class.getSimpleName().equals(data.getType())) { + processReview(publishNewItems, data, report); + } else if (WorkingPaper.class.getSimpleName().equals(data.getType())) { + processWorkingPaper(publishNewItems, data, report); + } + + return report; + } + + private void processArticleInCollectedVolume(final boolean publishNewItems, + final CsvLine data, + final PublicationImportReport report) { + if (isPublicationAlreadyInDatabase(data, ArticleInCollectedVolume.class.getSimpleName(), report)) { + return; + } + + final ArticleInCollectedVolumeImporter importer = new ArticleInCollectedVolumeImporter(data, report); + importer.doImport(publishNewItems); + } + + private void processArticleInJournal(final boolean publishNewItems, + final CsvLine data, + final PublicationImportReport report) { + if (isPublicationAlreadyInDatabase(data, ArticleInJournal.class.getSimpleName(), report)) { + return; + } + + final ArticleInJournalImporter importer = new ArticleInJournalImporter(data, report); + importer.doImport(publishNewItems); + } + + private void processCollectedVolume(final boolean publishNewItems, + final CsvLine data, + final PublicationImportReport report) { + if (isPublicationAlreadyInDatabase(data, CollectedVolume.class.getSimpleName(), report)) { + return; + } + + final CollectedVolumeImporter importer = new CollectedVolumeImporter(data, report); + importer.doImport(publishNewItems); + } + + private void processExpertise(final boolean publishNewItems, final CsvLine data, + final PublicationImportReport report) { + if (isPublicationAlreadyInDatabase(data, Expertise.class.getSimpleName(), report)) { + return; + } + + final ExpertiseImporter importer = new ExpertiseImporter(data, report); + importer.doImport(publishNewItems); + } + + private void processGreyLiterature(final boolean publishNewItems, + final CsvLine data, + final PublicationImportReport report) { + if (isPublicationAlreadyInDatabase(data, GreyLiterature.class.getSimpleName(), report)) { + return; + } + + final GreyLiteratureImporter importer = new GreyLiteratureImporter(data, report); + importer.doImport(publishNewItems); + } + + private void processInProceedings(final boolean publishNewItems, + final CsvLine data, + final PublicationImportReport report) { + if (isPublicationAlreadyInDatabase(data, InProceedings.class.getSimpleName(), report)) { + return; + } + + final InProceedingsImporter importer = new InProceedingsImporter(data, report); + importer.doImport(publishNewItems); + } + + private void processInternetArticle(final boolean publishNewItems, + final CsvLine data, + final PublicationImportReport report) { + if (isPublicationAlreadyInDatabase(data, InternetArticle.class.getSimpleName(), report)) { + return; + } + + final InternetArticleImporter importer = new InternetArticleImporter(data, report); + importer.doImport(publishNewItems); + } + + private void processMonograph(final boolean publishNewItems, + final CsvLine data, + final PublicationImportReport report) { + if (isPublicationAlreadyInDatabase(data, Monograph.class.getSimpleName(), report)) { + return; + } + + final MonographImporter importer = new MonographImporter(data, report); + importer.doImport(publishNewItems); + } + + private void processProceedings(final boolean publishNewItems, + final CsvLine data, + final PublicationImportReport report) { + if (isPublicationAlreadyInDatabase(data, Proceedings.class.getSimpleName(), report)) { + return; + } + + final ProceedingsImporter importer = new ProceedingsImporter(data, report); + importer.doImport(publishNewItems); + } + + private void processReview(final boolean publishNewItems, + final CsvLine data, + final PublicationImportReport report) { + if (isPublicationAlreadyInDatabase(data, Review.class.getSimpleName(), report)) { + return; + } + + final ReviewImporter importer = new ReviewImporter(data, report); + importer.doImport(publishNewItems); + + } + + private void processWorkingPaper(final boolean publishNewItems, + final CsvLine data, + final PublicationImportReport report) { + if (isPublicationAlreadyInDatabase(data, WorkingPaper.class.getSimpleName(), report)) { + return; + } + + final WorkingPaperImporter importer = new WorkingPaperImporter(data, report); + importer.doImport(publishNewItems); + } + +// private List parseAuthors(final boolean publishNewItems, final String authorsStr, final PublicationImportReport report) { +// final List authors = new ArrayList(); +// +// final String[] tokens = authorsStr.split(AUTHORS_SEP); +// reportWriter.printf("Found %d authors...\n", tokens.length); +// +// for (String token : tokens) { +// parseAuthor(token, authors, reportWriter); +// } +// +// return authors; +// } + private boolean isPublicationAlreadyInDatabase(final CsvLine data, + final String type, + final PublicationImportReport report) { + final String title = data.getTitle(); + final String year = data.getYear(); + + int yearOfPublication; + try { + yearOfPublication = Integer.parseInt(year); + } catch (NumberFormatException ex) { + yearOfPublication = 0; + } + + final Session session = SessionManager.getSession(); + final DataCollection collection = session.retrieve(Publication.BASE_DATA_OBJECT_TYPE); + final FilterFactory filterFactory = collection.getFilterFactory(); + final Filter titleFilter = filterFactory.equals("title", title); + final Filter yearFilter = filterFactory.equals("yearOfPublication", yearOfPublication); + collection.addFilter(titleFilter); + collection.addFilter(yearFilter); + + final boolean result = collection.isEmpty(); + collection.close(); + + report.setTitle(title); + report.setType(type); + report.addField(new FieldImportReport("Year of publication", year)); + report.setAlreadyInDatabase(true); + + return result; + } + +// private int parseYear(final CsvLine data, final PublicationImportReport report) { +// int year = 0; +// try { +// year = Integer.parseInt(data.getYear()); +// } catch (NumberFormatException ex) { +// report.addMessage(String.format("Can't parse year of publication into an integer in CSV line %d\n", +// data.getLineNumber())); +// } +// +// return year; +// } +// private void parseAuthor(final String authorToken, final List authors, +// final PublicationImportReport report) { +// final String[] nameTokens = authorToken.split(AUTHOR_NAME_SEP); +// +// final AuthorImportReport authorImportReport = new AuthorImportReport(); +// +// if (nameTokens.length == 1) { +// final AuthorData author = new AuthorData(); +// author.setSurname(nameTokens[0]); +// authorImportReport.setSurname(nameTokens[0]); +// authors.add(author); +// } else if (nameTokens.length == 2) { +// final AuthorData author = new AuthorData(); +// author.setSurname(nameTokens[0]); +// author.setGivenName(nameTokens[1]); +// authorImportReport.setSurname(nameTokens[0]); +// authorImportReport.setGivenName(nameTokens[1]); +// +// authors.add(author); +// } else { +// final AuthorData author = new AuthorData(); +// author.setSurname(nameTokens[0]); +// author.setGivenName(nameTokens[1]); +// authorImportReport.setSurname(nameTokens[0]); +// authorImportReport.setGivenName(nameTokens[1]); +// authors.add(author); +// } +// } +// private class AuthorData { +// +// private String surname; +// private String givenName; +// private boolean editor; +// +// public AuthorData() { +// //Nothing +// } +// +// public String getSurname() { +// if (surname == null) { +// return ""; +// } else { +// return surname.trim(); +// } +// } +// +// public void setSurname(final String surname) { +// if (surname.startsWith(DR_TITLE)) { +// this.surname = surname.substring(DR_TITLE.length()); +// } else if (surname.startsWith(PROF_DR)) { +// this.surname = surname.substring(PROF_DR.length()); +// } else { +// this.surname = surname; +// } +// } +// +// public String getGivenName() { +// if (givenName == null) { +// return ""; +// } else { +// return givenName.trim(); +// } +// } +// +// public void setGivenName(final String givenName) { +// this.givenName = givenName; +// } +// +// public boolean isEditor() { +// return editor; +// } +// +// public void setEditor(final boolean editor) { +// this.editor = editor; +// } +// +// } +// +// private String normalizeString(final String str) { +// if (str == null) { +// return "null"; +// } +// return str.replace("ä", "ae").replace("ö", "oe").replace("ü", "ue"). +// replace( +// "Ä", "Ae").replace("Ü", "Ue").replace("Ö", "Oe").replace("ß", +// "ss"). +// replace(" ", "-"). +// replaceAll("[^a-zA-Z0-9\\-]", "").toLowerCase().trim(); +// } +} \ No newline at end of file diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ReviewImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ReviewImporter.java new file mode 100644 index 000000000..97a7bd7e7 --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/ReviewImporter.java @@ -0,0 +1,41 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.ArticleInJournal; +import com.arsdigita.cms.contenttypes.ArticleInJournalBundle; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.Review; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.kernel.Kernel; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class ReviewImporter extends ArticleInJournalImporter { + + public ReviewImporter(final CsvLine data, final PublicationImportReport report) { + super(data, report); + } + + + @Override + protected ArticleInJournal createPublication() { + final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + + final Review review = new Review(); + review.setContentSection(folder.getContentSection()); + review.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + + final ArticleInJournalBundle bundle = new ArticleInJournalBundle(review); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + + return review; + } + + +} diff --git a/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/WorkingPaperImporter.java b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/WorkingPaperImporter.java new file mode 100644 index 000000000..dd937109c --- /dev/null +++ b/ccm-sci-publicationscsvimporter/src/com/arsdigita/cms/scipublications/importer/csv/WorkingPaperImporter.java @@ -0,0 +1,39 @@ +package com.arsdigita.cms.scipublications.importer.csv; + +import com.arsdigita.cms.Folder; +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.PublicationBundle; +import com.arsdigita.cms.contenttypes.UnPublished; +import com.arsdigita.cms.contenttypes.WorkingPaper; +import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; +import com.arsdigita.kernel.Kernel; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +class WorkingPaperImporter extends AbstractUnPublishedImporter { + + protected WorkingPaperImporter(final CsvLine data, final PublicationImportReport report) { + super(data, report); + } + + @Override + protected WorkingPaper createPublication() { + final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); + final Folder folder = new Folder(new BigDecimal(folderId)); + + final WorkingPaper workingPaper = new WorkingPaper(); + workingPaper.setContentSection(folder.getContentSection()); + workingPaper.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); + + final PublicationBundle bundle = new PublicationBundle(workingPaper); + bundle.setParent(folder); + bundle.setContentSection(folder.getContentSection()); + + return workingPaper; + } + +} diff --git a/ccm-sci-publicationscsvimporter/src/empty.pdl.mf b/ccm-sci-publicationscsvimporter/src/empty.pdl.mf new file mode 100644 index 000000000..e69de29bb