Aktueller Stand Importer für Publikationen, speziell CSV Importer
git-svn-id: https://svn.libreccm.org/ccm/trunk@1901 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
a840814b0d
commit
4cd1272548
|
|
@ -1,7 +1,6 @@
|
|||
package com.arsdigita.cms.contenttypes;
|
||||
|
||||
import com.arsdigita.runtime.AbstractConfig;
|
||||
|
||||
import com.arsdigita.util.parameter.BooleanParameter;
|
||||
import com.arsdigita.util.parameter.IntegerParameter;
|
||||
import com.arsdigita.util.parameter.Parameter;
|
||||
|
|
|
|||
|
|
@ -69,16 +69,18 @@ public class ImporterCli extends Program {
|
|||
protected void doRun(final CommandLine cmdLine) {
|
||||
final PrintWriter writer = new PrintWriter(System.out);
|
||||
final PrintWriter errWriter = new PrintWriter(System.err);
|
||||
|
||||
|
||||
writer.printf("Publications Importer CLI tool.\n");
|
||||
writer.flush();
|
||||
if (cmdLine.hasOption(LIST)) {
|
||||
final List<PublicationFormat> formats = SciPublicationsImporters.getInstance().getSupportedFormats();
|
||||
writer.printf("Supported formats:\n");
|
||||
for (PublicationFormat format : formats) {
|
||||
writer.printf("%s, MIME type: %s, file extension: %s\n", format.getName(),
|
||||
format.getMimeType().toString(),
|
||||
format.getFileExtension());
|
||||
format.getMimeType().toString(),
|
||||
format.getFileExtension());
|
||||
}
|
||||
writer.flush();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -87,6 +89,7 @@ public class ImporterCli extends Program {
|
|||
|
||||
if (cmdLine.getArgs().length != 1) {
|
||||
errWriter.printf("Missing file/directory to import.\n");
|
||||
errWriter.flush();
|
||||
help(System.err);
|
||||
return;
|
||||
}
|
||||
|
|
@ -94,6 +97,9 @@ public class ImporterCli extends Program {
|
|||
final String sourceName = cmdLine.getArgs()[0];
|
||||
final File source = new File(sourceName);
|
||||
importFile(source, pretend, publish);
|
||||
|
||||
errWriter.flush();
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
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()) {
|
||||
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);
|
||||
if (format == null) {
|
||||
errWriter.printf(String.format("No importer for publication format identified "
|
||||
+ "by file extension '%s' available.\n",
|
||||
extension));
|
||||
errWriter.flush();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -127,15 +134,29 @@ public class ImporterCli extends Program {
|
|||
data = FileUtils.readFileToString(file);
|
||||
} catch (IOException ex) {
|
||||
errWriter.printf(String.format("Failed to read file '%s'.\n", file.getAbsolutePath()), ex);
|
||||
errWriter.flush();
|
||||
return;
|
||||
}
|
||||
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.print(report.toString());
|
||||
writer.flush();
|
||||
} else {
|
||||
errWriter.printf("File %s does not exist.\n", file.getAbsolutePath());
|
||||
errWriter.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -42,7 +42,9 @@ public interface SciPublicationsImporter {
|
|||
* or to check an file containing publications.
|
||||
* @param publishNewItems If set to {@code true} the items created by the importer will also be published.
|
||||
* @return A report describing what the importer has done.
|
||||
* @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;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class SciPublicationsImporters {
|
|||
* specified format.
|
||||
*/
|
||||
public SciPublicationsImporter getImporterForFormat(final String format) {
|
||||
return importers.get(format);
|
||||
return importers.get(format.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -54,19 +54,21 @@ public class ImportReport {
|
|||
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.");
|
||||
writer.printf("Pretend mode is active. None of the publications in this report have been imported. The "
|
||||
+ "report only shows what would be done if the publications are truly imported.\n");
|
||||
}
|
||||
for(PublicationImportReport publication: publications) {
|
||||
for(int i = 0; i < 80; i++) {
|
||||
writer.append('-');
|
||||
}
|
||||
writer.append('\n');
|
||||
|
||||
writer.append(publication.toString());
|
||||
|
||||
for(int i = 0; i < 80; i++) {
|
||||
writer.append('-');
|
||||
}
|
||||
writer.append('\n');
|
||||
}
|
||||
|
||||
return strWriter.toString();
|
||||
|
|
|
|||
|
|
@ -145,15 +145,15 @@ public class PublicationImportReport {
|
|||
|
||||
writer.printf("%24s: %s\n", "title", title);
|
||||
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) {
|
||||
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());
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<registry>
|
||||
<!-- Nothing -->
|
||||
<config class="com.arsdigita.cms.scipublications.importer.csv.CsvImporterConfig" storage="ccm-sci-publications/csvimporter.properties"/>
|
||||
</registry>
|
||||
|
|
@ -1,16 +1,22 @@
|
|||
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.PublicationBundle;
|
||||
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 com.arsdigita.kernel.Kernel;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
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) {
|
||||
final T publication = importPublication();
|
||||
|
||||
publication.save();
|
||||
|
||||
assignCategories(publication.getPublicationBundle());
|
||||
|
||||
if (publishNewItems) {
|
||||
final Calendar now = new GregorianCalendar();
|
||||
final LifecycleDefinitionCollection lifecycles = publication.getContentSection().getLifecycleDefinitions();
|
||||
|
|
@ -56,6 +66,7 @@ abstract class AbstractPublicationImporter<T extends Publication> {
|
|||
final LifecycleDefinition lifecycleDef = lifecycles.getLifecycleDefinition();
|
||||
publication.publish(lifecycleDef, now.getTime());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,11 +91,29 @@ abstract class AbstractPublicationImporter<T extends Publication> {
|
|||
final T publication = createPublication();
|
||||
|
||||
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.setMisc(data.getMisc());
|
||||
processReviewed(publication);
|
||||
processAuthors(publication);
|
||||
|
||||
publication.save();
|
||||
|
||||
return publication;
|
||||
}
|
||||
|
||||
|
|
@ -95,6 +124,8 @@ abstract class AbstractPublicationImporter<T extends Publication> {
|
|||
*/
|
||||
protected abstract T createPublication();
|
||||
|
||||
protected abstract PublicationBundle createBundle(final T publication);
|
||||
|
||||
private void processTitleAndName(final T publication) {
|
||||
publication.setTitle(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
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.contenttypes.PublicationBundle;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -70,18 +67,12 @@ class ArticleInCollectedVolumeImporter extends AbstractPublicationImporter<Artic
|
|||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
protected ArticleInCollectedVolume createPublication() {
|
||||
return new ArticleInCollectedVolume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PublicationBundle createBundle(final ArticleInCollectedVolume article) {
|
||||
return new ArticleInCollectedVolumeBundle(article);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
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.PublicationBundle;
|
||||
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;
|
||||
|
|
@ -101,18 +98,12 @@ class ArticleInJournalImporter extends AbstractPublicationImporter<ArticleInJour
|
|||
|
||||
@Override
|
||||
protected ArticleInJournal createPublication() {
|
||||
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder();
|
||||
final Folder folder = new Folder(new BigDecimal(folderId));
|
||||
return new ArticleInJournal();
|
||||
}
|
||||
|
||||
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;
|
||||
@Override
|
||||
protected PublicationBundle createBundle(final ArticleInJournal article) {
|
||||
return new ArticleInJournalBundle(article);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
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.contenttypes.PublicationBundle;
|
||||
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
|
||||
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;
|
||||
return new CollectedVolume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PublicationBundle createBundle(final CollectedVolume collectedVolume) {
|
||||
return new CollectedVolumeBundle(collectedVolume);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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]
|
||||
|
||||
|
|
@ -1,13 +1,9 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -22,37 +18,21 @@ class ExpertiseImporter extends AbstractPublicationImporter<Expertise> {
|
|||
|
||||
@Override
|
||||
protected Expertise importPublication() {
|
||||
final Expertise expertise = super.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) {
|
||||
private void processNumberOfPages(final Expertise publication) {
|
||||
if ((getData().getNumberOfPages() != null) && !getData().getNumberOfPages().isEmpty()) {
|
||||
try {
|
||||
final int volume = Integer.parseInt(getData().getNumberOfPages());
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -30,22 +26,6 @@ class GreyLiteratureImporter extends AbstractUnPublishedImporter<GreyLiterature>
|
|||
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 {
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
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.contenttypes.PublicationBundle;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -66,18 +63,13 @@ class InProceedingsImporter extends AbstractPublicationImporter<InProceedings> {
|
|||
|
||||
@Override
|
||||
protected InProceedings createPublication() {
|
||||
final Integer folderId = Publication.getConfig().getDefaultPublicationsFolder();
|
||||
final Folder folder = new Folder(new BigDecimal(folderId));
|
||||
return new InProceedings();
|
||||
|
||||
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;
|
||||
@Override
|
||||
protected PublicationBundle createBundle(final InProceedings inProceedings) {
|
||||
return new InProceedingsBundle(inProceedings);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
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.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;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
|
@ -109,19 +106,12 @@ class InternetArticleImporter extends AbstractPublicationImporter<InternetArticl
|
|||
}
|
||||
|
||||
@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;
|
||||
protected InternetArticle createPublication() {
|
||||
return new InternetArticle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PublicationBundle createBundle(final InternetArticle article) {
|
||||
return new InternetArticleBundle(article);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
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.PublicationBundle;
|
||||
import com.arsdigita.cms.contenttypes.PublicationWithPublisherBundle;
|
||||
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
|
||||
import com.arsdigita.kernel.Kernel;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -20,19 +17,13 @@ class MonographImporter extends AbstractPublicationWithPublisherImporter<Monogra
|
|||
}
|
||||
|
||||
@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;
|
||||
protected Monograph createPublication() {
|
||||
return new Monograph();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PublicationBundle createBundle(final Monograph monograph) {
|
||||
return new PublicationWithPublisherBundle(monograph);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
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.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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -35,18 +32,12 @@ class ProceedingsImporter extends AbstractPublicationWithPublisherImporter<Proce
|
|||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
protected Proceedings createPublication() {
|
||||
return new Proceedings();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PublicationBundle createBundle(final Proceedings proceedings) {
|
||||
return new ProceedingsBundle(proceedings);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ 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.SciPublicationsImportException;
|
||||
import com.arsdigita.cms.scipublications.importer.SciPublicationsImporter;
|
||||
import com.arsdigita.cms.scipublications.importer.report.FieldImportReport;
|
||||
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 String LINE_SEP = "\n";
|
||||
private static final String COL_SEP = "\t";
|
||||
private static final CsvImporterConfig CONFIG = new CsvImporterConfig();
|
||||
// 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.";
|
||||
|
||||
static {
|
||||
CONFIG.load();
|
||||
}
|
||||
|
||||
public static CsvImporterConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
public PublicationFormat getSupportedFormat() {
|
||||
try {
|
||||
return new PublicationFormat("CSV",
|
||||
|
|
@ -71,9 +81,11 @@ public class PublicationsImporter implements SciPublicationsImporter {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImportReport importPublications(final String publications,
|
||||
final boolean pretend,
|
||||
final boolean publishNewItems) {
|
||||
final boolean publishNewItems)
|
||||
throws SciPublicationsImportException {
|
||||
final String[] linesWithHeader = publications.split(LINE_SEP);
|
||||
final String[] lines = Arrays.copyOfRange(linesWithHeader, 1, linesWithHeader.length);
|
||||
final ImportReport report = new ImportReport();
|
||||
|
|
@ -85,11 +97,16 @@ public class PublicationsImporter implements SciPublicationsImporter {
|
|||
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++;
|
||||
try {
|
||||
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++;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
tctx.abortTxn();
|
||||
throw new SciPublicationsImportException(ex);
|
||||
}
|
||||
|
||||
if (pretend) {
|
||||
|
|
@ -106,16 +123,21 @@ public class PublicationsImporter implements SciPublicationsImporter {
|
|||
final boolean publishNewItems) {
|
||||
final PublicationImportReport report = new PublicationImportReport();
|
||||
|
||||
final String[] cols = line.split(COL_SEP);
|
||||
//Check number of cols
|
||||
if (cols.length == 30) {
|
||||
final String[] cols = line.split(COL_SEP, -30);
|
||||
//Check number of cols
|
||||
System.err.println("Checking 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));
|
||||
return report;
|
||||
}
|
||||
System.err.println("Checked number of cols...");
|
||||
|
||||
System.err.println("Creating csv object...");
|
||||
final CsvLine data = new CsvLine(cols, lineNumber);
|
||||
|
||||
System.err.println("Calling importer...");
|
||||
if (ArticleInCollectedVolume.class.getSimpleName().equals(data.getType())) {
|
||||
processArticleInCollectedVolume(publishNewItems, data, report);
|
||||
} 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())) {
|
||||
processInternetArticle(publishNewItems, data, report);
|
||||
} else if (Monograph.class.getSimpleName().equals(data.getType())) {
|
||||
System.err.println("CAlling monograph importer...");
|
||||
processMonograph(publishNewItems, data, report);
|
||||
} else if (Proceedings.class.getSimpleName().equals(data.getType())) {
|
||||
processProceedings(publishNewItems, data, report);
|
||||
|
|
@ -236,6 +259,7 @@ public class PublicationsImporter implements SciPublicationsImporter {
|
|||
if (isPublicationAlreadyInDatabase(data, Proceedings.class.getSimpleName(), report)) {
|
||||
return;
|
||||
}
|
||||
System.err.println("Publication is not in database");
|
||||
|
||||
final ProceedingsImporter importer = new ProceedingsImporter(data, report);
|
||||
importer.doImport(publishNewItems);
|
||||
|
|
@ -297,13 +321,13 @@ public class PublicationsImporter implements SciPublicationsImporter {
|
|||
collection.addFilter(titleFilter);
|
||||
collection.addFilter(yearFilter);
|
||||
|
||||
final boolean result = collection.isEmpty();
|
||||
final boolean result = !collection.isEmpty();
|
||||
collection.close();
|
||||
|
||||
report.setTitle(title);
|
||||
report.setType(type);
|
||||
report.addField(new FieldImportReport("Year of publication", year));
|
||||
report.setAlreadyInDatabase(true);
|
||||
report.setAlreadyInDatabase(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -19,23 +14,10 @@ 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;
|
||||
return new Review();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +1,27 @@
|
|||
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> {
|
||||
class WorkingPaperImporter extends AbstractUnPublishedImporter<WorkingPaper> {
|
||||
|
||||
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;
|
||||
protected WorkingPaper createPublication() {
|
||||
return new WorkingPaper();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PublicationBundle createBundle(final WorkingPaper workingPaper) {
|
||||
return new PublicationBundle(workingPaper);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue