Aktueller Stand Importer für Publikationen, speziell CSV Importer

git-svn-id: https://svn.libreccm.org/ccm/trunk@1901 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2012-10-29 16:46:07 +00:00
parent a840814b0d
commit 4cd1272548
23 changed files with 358 additions and 223 deletions

View File

@ -1,7 +1,6 @@
package com.arsdigita.cms.contenttypes; package com.arsdigita.cms.contenttypes;
import com.arsdigita.runtime.AbstractConfig; import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.BooleanParameter; import com.arsdigita.util.parameter.BooleanParameter;
import com.arsdigita.util.parameter.IntegerParameter; import com.arsdigita.util.parameter.IntegerParameter;
import com.arsdigita.util.parameter.Parameter; import com.arsdigita.util.parameter.Parameter;

View File

@ -71,6 +71,7 @@ public class ImporterCli extends Program {
final PrintWriter errWriter = new PrintWriter(System.err); final PrintWriter errWriter = new PrintWriter(System.err);
writer.printf("Publications Importer CLI tool.\n"); writer.printf("Publications Importer CLI tool.\n");
writer.flush();
if (cmdLine.hasOption(LIST)) { if (cmdLine.hasOption(LIST)) {
final List<PublicationFormat> formats = SciPublicationsImporters.getInstance().getSupportedFormats(); final List<PublicationFormat> formats = SciPublicationsImporters.getInstance().getSupportedFormats();
writer.printf("Supported formats:\n"); writer.printf("Supported formats:\n");
@ -79,6 +80,7 @@ public class ImporterCli extends Program {
format.getMimeType().toString(), format.getMimeType().toString(),
format.getFileExtension()); format.getFileExtension());
} }
writer.flush();
return; return;
} }
@ -87,6 +89,7 @@ public class ImporterCli extends Program {
if (cmdLine.getArgs().length != 1) { if (cmdLine.getArgs().length != 1) {
errWriter.printf("Missing file/directory to import.\n"); errWriter.printf("Missing file/directory to import.\n");
errWriter.flush();
help(System.err); help(System.err);
return; return;
} }
@ -94,6 +97,9 @@ public class ImporterCli extends Program {
final String sourceName = cmdLine.getArgs()[0]; final String sourceName = cmdLine.getArgs()[0];
final File source = new File(sourceName); final File source = new File(sourceName);
importFile(source, pretend, publish); importFile(source, pretend, publish);
errWriter.flush();
writer.flush();
} }
protected void importFile(final File file, final boolean pretend, final boolean publish) { protected void importFile(final File file, final boolean pretend, final boolean publish) {
@ -111,12 +117,13 @@ public class ImporterCli extends Program {
} }
} else if (file.isFile()) { } else if (file.isFile()) {
final String fileName = file.getName(); final String fileName = file.getName();
final String extension = fileName.substring(fileName.lastIndexOf('.')); final String extension = fileName.substring(fileName.lastIndexOf('.') + 1);
final PublicationFormat format = findFormatForExtension(extension); final PublicationFormat format = findFormatForExtension(extension);
if (format == null) { if (format == null) {
errWriter.printf(String.format("No importer for publication format identified " errWriter.printf(String.format("No importer for publication format identified "
+ "by file extension '%s' available.\n", + "by file extension '%s' available.\n",
extension)); extension));
errWriter.flush();
return; return;
} }
@ -127,15 +134,29 @@ public class ImporterCli extends Program {
data = FileUtils.readFileToString(file); data = FileUtils.readFileToString(file);
} catch (IOException ex) { } catch (IOException ex) {
errWriter.printf(String.format("Failed to read file '%s'.\n", file.getAbsolutePath()), ex); errWriter.printf(String.format("Failed to read file '%s'.\n", file.getAbsolutePath()), ex);
errWriter.flush();
return; return;
} }
writer.printf("Importing publications from file '%s'...\n", file.getAbsolutePath()); writer.printf("Importing publications from file '%s'...\n", file.getAbsolutePath());
final ImportReport report = importer.importPublications(data, pretend, publish); writer.flush();
final ImportReport report;
try {
report = importer.importPublications(data, pretend, publish);
} catch (SciPublicationsImportException ex) {
errWriter.printf("Import failed:\n");
errWriter.printf("%s: %s\n", ex.getClass().getName(), ex.getMessage());
ex.printStackTrace(errWriter);
errWriter.flush();
writer.flush();
return;
}
writer.printf("Import finished. Report:\n\n"); writer.printf("Import finished. Report:\n\n");
writer.print(report.toString()); writer.print(report.toString());
writer.flush();
} else { } else {
errWriter.printf("File %s does not exist.\n", file.getAbsolutePath()); errWriter.printf("File %s does not exist.\n", file.getAbsolutePath());
errWriter.flush();
} }
} }

View File

@ -0,0 +1,49 @@
package com.arsdigita.cms.scipublications.importer;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class SciPublicationsImportException extends Exception {
private static final long serialVersionUID = 1L;
/**
* Creates a new instance of <code>SciPublicationsImportException</code> without detail message.
*/
public SciPublicationsImportException() {
super();
}
/**
* Constructs an instance of <code>SciPublicationsImportException</code> with the specified detail message.
*
* @param msg The detail message.
*/
public SciPublicationsImportException(final String msg) {
super(msg);
}
/**
* Constructs an instance of <code>SciPublicationsImportException</code> which wraps the
* specified exception.
*
* @param exception The exception to wrap.
*/
public SciPublicationsImportException(final Exception exception) {
super(exception);
}
/**
* Constructs an instance of <code>SciPublicationsImportException</code> with the specified message which also wraps the
* specified exception.
*
* @param msg The detail message.
* @param exception The exception to wrap.
*/
public SciPublicationsImportException(final String msg, final Exception exception) {
super(msg, exception);
}
}

View File

@ -42,7 +42,9 @@ public interface SciPublicationsImporter {
* 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.
* @throws SciPublicationsImportException If a none recoverable error occurs
*/ */
ImportReport importPublications(String publications, boolean pretend, boolean publishNewItems); ImportReport importPublications(String publications, boolean pretend, boolean publishNewItems)
throws SciPublicationsImportException;
} }

View File

@ -58,7 +58,7 @@ public class SciPublicationsImporters {
* specified format. * specified format.
*/ */
public SciPublicationsImporter getImporterForFormat(final String format) { public SciPublicationsImporter getImporterForFormat(final String format) {
return importers.get(format); return importers.get(format.toLowerCase());
} }
/** /**

View File

@ -54,19 +54,21 @@ public class ImportReport {
writer.printf("Number of publications imported: %d\n", publications.size()); writer.printf("Number of publications imported: %d\n", publications.size());
writer.printf("Pretend mode: %b\n", pretend); writer.printf("Pretend mode: %b\n", pretend);
if (pretend) { if (pretend) {
writer.printf("Pretend mode is active. None of the publications in this report have been imported. The" 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."); + "report only shows what would be done if the publications are truly imported.\n");
} }
for(PublicationImportReport publication: publications) { for(PublicationImportReport publication: publications) {
for(int i = 0; i < 80; i++) { for(int i = 0; i < 80; i++) {
writer.append('-'); writer.append('-');
} }
writer.append('\n');
writer.append(publication.toString()); writer.append(publication.toString());
for(int i = 0; i < 80; i++) { for(int i = 0; i < 80; i++) {
writer.append('-'); writer.append('-');
} }
writer.append('\n');
} }
return strWriter.toString(); return strWriter.toString();

View File

@ -145,7 +145,8 @@ public class PublicationImportReport {
writer.printf("%24s: %s\n", "title", title); writer.printf("%24s: %s\n", "title", title);
writer.printf("%24s: %s\n", "type", type); writer.printf("%24s: %s\n", "type", type);
writer.printf("%24s: %b\n", successful); writer.printf("%24s: %b\n", "Already in database", alreadyInDatabase);
writer.printf("%24s: %b\n", "successful", successful);
if (!successful) { if (!successful) {
writer.printf("Import failed. Messages from importer:\n "); writer.printf("Import failed. Messages from importer:\n ");
for(String message : messages) { for(String message : messages) {
@ -153,7 +154,6 @@ public class PublicationImportReport {
} }
return strWriter.toString(); return strWriter.toString();
} }
writer.printf("%24s: %b\n", "Already in database", alreadyInDatabase);
writer.printf("Authors:"); writer.printf("Authors:");
for(AuthorImportReport author: authors) { for(AuthorImportReport author: authors) {
writer.printf("%s\n", author.toString()); writer.printf("%s\n", author.toString());

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<registry> <registry>
<!-- Nothing --> <config class="com.arsdigita.cms.scipublications.importer.csv.CsvImporterConfig" storage="ccm-sci-publications/csvimporter.properties"/>
</registry> </registry>

View File

@ -1,16 +1,22 @@
package com.arsdigita.cms.scipublications.importer.csv; package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.categorization.Category;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contenttypes.Publication; import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.PublicationBundle;
import com.arsdigita.cms.lifecycle.LifecycleDefinition; import com.arsdigita.cms.lifecycle.LifecycleDefinition;
import com.arsdigita.cms.lifecycle.LifecycleDefinitionCollection; import com.arsdigita.cms.lifecycle.LifecycleDefinitionCollection;
import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; import com.arsdigita.cms.scipublications.importer.report.FieldImportReport;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.cms.scipublications.importer.util.AuthorData; import com.arsdigita.cms.scipublications.importer.util.AuthorData;
import com.arsdigita.cms.scipublications.importer.util.ImporterUtil; import com.arsdigita.cms.scipublications.importer.util.ImporterUtil;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* *
@ -48,7 +54,11 @@ abstract class AbstractPublicationImporter<T extends Publication> {
*/ */
public final void doImport(final boolean publishNewItems) { public final void doImport(final boolean publishNewItems) {
final T publication = importPublication(); final T publication = importPublication();
publication.save(); publication.save();
assignCategories(publication.getPublicationBundle());
if (publishNewItems) { if (publishNewItems) {
final Calendar now = new GregorianCalendar(); final Calendar now = new GregorianCalendar();
final LifecycleDefinitionCollection lifecycles = publication.getContentSection().getLifecycleDefinitions(); final LifecycleDefinitionCollection lifecycles = publication.getContentSection().getLifecycleDefinitions();
@ -56,6 +66,7 @@ abstract class AbstractPublicationImporter<T extends Publication> {
final LifecycleDefinition lifecycleDef = lifecycles.getLifecycleDefinition(); final LifecycleDefinition lifecycleDef = lifecycles.getLifecycleDefinition();
publication.publish(lifecycleDef, now.getTime()); publication.publish(lifecycleDef, now.getTime());
} }
} }
/** /**
@ -80,11 +91,29 @@ abstract class AbstractPublicationImporter<T extends Publication> {
final T publication = createPublication(); final T publication = createPublication();
processTitleAndName(publication); processTitleAndName(publication);
publication.save();
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder();
final Folder folder = new Folder(new BigDecimal(folderId));
publication.setContentSection(folder.getContentSection());
publication.setLanguage(Kernel.getConfig().getLanguagesIndependentCode());
publication.save();
final PublicationBundle bundle = createBundle(publication);
bundle.setParent(folder);
bundle.setContentSection(folder.getContentSection());
bundle.save();
publication.setAbstract(data.getAbstract()); publication.setAbstract(data.getAbstract());
publication.setMisc(data.getMisc()); publication.setMisc(data.getMisc());
processReviewed(publication); processReviewed(publication);
processAuthors(publication); processAuthors(publication);
publication.save();
return publication; return publication;
} }
@ -95,6 +124,8 @@ abstract class AbstractPublicationImporter<T extends Publication> {
*/ */
protected abstract T createPublication(); protected abstract T createPublication();
protected abstract PublicationBundle createBundle(final T publication);
private void processTitleAndName(final T publication) { private void processTitleAndName(final T publication) {
publication.setTitle(data.getTitle()); publication.setTitle(data.getTitle());
publication.setName(normalizeString(data.getTitle())); publication.setName(normalizeString(data.getTitle()));
@ -186,4 +217,27 @@ abstract class AbstractPublicationImporter<T extends Publication> {
} }
} }
private void assignCategories(final PublicationBundle publicationBundle) {
if ((data.getScope() != null) && "Persönlich".equals(data.getScope())) {
//Don't assign to a category, publications in only for personal profile
return;
}
final String[] departments = data.getDepartment().split(",");
final Category defaultCat = PublicationsImporter.getConfig().getDefaultCategory();
if (defaultCat != null) {
defaultCat.addChild(publicationBundle);
}
final Map<String, Category> depCats = PublicationsImporter.getConfig().getDepartmentCategories();
Category category;
for (String department : departments) {
category = depCats.get(department);
if (category != null) {
category.addChild(publicationBundle);
}
}
}
} }

View File

@ -1,14 +1,11 @@
package com.arsdigita.cms.scipublications.importer.csv; package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contenttypes.ArticleInCollectedVolume; import com.arsdigita.cms.contenttypes.ArticleInCollectedVolume;
import com.arsdigita.cms.contenttypes.ArticleInCollectedVolumeBundle; import com.arsdigita.cms.contenttypes.ArticleInCollectedVolumeBundle;
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.FieldImportReport;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.cms.scipublications.importer.util.ImporterUtil; import com.arsdigita.cms.scipublications.importer.util.ImporterUtil;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
/** /**
* *
@ -71,17 +68,11 @@ class ArticleInCollectedVolumeImporter extends AbstractPublicationImporter<Artic
@Override @Override
protected ArticleInCollectedVolume createPublication() { protected ArticleInCollectedVolume createPublication() {
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); return new ArticleInCollectedVolume();
final Folder folder = new Folder(new BigDecimal(folderId)); }
final ArticleInCollectedVolume article = new ArticleInCollectedVolume(); @Override
article.setContentSection(folder.getContentSection()); protected PublicationBundle createBundle(final ArticleInCollectedVolume article) {
article.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); return new ArticleInCollectedVolumeBundle(article);
final ArticleInCollectedVolumeBundle bundle = new ArticleInCollectedVolumeBundle(article);
bundle.setParent(folder);
bundle.setContentSection(folder.getContentSection());
return article;
} }
} }

View File

@ -1,14 +1,11 @@
package com.arsdigita.cms.scipublications.importer.csv; package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contenttypes.ArticleInJournal; import com.arsdigita.cms.contenttypes.ArticleInJournal;
import com.arsdigita.cms.contenttypes.ArticleInJournalBundle; import com.arsdigita.cms.contenttypes.ArticleInJournalBundle;
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.FieldImportReport;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.cms.scipublications.importer.util.ImporterUtil; import com.arsdigita.cms.scipublications.importer.util.ImporterUtil;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@ -101,18 +98,12 @@ class ArticleInJournalImporter extends AbstractPublicationImporter<ArticleInJour
@Override @Override
protected ArticleInJournal createPublication() { protected ArticleInJournal createPublication() {
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); return new ArticleInJournal();
final Folder folder = new Folder(new BigDecimal(folderId)); }
final ArticleInJournal article = new ArticleInJournal(); @Override
article.setContentSection(folder.getContentSection()); protected PublicationBundle createBundle(final ArticleInJournal article) {
article.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); return new ArticleInJournalBundle(article);
final ArticleInJournalBundle bundle = new ArticleInJournalBundle(article);
bundle.setParent(folder);
bundle.setContentSection(folder.getContentSection());
return article;
} }
} }

View File

@ -1,12 +1,9 @@
package com.arsdigita.cms.scipublications.importer.csv; package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contenttypes.CollectedVolume; import com.arsdigita.cms.contenttypes.CollectedVolume;
import com.arsdigita.cms.contenttypes.CollectedVolumeBundle; import com.arsdigita.cms.contenttypes.CollectedVolumeBundle;
import com.arsdigita.cms.contenttypes.Publication; import com.arsdigita.cms.contenttypes.PublicationBundle;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
/** /**
* *
@ -21,17 +18,12 @@ class CollectedVolumeImporter extends AbstractPublicationWithPublisherImporter<C
@Override @Override
protected CollectedVolume createPublication() { protected CollectedVolume createPublication() {
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); return new CollectedVolume();
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;
} }
@Override
protected PublicationBundle createBundle(final CollectedVolume collectedVolume) {
return new CollectedVolumeBundle(collectedVolume);
}
} }

View File

@ -0,0 +1,85 @@
package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.categorization.Category;
import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.IntegerParameter;
import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.StringParameter;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$
*/
public class CsvImporterConfig extends AbstractConfig {
private static final Logger LOGGER = Logger.getLogger(CsvImporterConfig.class);
private Parameter defaultCategoryId;
private Parameter departmentCategoryIds;
public CsvImporterConfig() {
super();
defaultCategoryId = new IntegerParameter("com.arsdigita.cms.scipublications.importer.csv.default_category_id",
Parameter.REQUIRED,
0);
departmentCategoryIds = new StringParameter(
"com.arsdigita.cms.scipublications.importer.csv.department_category_ids",
Parameter.REQUIRED,
"");
register(defaultCategoryId);
register(departmentCategoryIds);
loadInfo();
}
public Integer getDefaultCategoryId() {
return (Integer) get(defaultCategoryId);
}
public Category getDefaultCategory() {
final Integer categoryId = getDefaultCategoryId();
if (categoryId == 0) {
return null;
} else {
return new Category(new BigDecimal(categoryId));
}
}
public String getDepartmentCategoryIds() {
return (String) get(departmentCategoryIds);
}
public Map<String, Category> getDepartmentCategories() {
final String categoryIds = getDepartmentCategoryIds();
final Map<String, Category> categories = new HashMap<String, Category>();
final String[] departmentTokens = categoryIds.split(";");
for (String departmentToken : departmentTokens) {
processDepartmentToken(departmentToken, categories);
}
return categories;
}
private void processDepartmentToken(final String departmentToken, final Map<String, Category> categories) {
final String[] tokens = departmentToken.split(":");
if (tokens.length != 2) {
LOGGER.warn("Failed to parse department categories id property. Invalid department token.");
return;
}
final BigDecimal categoryId = new BigDecimal(tokens[1]);
final Category category = new Category(categoryId);
categories.put(tokens[0], category);
}
}

View File

@ -0,0 +1,10 @@
com.arsdigita.cms.scipublications.importer.csv.default_category_id.title = Default category for imported publications
com.arsdigita.cms.scipublications.importer.csv.default_category_id.purpose = All publications which are created during the import will be assigned to this category. The category set using the id of the category.
com.arsdigita.cms.scipublications.importer.csv.default_category_id.example = 12345
com.arsdigita.cms.scipublications.importer.csv.default_category_id.format = [Integer]
com.arsdigita.cms.scipublications.importer.csv.department_category_ids.title = Department categories
com.arsdigita.cms.scipublications.importer.csv.department_category_ids.purpose = Categories for the departments provided in the CSV. This property is formated string with this format: DepartmentId1:CategoryId1;DepartmentId2:CategoryId2;...
com.arsdigita.cms.scipublications.importer.csv.department_category_ids.example = 1:12345;2:67890
com.arsdigita.cms.scipublications.importer.csv.department_category_ids.format = [String]

View File

@ -1,13 +1,9 @@
package com.arsdigita.cms.scipublications.importer.csv; package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contenttypes.Expertise; import com.arsdigita.cms.contenttypes.Expertise;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.PublicationBundle; import com.arsdigita.cms.contenttypes.PublicationBundle;
import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; import com.arsdigita.cms.scipublications.importer.report.FieldImportReport;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
/** /**
* *
@ -36,22 +32,6 @@ class ExpertiseImporter extends AbstractPublicationImporter<Expertise> {
return 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) { private void processNumberOfPages(final Expertise publication) {
if ((getData().getNumberOfPages() != null) && !getData().getNumberOfPages().isEmpty()) { if ((getData().getNumberOfPages() != null) && !getData().getNumberOfPages().isEmpty()) {
try { try {
@ -64,4 +44,15 @@ class ExpertiseImporter extends AbstractPublicationImporter<Expertise> {
} }
} }
} }
@Override
protected Expertise createPublication() {
return new Expertise();
}
@Override
protected PublicationBundle createBundle(final Expertise expertise) {
return new PublicationBundle(expertise);
}
} }

View File

@ -1,13 +1,9 @@
package com.arsdigita.cms.scipublications.importer.csv; package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contenttypes.GreyLiterature; import com.arsdigita.cms.contenttypes.GreyLiterature;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.PublicationBundle; import com.arsdigita.cms.contenttypes.PublicationBundle;
import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; import com.arsdigita.cms.scipublications.importer.report.FieldImportReport;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
/** /**
* *
@ -30,22 +26,6 @@ class GreyLiteratureImporter extends AbstractUnPublishedImporter<GreyLiterature>
return 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) { private void processPagesFrom(final GreyLiterature publication) {
if ((getData().getPageFrom() != null) && !getData().getPageFrom().isEmpty()) { if ((getData().getPageFrom() != null) && !getData().getPageFrom().isEmpty()) {
try { try {
@ -70,4 +50,14 @@ class GreyLiteratureImporter extends AbstractUnPublishedImporter<GreyLiterature>
} }
} }
@Override
protected GreyLiterature createPublication() {
return new GreyLiterature();
}
@Override
protected PublicationBundle createBundle(final GreyLiterature greyLiterature) {
return new PublicationBundle(greyLiterature);
}
} }

View File

@ -1,14 +1,11 @@
package com.arsdigita.cms.scipublications.importer.csv; package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contenttypes.InProceedings; import com.arsdigita.cms.contenttypes.InProceedings;
import com.arsdigita.cms.contenttypes.InProceedingsBundle; import com.arsdigita.cms.contenttypes.InProceedingsBundle;
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.FieldImportReport;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.cms.scipublications.importer.util.ImporterUtil; import com.arsdigita.cms.scipublications.importer.util.ImporterUtil;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
/** /**
* *
@ -66,18 +63,13 @@ class InProceedingsImporter extends AbstractPublicationImporter<InProceedings> {
@Override @Override
protected InProceedings createPublication() { protected InProceedings createPublication() {
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); return new InProceedings();
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); @Override
bundle.setParent(folder); protected PublicationBundle createBundle(final InProceedings inProceedings) {
bundle.setContentSection(folder.getContentSection()); return new InProceedingsBundle(inProceedings);
return inProceedings;
} }
} }

View File

@ -1,13 +1,10 @@
package com.arsdigita.cms.scipublications.importer.csv; package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contenttypes.InternetArticle; import com.arsdigita.cms.contenttypes.InternetArticle;
import com.arsdigita.cms.contenttypes.InternetArticleBundle; import com.arsdigita.cms.contenttypes.InternetArticleBundle;
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.FieldImportReport;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@ -109,19 +106,12 @@ class InternetArticleImporter extends AbstractPublicationImporter<InternetArticl
} }
@Override @Override
public InternetArticle createPublication() { protected InternetArticle createPublication() {
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); return new InternetArticle();
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;
} }
@Override
protected PublicationBundle createBundle(final InternetArticle article) {
return new InternetArticleBundle(article);
}
} }

View File

@ -1,12 +1,9 @@
package com.arsdigita.cms.scipublications.importer.csv; package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contenttypes.Monograph; import com.arsdigita.cms.contenttypes.Monograph;
import com.arsdigita.cms.contenttypes.Publication; import com.arsdigita.cms.contenttypes.PublicationBundle;
import com.arsdigita.cms.contenttypes.PublicationWithPublisherBundle; import com.arsdigita.cms.contenttypes.PublicationWithPublisherBundle;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
/** /**
* *
@ -21,18 +18,12 @@ class MonographImporter extends AbstractPublicationWithPublisherImporter<Monogra
@Override @Override
protected Monograph createPublication() { protected Monograph createPublication() {
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); return new Monograph();
final Folder folder = new Folder(new BigDecimal(folderId)); }
final Monograph monograph = new Monograph(); @Override
monograph.setContentSection(folder.getContentSection()); protected PublicationBundle createBundle(final Monograph monograph) {
monograph.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); return new PublicationWithPublisherBundle(monograph);
final PublicationWithPublisherBundle bundle = new PublicationWithPublisherBundle(monograph);
bundle.setParent(folder);
bundle.setContentSection(folder.getContentSection());
return monograph;
} }
} }

View File

@ -1,13 +1,10 @@
package com.arsdigita.cms.scipublications.importer.csv; package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contenttypes.Proceedings; import com.arsdigita.cms.contenttypes.Proceedings;
import com.arsdigita.cms.contenttypes.ProceedingsBundle; import com.arsdigita.cms.contenttypes.ProceedingsBundle;
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.FieldImportReport;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
/** /**
* *
@ -36,17 +33,11 @@ class ProceedingsImporter extends AbstractPublicationWithPublisherImporter<Proce
@Override @Override
protected Proceedings createPublication() { protected Proceedings createPublication() {
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); return new Proceedings();
final Folder folder = new Folder(new BigDecimal(folderId)); }
final Proceedings proceedings = new Proceedings(); @Override
proceedings.setContentSection(folder.getContentSection()); protected PublicationBundle createBundle(final Proceedings proceedings) {
proceedings.setLanguage(Kernel.getConfig().getLanguagesIndependentCode()); return new ProceedingsBundle(proceedings);
final ProceedingsBundle bundle = new ProceedingsBundle(proceedings);
bundle.setParent(folder);
bundle.setContentSection(folder.getContentSection());
return proceedings;
} }
} }

View File

@ -31,6 +31,7 @@ import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.contenttypes.Review; import com.arsdigita.cms.contenttypes.Review;
import com.arsdigita.cms.contenttypes.WorkingPaper; import com.arsdigita.cms.contenttypes.WorkingPaper;
import com.arsdigita.cms.scipublications.imexporter.PublicationFormat; import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
import com.arsdigita.cms.scipublications.importer.SciPublicationsImportException;
import com.arsdigita.cms.scipublications.importer.SciPublicationsImporter; import com.arsdigita.cms.scipublications.importer.SciPublicationsImporter;
import com.arsdigita.cms.scipublications.importer.report.FieldImportReport; import com.arsdigita.cms.scipublications.importer.report.FieldImportReport;
import com.arsdigita.cms.scipublications.importer.report.ImportReport; import com.arsdigita.cms.scipublications.importer.report.ImportReport;
@ -51,11 +52,20 @@ public class PublicationsImporter implements SciPublicationsImporter {
private static final Logger LOGGER = Logger.getLogger(PublicationsImporter.class); private static final Logger LOGGER = Logger.getLogger(PublicationsImporter.class);
private static final String LINE_SEP = "\n"; private static final String LINE_SEP = "\n";
private static final String COL_SEP = "\t"; private static final String COL_SEP = "\t";
private static final CsvImporterConfig CONFIG = new CsvImporterConfig();
// private static final String AUTHORS_SEP = ";"; // private static final String AUTHORS_SEP = ";";
// private static final String AUTHOR_NAME_SEP = ","; // private static final String AUTHOR_NAME_SEP = ",";
// private static final String DR_TITLE = "Dr."; // private static final String DR_TITLE = "Dr.";
// private static final String PROF_DR = "Prof. Dr."; // private static final String PROF_DR = "Prof. Dr.";
static {
CONFIG.load();
}
public static CsvImporterConfig getConfig() {
return CONFIG;
}
public PublicationFormat getSupportedFormat() { public PublicationFormat getSupportedFormat() {
try { try {
return new PublicationFormat("CSV", return new PublicationFormat("CSV",
@ -71,9 +81,11 @@ public class PublicationsImporter implements SciPublicationsImporter {
} }
} }
@Override
public ImportReport importPublications(final String publications, public ImportReport importPublications(final String publications,
final boolean pretend, final boolean pretend,
final boolean publishNewItems) { final boolean publishNewItems)
throws SciPublicationsImportException {
final String[] linesWithHeader = publications.split(LINE_SEP); final String[] linesWithHeader = publications.split(LINE_SEP);
final String[] lines = Arrays.copyOfRange(linesWithHeader, 1, linesWithHeader.length); final String[] lines = Arrays.copyOfRange(linesWithHeader, 1, linesWithHeader.length);
final ImportReport report = new ImportReport(); final ImportReport report = new ImportReport();
@ -85,12 +97,17 @@ public class PublicationsImporter implements SciPublicationsImporter {
final TransactionContext tctx = session.getTransactionContext(); final TransactionContext tctx = session.getTransactionContext();
tctx.beginTxn(); tctx.beginTxn();
try {
int lineNumber = 2; //Because we are starting at line 2 of the CSV file (line 1 contains the column headers) int lineNumber = 2; //Because we are starting at line 2 of the CSV file (line 1 contains the column headers)
for (String line : lines) { for (String line : lines) {
final PublicationImportReport result = importPublication(line, lineNumber, publishNewItems); final PublicationImportReport result = importPublication(line, lineNumber, publishNewItems);
report.addPublication(result); report.addPublication(result);
lineNumber++; lineNumber++;
} }
} catch (Exception ex) {
tctx.abortTxn();
throw new SciPublicationsImportException(ex);
}
if (pretend) { if (pretend) {
tctx.abortTxn(); tctx.abortTxn();
@ -106,16 +123,21 @@ public class PublicationsImporter implements SciPublicationsImporter {
final boolean publishNewItems) { final boolean publishNewItems) {
final PublicationImportReport report = new PublicationImportReport(); final PublicationImportReport report = new PublicationImportReport();
final String[] cols = line.split(COL_SEP); final String[] cols = line.split(COL_SEP, -30);
//Check number of cols //Check number of cols
if (cols.length == 30) { System.err.println("Checking number of cols...");
if (cols.length != 30) {
report.setSuccessful(false); report.setSuccessful(false);
report.addMessage(String.format("!!! Wrong number of columns. Exepcted 30 columns but found %d columns. " report.addMessage(String.format("!!! Wrong number of columns. Exepcted 30 columns but found %d columns. "
+ "Skiping line %d!\n", cols.length, lineNumber)); + "Skiping line %d!\n", cols.length, lineNumber));
return report;
} }
System.err.println("Checked number of cols...");
System.err.println("Creating csv object...");
final CsvLine data = new CsvLine(cols, lineNumber); final CsvLine data = new CsvLine(cols, lineNumber);
System.err.println("Calling importer...");
if (ArticleInCollectedVolume.class.getSimpleName().equals(data.getType())) { if (ArticleInCollectedVolume.class.getSimpleName().equals(data.getType())) {
processArticleInCollectedVolume(publishNewItems, data, report); processArticleInCollectedVolume(publishNewItems, data, report);
} else if (ArticleInCollectedVolume.class.getSimpleName().equals(data.getType())) { } else if (ArticleInCollectedVolume.class.getSimpleName().equals(data.getType())) {
@ -131,6 +153,7 @@ public class PublicationsImporter implements SciPublicationsImporter {
} else if (InternetArticle.class.getSimpleName().equals(data.getType())) { } else if (InternetArticle.class.getSimpleName().equals(data.getType())) {
processInternetArticle(publishNewItems, data, report); processInternetArticle(publishNewItems, data, report);
} else if (Monograph.class.getSimpleName().equals(data.getType())) { } else if (Monograph.class.getSimpleName().equals(data.getType())) {
System.err.println("CAlling monograph importer...");
processMonograph(publishNewItems, data, report); processMonograph(publishNewItems, data, report);
} else if (Proceedings.class.getSimpleName().equals(data.getType())) { } else if (Proceedings.class.getSimpleName().equals(data.getType())) {
processProceedings(publishNewItems, data, report); processProceedings(publishNewItems, data, report);
@ -236,6 +259,7 @@ public class PublicationsImporter implements SciPublicationsImporter {
if (isPublicationAlreadyInDatabase(data, Proceedings.class.getSimpleName(), report)) { if (isPublicationAlreadyInDatabase(data, Proceedings.class.getSimpleName(), report)) {
return; return;
} }
System.err.println("Publication is not in database");
final ProceedingsImporter importer = new ProceedingsImporter(data, report); final ProceedingsImporter importer = new ProceedingsImporter(data, report);
importer.doImport(publishNewItems); importer.doImport(publishNewItems);
@ -297,13 +321,13 @@ public class PublicationsImporter implements SciPublicationsImporter {
collection.addFilter(titleFilter); collection.addFilter(titleFilter);
collection.addFilter(yearFilter); collection.addFilter(yearFilter);
final boolean result = collection.isEmpty(); final boolean result = !collection.isEmpty();
collection.close(); collection.close();
report.setTitle(title); report.setTitle(title);
report.setType(type); report.setType(type);
report.addField(new FieldImportReport("Year of publication", year)); report.addField(new FieldImportReport("Year of publication", year));
report.setAlreadyInDatabase(true); report.setAlreadyInDatabase(result);
return result; return result;
} }

View File

@ -1,13 +1,8 @@
package com.arsdigita.cms.scipublications.importer.csv; package com.arsdigita.cms.scipublications.importer.csv;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contenttypes.ArticleInJournal; 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.contenttypes.Review;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
/** /**
* *
@ -20,22 +15,9 @@ class ReviewImporter extends ArticleInJournalImporter {
super(data, report); super(data, report);
} }
@Override @Override
protected ArticleInJournal createPublication() { protected ArticleInJournal createPublication() {
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); return new Review();
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;
} }
} }

View File

@ -1,20 +1,15 @@
package com.arsdigita.cms.scipublications.importer.csv; 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.PublicationBundle;
import com.arsdigita.cms.contenttypes.UnPublished;
import com.arsdigita.cms.contenttypes.WorkingPaper; import com.arsdigita.cms.contenttypes.WorkingPaper;
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport; import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
import com.arsdigita.kernel.Kernel;
import java.math.BigDecimal;
/** /**
* *
* @author Jens Pelzetter <jens@jp-digital.de> * @author Jens Pelzetter <jens@jp-digital.de>
* @version $Id$ * @version $Id$
*/ */
class WorkingPaperImporter extends AbstractUnPublishedImporter<UnPublished> { class WorkingPaperImporter extends AbstractUnPublishedImporter<WorkingPaper> {
protected WorkingPaperImporter(final CsvLine data, final PublicationImportReport report) { protected WorkingPaperImporter(final CsvLine data, final PublicationImportReport report) {
super(data, report); super(data, report);
@ -22,18 +17,11 @@ class WorkingPaperImporter extends AbstractUnPublishedImporter<UnPublished> {
@Override @Override
protected WorkingPaper createPublication() { protected WorkingPaper createPublication() {
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder(); return new WorkingPaper();
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;
} }
@Override
protected PublicationBundle createBundle(final WorkingPaper workingPaper) {
return new PublicationBundle(workingPaper);
}
} }