Aktueller Stand RIS Importer
git-svn-id: https://svn.libreccm.org/ccm/trunk@2001 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
f610854202
commit
a1bed7b03a
|
|
@ -343,6 +343,10 @@ public enum RisField {
|
||||||
C1,
|
C1,
|
||||||
C2,
|
C2,
|
||||||
C3,
|
C3,
|
||||||
|
/**
|
||||||
|
* Number of volumes
|
||||||
|
*/
|
||||||
|
NV,
|
||||||
/**
|
/**
|
||||||
* Begin of a new reference. Value is the type of the reference.
|
* Begin of a new reference. Value is the type of the reference.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,14 @@ public enum RisType {
|
||||||
* Edited book
|
* Edited book
|
||||||
*/
|
*/
|
||||||
EDBOOK,
|
EDBOOK,
|
||||||
|
/**
|
||||||
|
* Electronic book
|
||||||
|
*/
|
||||||
|
EBOOK,
|
||||||
|
/**
|
||||||
|
* Electronic book section
|
||||||
|
*/
|
||||||
|
ECHAP,
|
||||||
/**
|
/**
|
||||||
* Electronic citation
|
* Electronic citation
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ public class PublicationImportReport {
|
||||||
private JournalImportReport journal;
|
private JournalImportReport journal;
|
||||||
private ProceedingsImportReport proceedings;
|
private ProceedingsImportReport proceedings;
|
||||||
private List<OrganizationalUnitImportReport> orgaUnits = new ArrayList<OrganizationalUnitImportReport>();
|
private List<OrganizationalUnitImportReport> orgaUnits = new ArrayList<OrganizationalUnitImportReport>();
|
||||||
|
private SeriesImportReport series;
|
||||||
private boolean successful;
|
private boolean successful;
|
||||||
private List<String> messages = new ArrayList<String>();
|
private List<String> messages = new ArrayList<String>();
|
||||||
|
|
||||||
|
|
@ -118,6 +119,14 @@ public class PublicationImportReport {
|
||||||
this.orgaUnits = orgaUnits;
|
this.orgaUnits = orgaUnits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SeriesImportReport getSeries() {
|
||||||
|
return series;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeries(final SeriesImportReport series) {
|
||||||
|
this.series = series;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isSuccessful() {
|
public boolean isSuccessful() {
|
||||||
return successful;
|
return successful;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.arsdigita.cms.scipublications.importer.report;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class SeriesImportReport {
|
||||||
|
|
||||||
|
private String seriesTitle;
|
||||||
|
private boolean created;
|
||||||
|
|
||||||
|
public String getSeriesTitle() {
|
||||||
|
return seriesTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeriesTitle(final String seriesTitle) {
|
||||||
|
this.seriesTitle = seriesTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCreated() {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreated(final boolean created) {
|
||||||
|
this.created = created;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (created) {
|
||||||
|
return String.format("Created series '%s' and linked series to publication.", seriesTitle);
|
||||||
|
} else {
|
||||||
|
return String.format("Found series '%s' in database and linked series to publication.", seriesTitle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.arsdigita.cms.scipublications.importer.ris;
|
package com.arsdigita.cms.scipublications.importer.ris;
|
||||||
|
|
||||||
import com.arsdigita.cms.contenttypes.Publication;
|
|
||||||
import com.arsdigita.cms.scipublications.imexporter.ris.RisType;
|
import com.arsdigita.cms.scipublications.imexporter.ris.RisType;
|
||||||
import com.arsdigita.cms.scipublications.importer.report.ImportReport;
|
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.util.ImporterUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for importing RisConverter.
|
* Interface for importing RisConverter.
|
||||||
|
|
@ -18,10 +18,16 @@ public interface RisConverter {
|
||||||
* {@code publishNewItems} is set to {@code true}.
|
* {@code publishNewItems} is set to {@code true}.
|
||||||
*
|
*
|
||||||
* @param dataset
|
* @param dataset
|
||||||
* @param report
|
* @param importerUtil
|
||||||
|
* @param pretend
|
||||||
|
* @param publishNewItems
|
||||||
* @return
|
* @return
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
convert(RisDataset dataset, ImportReport report, boolean pretend, boolean publishNewItems);
|
PublicationImportReport convert(RisDataset dataset,
|
||||||
|
ImporterUtil importerUtil,
|
||||||
|
boolean pretend,
|
||||||
|
boolean publishNewItems);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.arsdigita.cms.scipublications.importer.ris;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
*/
|
||||||
|
public class RisConverterException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of <code>RisConverterException</code> without detail message.
|
||||||
|
*/
|
||||||
|
public RisConverterException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance of <code>RisConverterException</code> with the specified detail message.
|
||||||
|
*
|
||||||
|
* @param msg The detail message.
|
||||||
|
*/
|
||||||
|
public RisConverterException(final String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance of <code>RisConverterException</code> which wraps the
|
||||||
|
* specified exception.
|
||||||
|
*
|
||||||
|
* @param exception The exception to wrap.
|
||||||
|
*/
|
||||||
|
public RisConverterException(final Exception exception) {
|
||||||
|
super(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance of <code>RisConverterException</code> with the specified message which also wraps the
|
||||||
|
* specified exception.
|
||||||
|
*
|
||||||
|
* @param msg The detail message.
|
||||||
|
* @param exception The exception to wrap.
|
||||||
|
*/
|
||||||
|
public RisConverterException(final String msg, final Exception exception) {
|
||||||
|
super(msg, exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,8 @@ import com.arsdigita.cms.contenttypes.Publication;
|
||||||
import com.arsdigita.cms.scipublications.imexporter.ris.RisType;
|
import com.arsdigita.cms.scipublications.imexporter.ris.RisType;
|
||||||
import com.arsdigita.cms.scipublications.importer.SciPublicationsImportException;
|
import com.arsdigita.cms.scipublications.importer.SciPublicationsImportException;
|
||||||
import com.arsdigita.cms.scipublications.importer.report.ImportReport;
|
import com.arsdigita.cms.scipublications.importer.report.ImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.util.ImporterUtil;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
|
|
@ -24,7 +26,7 @@ public class RisConverters {
|
||||||
* The constructor loads all available implementations of the
|
* The constructor loads all available implementations of the
|
||||||
* {@link RisConverter} interface using the {@link ServiceLoader}.
|
* {@link RisConverter} interface using the {@link ServiceLoader}.
|
||||||
*/
|
*/
|
||||||
private RisConverts() {
|
private RisConverters() {
|
||||||
LOGGER.debug("Loading RIS import converters...");
|
LOGGER.debug("Loading RIS import converters...");
|
||||||
final ServiceLoader<RisConverter> converterServices = ServiceLoader.load(RisConverter.class);
|
final ServiceLoader<RisConverter> converterServices = ServiceLoader.load(RisConverter.class);
|
||||||
|
|
||||||
|
|
@ -55,34 +57,32 @@ public class RisConverters {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param dataset
|
* @param dataset
|
||||||
* @param report
|
* @param importerUtil
|
||||||
* @param pretend
|
* @param pretend
|
||||||
* @param publishNewItems
|
* @param publishNewItems
|
||||||
|
* @return
|
||||||
* @throws SciPublicationsImportException
|
* @throws SciPublicationsImportException
|
||||||
*/
|
*/
|
||||||
public void convert(final RisDataset dataset,
|
public PublicationImportReport convert(final RisDataset dataset,
|
||||||
final ImportReport report,
|
final ImporterUtil importerUtil,
|
||||||
final boolean pretend,
|
final boolean pretend,
|
||||||
final boolean publishNewItems)
|
final boolean publishNewItems) throws RisConverterException {
|
||||||
throws SciPublicationsImportException {
|
|
||||||
try {
|
try {
|
||||||
LOGGER.debug(String.format("Trying to find converter for RIS type '%s'...", dataset.getType().toString()));
|
LOGGER.debug(String.format("Trying to find converter for RIS type '%s'...", dataset.getType().toString()));
|
||||||
RisConverter converter = converters.get(dataset.getType());
|
RisConverter converter = converters.get(dataset.getType());
|
||||||
|
|
||||||
if (converter == null) {
|
if (converter == null) {
|
||||||
throw new SciPublicationsImportException(String.format("Failed to find a converter for RIS type '%s'.",
|
throw new RisConverterException(String.format("Failed to find a converter for RIS type '%s'.",
|
||||||
dataset.getType().toString()));
|
dataset.getType().toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
converter = converter.getClass().newInstance();
|
converter = converter.getClass().newInstance();
|
||||||
|
|
||||||
converter.convert(dataset, report, pretend, publishNewItems);
|
return converter.convert(dataset, importerUtil, pretend, publishNewItems);
|
||||||
} catch (InstantiationException ex) {
|
} catch (InstantiationException ex) {
|
||||||
logger.warn("Failed to instaniate RIS converter.", ex);
|
throw new RisConverterException("Converter instantiation failed.", ex);
|
||||||
return null;
|
|
||||||
} catch (IllegalAccessException ex) {
|
} catch (IllegalAccessException ex) {
|
||||||
logger.warn("Failed to instaniate RIS converter.", ex);
|
throw new RisConverterException("Converter instantiation failed.", ex);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.arsdigita.cms.scipublications.imexporter.ris.RisField;
|
||||||
import com.arsdigita.cms.scipublications.imexporter.ris.RisType;
|
import com.arsdigita.cms.scipublications.imexporter.ris.RisType;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -14,7 +15,7 @@ import java.util.Map;
|
||||||
public class RisDataset {
|
public class RisDataset {
|
||||||
|
|
||||||
private final RisType type;
|
private final RisType type;
|
||||||
private final Map<RisField, String> values = new EnumMap<RisField, String>(RisField.class);
|
private final Map<RisField, List<String>> values = new EnumMap<RisField, List<String>>(RisField.class);
|
||||||
|
|
||||||
public RisDataset(final RisType type) {
|
public RisDataset(final RisType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
@ -24,7 +25,7 @@ public class RisDataset {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<RisField, String> getValues() {
|
public Map<RisField, List<String>> getValues() {
|
||||||
return Collections.unmodifiableMap(values);
|
return Collections.unmodifiableMap(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import com.arsdigita.cms.scipublications.imexporter.PublicationFormat;
|
||||||
import com.arsdigita.cms.scipublications.importer.SciPublicationsImportException;
|
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.ImportReport;
|
import com.arsdigita.cms.scipublications.importer.report.ImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.util.ImporterUtil;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.activation.MimeType;
|
import javax.activation.MimeType;
|
||||||
import javax.activation.MimeTypeParseException;
|
import javax.activation.MimeTypeParseException;
|
||||||
|
|
@ -43,19 +45,27 @@ public class RisImporter implements SciPublicationsImporter {
|
||||||
report.setImporter("RIS Importer");
|
report.setImporter("RIS Importer");
|
||||||
report.setPretend(pretend);
|
report.setPretend(pretend);
|
||||||
|
|
||||||
|
final ImporterUtil importerUtil = new ImporterUtil(publishNewItems);
|
||||||
|
|
||||||
for (RisDataset dataset : datasets) {
|
for (RisDataset dataset : datasets) {
|
||||||
converters.convert(dataset, importReport, pretend, publishNewItems);
|
processPublication(dataset, report, importerUtil, pretend, publishNewItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ImportReport;
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
private processPublication(final RisDataset dataset,
|
private void processPublication(final RisDataset dataset,
|
||||||
final ImportReport importReport,
|
final ImportReport report,
|
||||||
|
final ImporterUtil importerUtil,
|
||||||
final boolean pretend,
|
final boolean pretend,
|
||||||
final boolean publishNewItems) {
|
final boolean publishNewItems) {
|
||||||
|
try {
|
||||||
|
report.addPublication(converters.convert(dataset, importerUtil, pretend, publishNewItems));
|
||||||
|
} catch (RisConverterException ex) {
|
||||||
|
final PublicationImportReport importReport = new PublicationImportReport();
|
||||||
|
importReport.addMessage(String.format("Failed to create converter for RIS type '%s'.",
|
||||||
|
dataset.getType().toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.arsdigita.cms.scipublications.importer.ris;
|
package com.arsdigita.cms.scipublications.importer.ris;
|
||||||
|
|
||||||
import com.arsdigita.cms.scipublications.imexporter.ris.RisFieldValue;
|
|
||||||
import com.arsdigita.cms.scipublications.imexporter.ris.RisField;
|
import com.arsdigita.cms.scipublications.imexporter.ris.RisField;
|
||||||
|
import com.arsdigita.cms.scipublications.imexporter.ris.RisFieldValue;
|
||||||
import com.arsdigita.cms.scipublications.imexporter.ris.RisType;
|
import com.arsdigita.cms.scipublications.imexporter.ris.RisType;
|
||||||
import com.arsdigita.cms.scipublications.importer.SciPublicationsImportException;
|
import com.arsdigita.cms.scipublications.importer.SciPublicationsImportException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -43,7 +43,15 @@ public class RisParser {
|
||||||
} else if (RisField.ER.equals(field.getName())) {
|
} else if (RisField.ER.equals(field.getName())) {
|
||||||
openDataset = false;
|
openDataset = false;
|
||||||
} else {
|
} else {
|
||||||
entries.get(entries.size() - 1).getValues().put(field.getName(), field.getValue());
|
final RisDataset currentDataset = entries.get(entries.size() - 1);
|
||||||
|
if (currentDataset.getValues().get(field.getName()) == null) {
|
||||||
|
final List<String> data = new ArrayList<String>();
|
||||||
|
data.add(field.getValue());
|
||||||
|
currentDataset.getValues().put(field.getName(), data);
|
||||||
|
} else {
|
||||||
|
final List<String> data = currentDataset.getValues().get(field.getName());
|
||||||
|
data.add(field.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,172 @@
|
||||||
|
package com.arsdigita.cms.scipublications.importer.ris.converters;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.contenttypes.Monograph;
|
||||||
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
|
import com.arsdigita.cms.scipublications.imexporter.ris.RisField;
|
||||||
|
import com.arsdigita.cms.scipublications.imexporter.ris.RisType;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.AuthorImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.FieldImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.ris.RisConverter;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.ris.RisDataset;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.util.AuthorData;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.util.ImporterUtil;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converter for the RIS type {@code BOOK} to the SciPublications type {@link Monograph}.
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class BookConverter implements RisConverter {
|
||||||
|
|
||||||
|
public PublicationImportReport convert(final RisDataset dataset,
|
||||||
|
final ImporterUtil importerUtil,
|
||||||
|
final boolean pretend,
|
||||||
|
final boolean publishNewItems) {
|
||||||
|
final PublicationImportReport report = new PublicationImportReport();
|
||||||
|
report.setType(Monograph.BASE_DATA_OBJECT_TYPE);
|
||||||
|
|
||||||
|
final Monograph monograph = new Monograph();
|
||||||
|
|
||||||
|
monograph.setTitle(dataset.getValues().get(RisField.TI).get(0));
|
||||||
|
report.setTitle(dataset.getValues().get(RisField.TI).get(0));
|
||||||
|
|
||||||
|
final String yearStr = dataset.getValues().get(RisField.PY).get(0);
|
||||||
|
try {
|
||||||
|
final int year = Integer.parseInt(yearStr);
|
||||||
|
monograph.setYearOfPublication(year);
|
||||||
|
report.addField(new FieldImportReport("year", yearStr));
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
report.addMessage(String.format("Failed to convert year of publication value '%s' from RIS to"
|
||||||
|
+ "integer value. Setting year of publication to 0"));
|
||||||
|
monograph.setYearOfPublication(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> authors = dataset.getValues().get(RisField.AU);
|
||||||
|
if ((authors != null) && !authors.isEmpty()) {
|
||||||
|
for (String authorStr : authors) {
|
||||||
|
processAuthorStr(authorStr, false, importerUtil, monograph, report, pretend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> editors = dataset.getValues().get(RisField.A3);
|
||||||
|
if ((editors != null) && !editors.isEmpty()) {
|
||||||
|
for (String editorStr : editors) {
|
||||||
|
processAuthorStr(editorStr, true, importerUtil, monograph, report, pretend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> publisherList = dataset.getValues().get(RisField.PB);
|
||||||
|
final List<String> placeList = dataset.getValues().get(RisField.CY);
|
||||||
|
final String publisherName;
|
||||||
|
if ((publisherList == null) || publisherList.isEmpty()) {
|
||||||
|
publisherName = null;
|
||||||
|
} else {
|
||||||
|
publisherName = publisherList.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String place;
|
||||||
|
if ((placeList == null) || placeList.isEmpty()) {
|
||||||
|
place = null;
|
||||||
|
} else {
|
||||||
|
place = placeList.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (publisherName != null) {
|
||||||
|
report.setPublisher(importerUtil.processPublisher(monograph, place, publisherName, pretend));
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> abstractList = dataset.getValues().get(RisField.AB);
|
||||||
|
if ((abstractList != null) && (!abstractList.isEmpty())) {
|
||||||
|
monograph.setAbstract(abstractList.get(0));
|
||||||
|
report.addField(new FieldImportReport("abstract", abstractList.get(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> edition = dataset.getValues().get(RisField.ET);
|
||||||
|
if ((edition != null) && !edition.isEmpty()) {
|
||||||
|
monograph.setEdition(edition.get(0));
|
||||||
|
report.addField(new FieldImportReport("edition", edition.get(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> numberOfVols = dataset.getValues().get(RisField.NV);
|
||||||
|
if ((numberOfVols != null) && !numberOfVols.isEmpty()) {
|
||||||
|
try {
|
||||||
|
final int value = Integer.parseInt(numberOfVols.get(0));
|
||||||
|
monograph.setNumberOfVolumes(value);
|
||||||
|
report.addField(new FieldImportReport("number of volumes", numberOfVols.get(0)));
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
report.addMessage("Failed to parse number of volumes.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> isbn = dataset.getValues().get(RisField.SN);
|
||||||
|
if ((isbn != null) && !isbn.isEmpty()) {
|
||||||
|
monograph.setISBN(isbn.get(0));
|
||||||
|
report.addField(new FieldImportReport("isbn", isbn.get(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> numberOfPages = dataset.getValues().get(RisField.SP);
|
||||||
|
if ((numberOfPages != null) && !numberOfPages.isEmpty()) {
|
||||||
|
try {
|
||||||
|
final int value = Integer.parseInt(numberOfPages.get(0));
|
||||||
|
monograph.setNumberOfPages(value);
|
||||||
|
report.addField(new FieldImportReport("number of pages", numberOfPages.get(0)));
|
||||||
|
} catch(NumberFormatException ex) {
|
||||||
|
report.addMessage("Failed to parse number of pages");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> volume = dataset.getValues().get(RisField.VL);
|
||||||
|
if ((volume != null) && !volume.isEmpty()) {
|
||||||
|
try {
|
||||||
|
final int value = Integer.parseInt(volume.get(0));
|
||||||
|
monograph.setVolume(value);
|
||||||
|
report.addField(new FieldImportReport("volume", volume.get(0)));
|
||||||
|
} catch(NumberFormatException ex) {
|
||||||
|
report.addMessage("Failed to parse value of field 'volume'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> series = dataset.getValues().get(RisField.T2);
|
||||||
|
if ((series != null) && !series.isEmpty()) {
|
||||||
|
report.setSeries(importerUtil.processSeries(monograph, series.get(0), pretend));
|
||||||
|
}
|
||||||
|
|
||||||
|
return report;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processAuthorStr(final String authorStr,
|
||||||
|
final boolean editor,
|
||||||
|
final ImporterUtil importerUtil,
|
||||||
|
final Publication publication,
|
||||||
|
final PublicationImportReport importReport,
|
||||||
|
final boolean pretend) {
|
||||||
|
final AuthorData authorData = new AuthorData();
|
||||||
|
|
||||||
|
final String[] tokens = authorStr.split(",");
|
||||||
|
if (tokens.length == 0) {
|
||||||
|
importReport.addMessage(String.format("Failed to parse author string '%s'.", authorStr));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tokens.length >= 1) {
|
||||||
|
authorData.setSurname(tokens[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tokens.length >= 2) {
|
||||||
|
authorData.setGivenName(tokens[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
authorData.setEditor(editor);
|
||||||
|
|
||||||
|
final AuthorImportReport authorReport = importerUtil.processAuthor(publication, authorData, pretend);
|
||||||
|
importReport.addAuthor(authorReport);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RisType getRisType() {
|
||||||
|
return RisType.BOOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,161 @@
|
||||||
|
package com.arsdigita.cms.scipublications.importer.ris.converters;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.contenttypes.Monograph;
|
||||||
|
import com.arsdigita.cms.contenttypes.Publication;
|
||||||
|
import com.arsdigita.cms.scipublications.imexporter.ris.RisField;
|
||||||
|
import com.arsdigita.cms.scipublications.imexporter.ris.RisType;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.AuthorImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.FieldImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.PublicationImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.ris.RisConverter;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.ris.RisDataset;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.util.AuthorData;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.util.ImporterUtil;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converter for the RIS type {@code EBOOK} to the SciPublications type {@link Monograph}.
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class EbookConverter implements RisConverter {
|
||||||
|
|
||||||
|
public PublicationImportReport convert(final RisDataset dataset,
|
||||||
|
final ImporterUtil importerUtil,
|
||||||
|
final boolean pretend,
|
||||||
|
final boolean publishNewItems) {
|
||||||
|
final PublicationImportReport report = new PublicationImportReport();
|
||||||
|
report.setType(Monograph.BASE_DATA_OBJECT_TYPE);
|
||||||
|
|
||||||
|
final Monograph monograph = new Monograph();
|
||||||
|
|
||||||
|
monograph.setTitle(dataset.getValues().get(RisField.TI).get(0));
|
||||||
|
report.setTitle(dataset.getValues().get(RisField.TI).get(0));
|
||||||
|
|
||||||
|
final String yearStr = dataset.getValues().get(RisField.PY).get(0);
|
||||||
|
try {
|
||||||
|
final int year = Integer.parseInt(yearStr);
|
||||||
|
monograph.setYearOfPublication(year);
|
||||||
|
report.addField(new FieldImportReport("year", yearStr));
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
report.addMessage(String.format("Failed to convert year of publication value '%s' from RIS to"
|
||||||
|
+ "integer value. Setting year of publication to 0"));
|
||||||
|
monograph.setYearOfPublication(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> authors = dataset.getValues().get(RisField.AU);
|
||||||
|
if ((authors != null) && !authors.isEmpty()) {
|
||||||
|
for (String authorStr : authors) {
|
||||||
|
processAuthorStr(authorStr, false, importerUtil, monograph, report, pretend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> editors = dataset.getValues().get(RisField.A3);
|
||||||
|
if ((editors != null) && !editors.isEmpty()) {
|
||||||
|
for (String editorStr : editors) {
|
||||||
|
processAuthorStr(editorStr, true, importerUtil, monograph, report, pretend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> publisherList = dataset.getValues().get(RisField.PB);
|
||||||
|
final List<String> placeList = dataset.getValues().get(RisField.CY);
|
||||||
|
final String publisherName;
|
||||||
|
if ((publisherList == null) || publisherList.isEmpty()) {
|
||||||
|
publisherName = null;
|
||||||
|
} else {
|
||||||
|
publisherName = publisherList.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String place;
|
||||||
|
if ((placeList == null) || placeList.isEmpty()) {
|
||||||
|
place = null;
|
||||||
|
} else {
|
||||||
|
place = placeList.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (publisherName != null) {
|
||||||
|
report.setPublisher(importerUtil.processPublisher(monograph, place, publisherName, pretend));
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> abstractList = dataset.getValues().get(RisField.AB);
|
||||||
|
if ((abstractList != null) && (!abstractList.isEmpty())) {
|
||||||
|
monograph.setAbstract(abstractList.get(0));
|
||||||
|
report.addField(new FieldImportReport("abstract", abstractList.get(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> edition = dataset.getValues().get(RisField.ET);
|
||||||
|
if ((edition != null) && !edition.isEmpty()) {
|
||||||
|
monograph.setEdition(edition.get(0));
|
||||||
|
report.addField(new FieldImportReport("edition", edition.get(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> isbn = dataset.getValues().get(RisField.SN);
|
||||||
|
if ((isbn != null) && !isbn.isEmpty()) {
|
||||||
|
monograph.setISBN(isbn.get(0));
|
||||||
|
report.addField(new FieldImportReport("isbn", isbn.get(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> numberOfPages = dataset.getValues().get(RisField.SP);
|
||||||
|
if ((numberOfPages != null) && !numberOfPages.isEmpty()) {
|
||||||
|
try {
|
||||||
|
final int value = Integer.parseInt(numberOfPages.get(0));
|
||||||
|
monograph.setNumberOfPages(value);
|
||||||
|
report.addField(new FieldImportReport("number of pages", numberOfPages.get(0)));
|
||||||
|
} catch(NumberFormatException ex) {
|
||||||
|
report.addMessage("Failed to parse number of pages");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> volume = dataset.getValues().get(RisField.VL);
|
||||||
|
if ((volume != null) && !volume.isEmpty()) {
|
||||||
|
try {
|
||||||
|
final int value = Integer.parseInt(volume.get(0));
|
||||||
|
monograph.setVolume(value);
|
||||||
|
report.addField(new FieldImportReport("volume", volume.get(0)));
|
||||||
|
} catch(NumberFormatException ex) {
|
||||||
|
report.addMessage("Failed to parse value of field 'volume'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> series = dataset.getValues().get(RisField.T2);
|
||||||
|
if ((series != null) && !series.isEmpty()) {
|
||||||
|
report.setSeries(importerUtil.processSeries(monograph, series.get(0), pretend));
|
||||||
|
}
|
||||||
|
|
||||||
|
return report;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processAuthorStr(final String authorStr,
|
||||||
|
final boolean editor,
|
||||||
|
final ImporterUtil importerUtil,
|
||||||
|
final Publication publication,
|
||||||
|
final PublicationImportReport importReport,
|
||||||
|
final boolean pretend) {
|
||||||
|
final AuthorData authorData = new AuthorData();
|
||||||
|
|
||||||
|
final String[] tokens = authorStr.split(",");
|
||||||
|
if (tokens.length == 0) {
|
||||||
|
importReport.addMessage(String.format("Failed to parse author string '%s'.", authorStr));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tokens.length >= 1) {
|
||||||
|
authorData.setSurname(tokens[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tokens.length >= 2) {
|
||||||
|
authorData.setGivenName(tokens[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
authorData.setEditor(editor);
|
||||||
|
|
||||||
|
final AuthorImportReport authorReport = importerUtil.processAuthor(publication, authorData, pretend);
|
||||||
|
importReport.addAuthor(authorReport);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RisType getRisType() {
|
||||||
|
return RisType.EBOOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -20,15 +20,19 @@ import com.arsdigita.cms.contenttypes.PublicationWithPublisher;
|
||||||
import com.arsdigita.cms.contenttypes.Publisher;
|
import com.arsdigita.cms.contenttypes.Publisher;
|
||||||
import com.arsdigita.cms.contenttypes.PublisherBundle;
|
import com.arsdigita.cms.contenttypes.PublisherBundle;
|
||||||
import com.arsdigita.cms.contenttypes.SciAuthor;
|
import com.arsdigita.cms.contenttypes.SciAuthor;
|
||||||
|
import com.arsdigita.cms.contenttypes.Series;
|
||||||
|
import com.arsdigita.cms.contenttypes.SeriesBundle;
|
||||||
import com.arsdigita.cms.contenttypes.UnPublished;
|
import com.arsdigita.cms.contenttypes.UnPublished;
|
||||||
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.AuthorImportReport;
|
import com.arsdigita.cms.scipublications.importer.report.AuthorImportReport;
|
||||||
import com.arsdigita.cms.scipublications.importer.report.CollectedVolumeImportReport;
|
import com.arsdigita.cms.scipublications.importer.report.CollectedVolumeImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.FieldImportReport;
|
||||||
import com.arsdigita.cms.scipublications.importer.report.JournalImportReport;
|
import com.arsdigita.cms.scipublications.importer.report.JournalImportReport;
|
||||||
import com.arsdigita.cms.scipublications.importer.report.OrganizationalUnitImportReport;
|
import com.arsdigita.cms.scipublications.importer.report.OrganizationalUnitImportReport;
|
||||||
import com.arsdigita.cms.scipublications.importer.report.ProceedingsImportReport;
|
import com.arsdigita.cms.scipublications.importer.report.ProceedingsImportReport;
|
||||||
import com.arsdigita.cms.scipublications.importer.report.PublisherImportReport;
|
import com.arsdigita.cms.scipublications.importer.report.PublisherImportReport;
|
||||||
|
import com.arsdigita.cms.scipublications.importer.report.SeriesImportReport;
|
||||||
import com.arsdigita.kernel.Kernel;
|
import com.arsdigita.kernel.Kernel;
|
||||||
import com.arsdigita.persistence.DataCollection;
|
import com.arsdigita.persistence.DataCollection;
|
||||||
import com.arsdigita.persistence.Session;
|
import com.arsdigita.persistence.Session;
|
||||||
|
|
@ -54,6 +58,7 @@ public class ImporterUtil {
|
||||||
private final transient Set<String> createdProcs = new HashSet<String>();
|
private final transient Set<String> createdProcs = new HashSet<String>();
|
||||||
private final transient Set<String> createdPublishers = new HashSet<String>();
|
private final transient Set<String> createdPublishers = new HashSet<String>();
|
||||||
private final transient Set<String> createdOrgas = new HashSet<String>();
|
private final transient Set<String> createdOrgas = new HashSet<String>();
|
||||||
|
private final transient Set<String> createdSeries = new HashSet<String>();
|
||||||
|
|
||||||
public ImporterUtil() {
|
public ImporterUtil() {
|
||||||
publish = false;
|
publish = false;
|
||||||
|
|
@ -502,6 +507,64 @@ public class ImporterUtil {
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SeriesImportReport processSeries(final Publication publication,
|
||||||
|
final String seriesTitle,
|
||||||
|
final boolean pretend) {
|
||||||
|
final SeriesImportReport report = new SeriesImportReport();
|
||||||
|
|
||||||
|
final Session session = SessionManager.getSession();
|
||||||
|
final DataCollection collection = session.retrieve(Series.BASE_DATA_OBJECT_TYPE);
|
||||||
|
collection.addEqualsFilter("title", seriesTitle);
|
||||||
|
|
||||||
|
report.setSeriesTitle(seriesTitle);
|
||||||
|
if (collection.isEmpty()) {
|
||||||
|
if (!pretend) {
|
||||||
|
final Integer folderId = Publication.getConfig().getDefaultSeriesFolder();
|
||||||
|
final Folder folder = new Folder(new BigDecimal(folderId));
|
||||||
|
if (folder == null) {
|
||||||
|
throw new IllegalArgumentException("Error getting folder for series.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final Series series = new Series();
|
||||||
|
series.setName(normalizeString(seriesTitle));
|
||||||
|
series.setTitle(seriesTitle);
|
||||||
|
series.setLanguage(Kernel.getConfig().getLanguagesIndependentCode());
|
||||||
|
series.setContentSection(folder.getContentSection());
|
||||||
|
series.save();
|
||||||
|
|
||||||
|
final SeriesBundle bundle = new SeriesBundle(series);
|
||||||
|
bundle.setParent(folder);
|
||||||
|
bundle.setContentSection(folder.getContentSection());
|
||||||
|
bundle.save();
|
||||||
|
|
||||||
|
publication.addSeries(series);
|
||||||
|
|
||||||
|
if (publish) {
|
||||||
|
publishItem(series);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
report.setCreated(true);
|
||||||
|
|
||||||
|
//Special handling for pretend mode
|
||||||
|
if (pretend && createdSeries.contains(seriesTitle)) {
|
||||||
|
report.setCreated(false);
|
||||||
|
} else {
|
||||||
|
createdSeries.add(seriesTitle);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!pretend) {
|
||||||
|
collection.next();
|
||||||
|
final Series series = new Series(collection.getDataObject());
|
||||||
|
publication.addSeries(series);
|
||||||
|
}
|
||||||
|
report.setCreated(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.close();
|
||||||
|
|
||||||
|
return report;
|
||||||
|
}
|
||||||
|
|
||||||
public void publishItem(final ContentItem item) {
|
public void publishItem(final ContentItem item) {
|
||||||
final Calendar now = new GregorianCalendar();
|
final Calendar now = new GregorianCalendar();
|
||||||
final LifecycleDefinitionCollection lifecycles = item.getContentSection().getLifecycleDefinitions();
|
final LifecycleDefinitionCollection lifecycles = item.getContentSection().getLifecycleDefinitions();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue