Infrastruktur für Importer für Publikationen und CSV Importer als Beispiel
git-svn-id: https://svn.libreccm.org/ccm/trunk@1889 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
f821d63d39
commit
c9e969bb13
|
|
@ -26,6 +26,7 @@ public class PublicationsConfig extends AbstractConfig {
|
||||||
private final Parameter defaultProceedingsFolder;
|
private final Parameter defaultProceedingsFolder;
|
||||||
private final Parameter defaultInProceedingsFolder;
|
private final Parameter defaultInProceedingsFolder;
|
||||||
private final Parameter defaultArticlesInJournalFolder;
|
private final Parameter defaultArticlesInJournalFolder;
|
||||||
|
private final Parameter defaultPublicationsFolder;
|
||||||
|
|
||||||
public PublicationsConfig() {
|
public PublicationsConfig() {
|
||||||
attachOrgaUnitsStep =
|
attachOrgaUnitsStep =
|
||||||
|
|
@ -90,6 +91,11 @@ public class PublicationsConfig extends AbstractConfig {
|
||||||
Parameter.OPTIONAL,
|
Parameter.OPTIONAL,
|
||||||
null);
|
null);
|
||||||
|
|
||||||
|
defaultPublicationsFolder = new IntegerParameter(
|
||||||
|
"com.arsdigita.cms.contenttypes.publications.default_publications_folder",
|
||||||
|
Parameter.OPTIONAL,
|
||||||
|
null);
|
||||||
|
|
||||||
register(attachOrgaUnitsStep);
|
register(attachOrgaUnitsStep);
|
||||||
register(attachPublicationsStepTo);
|
register(attachPublicationsStepTo);
|
||||||
register(defaultAuthorsFolder);
|
register(defaultAuthorsFolder);
|
||||||
|
|
@ -102,6 +108,7 @@ public class PublicationsConfig extends AbstractConfig {
|
||||||
register(defaultProceedingsFolder);
|
register(defaultProceedingsFolder);
|
||||||
register(defaultInProceedingsFolder);
|
register(defaultInProceedingsFolder);
|
||||||
register(defaultArticlesInJournalFolder);
|
register(defaultArticlesInJournalFolder);
|
||||||
|
register(defaultPublicationsFolder);
|
||||||
|
|
||||||
loadInfo();
|
loadInfo();
|
||||||
}
|
}
|
||||||
|
|
@ -193,4 +200,13 @@ public class PublicationsConfig extends AbstractConfig {
|
||||||
return (Integer) get(defaultArticlesInJournalFolder);
|
return (Integer) get(defaultArticlesInJournalFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getDefaultPublicationsFolder() {
|
||||||
|
if (get(defaultPublicationsFolder) == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return (Integer) get(defaultPublicationsFolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,3 +57,8 @@ com.arsdigita.cms.contenttypes.publications.default_articlesinjournal_folder.tit
|
||||||
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.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.example = 10002
|
||||||
com.arsdigita.cms.contenttypes.publications.default_articlesinjournal_folder.format = Integer
|
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
|
||||||
|
|
@ -19,15 +19,16 @@
|
||||||
package com.arsdigita.cms.scipublications.importer;
|
package com.arsdigita.cms.scipublications.importer;
|
||||||
|
|
||||||
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.ImportReport;
|
||||||
import com.arsdigita.util.cmd.Program;
|
import com.arsdigita.util.cmd.Program;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.cli.OptionBuilder;
|
import org.apache.commons.cli.OptionBuilder;
|
||||||
import org.apache.commons.cli.Options;
|
import org.apache.commons.cli.Options;
|
||||||
import org.apache.commons.io.FileUtils;
|
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 {
|
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 PRETEND = "pretend";
|
||||||
private static final String PUBLISH = "publish";
|
private static final String PUBLISH = "publish";
|
||||||
private static final String LIST = "list";
|
private static final String LIST = "list";
|
||||||
|
|
@ -66,14 +67,17 @@ public class ImporterCli extends Program {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doRun(final CommandLine cmdLine) {
|
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)) {
|
if (cmdLine.hasOption(LIST)) {
|
||||||
final List<PublicationFormat> formats = SciPublicationsImporters.getInstance().getSupportedFormats();
|
final List<PublicationFormat> formats = SciPublicationsImporters.getInstance().getSupportedFormats();
|
||||||
LOGGER.info("Supported formats:");
|
writer.printf("Supported formats:\n");
|
||||||
for(PublicationFormat format : formats) {
|
for (PublicationFormat format : formats) {
|
||||||
LOGGER.info(String.format("%s, MIME type: %s, file extension: %s", format.getName(),
|
writer.printf("%s, MIME type: %s, file extension: %s\n", format.getName(),
|
||||||
format.getMimeType().toString(),
|
format.getMimeType().toString(),
|
||||||
format.getFileExtension()));
|
format.getFileExtension());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -82,7 +86,7 @@ public class ImporterCli extends Program {
|
||||||
final boolean publish = cmdLine.hasOption(PUBLISH);
|
final boolean publish = cmdLine.hasOption(PUBLISH);
|
||||||
|
|
||||||
if (cmdLine.getArgs().length != 1) {
|
if (cmdLine.getArgs().length != 1) {
|
||||||
LOGGER.error("Missing file/directory to import.");
|
errWriter.printf("Missing file/directory to import.\n");
|
||||||
help(System.err);
|
help(System.err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -93,6 +97,9 @@ public class ImporterCli extends Program {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void importFile(final File file, final boolean pretend, final boolean publish) {
|
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) {
|
if (file == null) {
|
||||||
throw new IllegalArgumentException("File object is null.");
|
throw new IllegalArgumentException("File object is null.");
|
||||||
}
|
}
|
||||||
|
|
@ -107,8 +114,8 @@ public class ImporterCli extends Program {
|
||||||
final String extension = fileName.substring(fileName.lastIndexOf('.'));
|
final String extension = fileName.substring(fileName.lastIndexOf('.'));
|
||||||
final PublicationFormat format = findFormatForExtension(extension);
|
final PublicationFormat format = findFormatForExtension(extension);
|
||||||
if (format == null) {
|
if (format == null) {
|
||||||
LOGGER.error(String.format("No importer for publication format identified "
|
errWriter.printf(String.format("No importer for publication format identified "
|
||||||
+ "by file extension '%s' available.",
|
+ "by file extension '%s' available.\n",
|
||||||
extension));
|
extension));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -119,13 +126,16 @@ public class ImporterCli extends Program {
|
||||||
try {
|
try {
|
||||||
data = FileUtils.readFileToString(file);
|
data = FileUtils.readFileToString(file);
|
||||||
} catch (IOException ex) {
|
} 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;
|
return;
|
||||||
}
|
}
|
||||||
LOGGER.info(String.format("Importing publications from file '%s'...", file.getAbsolutePath()));
|
writer.printf("Importing publications from file '%s'...\n", file.getAbsolutePath());
|
||||||
importer.importPublications(data, pretend, publish);
|
final ImportReport report = importer.importPublications(data, pretend, publish);
|
||||||
|
|
||||||
|
writer.printf("Import finished. Report:\n\n");
|
||||||
|
writer.print(report.toString());
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info(String.format("File %s does not exist.", file.getAbsolutePath()));
|
errWriter.printf("File %s does not exist.\n", file.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
package com.arsdigita.cms.scipublications.importer;
|
package com.arsdigita.cms.scipublications.importer;
|
||||||
|
|
||||||
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.ImportReport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for publication importers
|
* 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
|
* @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.
|
* or to check an file containing publications.
|
||||||
* @param publishNewItems If set to {@code true} the items created by the importer will also be published.
|
* @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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.arsdigita.cms.scipublications.importer.report;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class CollectedVolumeImportReport {
|
||||||
|
|
||||||
|
private String collectedVolumeTitle;
|
||||||
|
private List<AuthorImportReport> authors = new ArrayList<AuthorImportReport>();
|
||||||
|
private boolean created;
|
||||||
|
|
||||||
|
public String getCollectedVolumeTitle() {
|
||||||
|
return collectedVolumeTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCollectedVolumeTitle(final String collectedVolumeTitle) {
|
||||||
|
this.collectedVolumeTitle = collectedVolumeTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AuthorImportReport> getAuthors() {
|
||||||
|
return Collections.unmodifiableList(authors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAuthor(final AuthorImportReport author) {
|
||||||
|
authors.add(author);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthors(final List<AuthorImportReport> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.arsdigita.cms.scipublications.importer.report;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class ImportReport {
|
||||||
|
|
||||||
|
private String importer;
|
||||||
|
private boolean pretend;
|
||||||
|
private List<PublicationImportReport> publications = new ArrayList<PublicationImportReport>();
|
||||||
|
|
||||||
|
public String getImporter() {
|
||||||
|
return importer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImporter(final String importer) {
|
||||||
|
this.importer = importer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PublicationImportReport> getPublications() {
|
||||||
|
return Collections.unmodifiableList(publications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPublication(final PublicationImportReport publication) {
|
||||||
|
publications.add(publication);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublications(final List<PublicationImportReport> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.arsdigita.cms.scipublications.importer.report;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.arsdigita.cms.scipublications.importer.report;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class ProceedingsImportReport {
|
||||||
|
|
||||||
|
private String proceedingsTitle;
|
||||||
|
private String conference;
|
||||||
|
private Date dateFromOfConference;
|
||||||
|
private Date dateToOfConference;
|
||||||
|
private List<AuthorImportReport> authors = new ArrayList<AuthorImportReport>();
|
||||||
|
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<AuthorImportReport> getAuthors() {
|
||||||
|
return Collections.unmodifiableList(authors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAuthor(final AuthorImportReport author) {
|
||||||
|
authors.add(author);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthors(final List<AuthorImportReport> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class PublicationImportReport {
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private String type;
|
||||||
|
private boolean alreadyInDatabase;
|
||||||
|
private List<FieldImportReport> fields = new ArrayList<FieldImportReport>();
|
||||||
|
private List<AuthorImportReport> authors = new ArrayList<AuthorImportReport>();
|
||||||
|
private PublisherImportReport publisher;
|
||||||
|
private CollectedVolumeImportReport collectedVolume;
|
||||||
|
private JournalImportReport journal;
|
||||||
|
private ProceedingsImportReport proceedings;
|
||||||
|
private List<OrganizationalUnitImportReport> orgaUnits = new ArrayList<OrganizationalUnitImportReport>();
|
||||||
|
private boolean successful;
|
||||||
|
private List<String> messages = new ArrayList<String>();
|
||||||
|
|
||||||
|
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<FieldImportReport> getFields() {
|
||||||
|
return Collections.unmodifiableList(fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addField(final FieldImportReport field) {
|
||||||
|
fields.add(field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFields(final List<FieldImportReport> fields) {
|
||||||
|
this.fields = fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AuthorImportReport> getAuthors() {
|
||||||
|
return Collections.unmodifiableList(authors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAuthor(final AuthorImportReport author) {
|
||||||
|
authors.add(author);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthors(final List<AuthorImportReport> 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<OrganizationalUnitImportReport> getOrgaUnits() {
|
||||||
|
return Collections.unmodifiableList(orgaUnits);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOrgaUnit(final OrganizationalUnitImportReport orgaUnit) {
|
||||||
|
orgaUnits.add(orgaUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrgaUnits(final List<OrganizationalUnitImportReport> orgaUnits) {
|
||||||
|
this.orgaUnits = orgaUnits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuccessful() {
|
||||||
|
return successful;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuccessful(final boolean successful) {
|
||||||
|
this.successful = successful;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getMessages() {
|
||||||
|
return Collections.unmodifiableList(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMessage(final String message) {
|
||||||
|
messages.add(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(final List<String> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.arsdigita.cms.scipublications.importer.report;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @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<AuthorData> 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<AuthorData> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<ccm:application xmlns:ccm="http://ccm.redhat.com/ccm-project"
|
||||||
|
name="ccm-sci-publicationscsvimporter"
|
||||||
|
version="6.6.0"
|
||||||
|
release="1"
|
||||||
|
webapp="ROOT">
|
||||||
|
|
||||||
|
<ccm:dependencies>
|
||||||
|
<ccm:requires name="ccm-core" version="6.6.0" relation="ge"/>
|
||||||
|
<ccm:requires name="ccm-cms" version="6.6.6" relation="ge"/>
|
||||||
|
<ccm:requires name="ccm-sci-publications" version="6.6.3" relation="ge"/>
|
||||||
|
</ccm:dependencies>
|
||||||
|
|
||||||
|
<ccm:directories>
|
||||||
|
<ccm:directory name="src"/>
|
||||||
|
</ccm:directories>
|
||||||
|
|
||||||
|
<ccm:contacts>
|
||||||
|
<ccm:contact uri="http://www.scientificcms.org" type="website"/>
|
||||||
|
<ccm:contact uri="mailto:info@scientificcms.org" type="support"/>
|
||||||
|
</ccm:contacts>
|
||||||
|
|
||||||
|
<ccm:description>
|
||||||
|
Importer for Publications using a CSV file. Only used for internal purposes
|
||||||
|
at the University of Bremen.
|
||||||
|
</ccm:description>
|
||||||
|
|
||||||
|
</ccm:application>
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
com.arsdigita.cms.scipublications.importer.csv.PublicationsImporter
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<registry>
|
||||||
|
<!-- Nothing -->
|
||||||
|
</registry>
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<load>
|
||||||
|
<requires>
|
||||||
|
<table name="inits"/>
|
||||||
|
<table name="acs_objects"/>
|
||||||
|
<table name="cms_items"/>
|
||||||
|
<table name="ct_publications"/>
|
||||||
|
<initializer class="com.arsdigita.cms.Initializer"/>
|
||||||
|
<initializer class="com.arsdigita.cms.contenttypes.PublicationInitializer"/>
|
||||||
|
</requires>
|
||||||
|
|
||||||
|
<provides>
|
||||||
|
<!--<initializer class="com.arsdigita.cms.scipublications.importer.csv.Initializer"/>-->
|
||||||
|
</provides>
|
||||||
|
<scripts>
|
||||||
|
<!--<data class="com.arsdigita.cms.scipublications.importer.csv.Loader"/>-->
|
||||||
|
</scripts>
|
||||||
|
</load>
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
abstract class AbstractPublicationImporter<T extends Publication> {
|
||||||
|
|
||||||
|
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:
|
||||||
|
* <pre>
|
||||||
|
* 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;
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @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<AuthorData> 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<AuthorData> parseAuthors(final String authorsStr) {
|
||||||
|
final List<AuthorData> authors = new ArrayList<AuthorData>();
|
||||||
|
|
||||||
|
final String[] tokens = authorsStr.split(AUTHORS_SEP);
|
||||||
|
for (String token : tokens) {
|
||||||
|
parseAuthor(token, authors);
|
||||||
|
}
|
||||||
|
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseAuthor(final String authorToken, final List<AuthorData> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
abstract class AbstractPublicationWithPublisherImporter<T extends PublicationWithPublisher>
|
||||||
|
extends AbstractPublicationImporter<T> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
abstract class AbstractUnPublishedImporter<T extends UnPublished> extends AbstractPublicationImporter<T> {
|
||||||
|
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
class ArticleInCollectedVolumeImporter extends AbstractPublicationImporter<ArticleInCollectedVolume> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
class ArticleInJournalImporter extends AbstractPublicationImporter<ArticleInJournal> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
class CollectedVolumeImporter extends AbstractPublicationWithPublisherImporter<CollectedVolume> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,147 @@
|
||||||
|
package com.arsdigita.cms.scipublications.importer.csv;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
class ExpertiseImporter extends AbstractPublicationImporter<Expertise> {
|
||||||
|
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
class GreyLiteratureImporter extends AbstractUnPublishedImporter<GreyLiterature> {
|
||||||
|
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
class InProceedingsImporter extends AbstractPublicationImporter<InProceedings> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
class InternetArticleImporter extends AbstractPublicationImporter<InternetArticle> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
class MonographImporter extends AbstractPublicationWithPublisherImporter<Monograph> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
class ProceedingsImporter extends AbstractPublicationWithPublisherImporter<Proceedings> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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<AuthorData> parseAuthors(final boolean publishNewItems, final String authorsStr, final PublicationImportReport report) {
|
||||||
|
// final List<AuthorData> authors = new ArrayList<AuthorData>();
|
||||||
|
//
|
||||||
|
// 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<AuthorData> 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();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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 <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
class WorkingPaperImporter extends AbstractUnPublishedImporter<UnPublished> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue