diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsServlet.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsServlet.java index adeea4018..9820111c4 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsServlet.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsServlet.java @@ -462,12 +462,49 @@ public class SciPublicationsServlet extends BaseApplicationServlet { exportPublications(format, publicationIds, response); } else { - LOGGER.warn("Export action needs either a publication id or a " - + "term id. Neither was found in the query parameters." - + "Responding with BAD_REQUEST status."); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, - "The export action needs either a publication id or " - + "a term id. Neither was found in the query parameters."); +// LOGGER.warn("Export action needs either a publication id or a " +// + "term id. Neither was found in the query parameters." +// + "Responding with BAD_REQUEST status."); +// response.sendError(HttpServletResponse.SC_BAD_REQUEST, +// "The export action needs either a publication id or " +// + "a term id. Neither was found in the query parameters."); + //Otherwise, export all publications + final DataCollection publications = SessionManager.getSession().retrieve( + Publication.BASE_DATA_OBJECT_TYPE); + + if (Kernel.getConfig().languageIndependentItems()) { + final FilterFactory filterFactory = publications.getFilterFactory(); + final Filter filter = filterFactory.or(). + addFilter(filterFactory.equals("language", GlobalizationHelper. + getNegotiatedLocale().getLanguage())). + addFilter(filterFactory.and(). + addFilter( + filterFactory.equals("language", + GlobalizationHelper.LANG_INDEPENDENT)). + addFilter(filterFactory.notIn("parent", + "com.arsdigita.navigation.getParentIDsOfMatchedItems"). + set("language", GlobalizationHelper. + getNegotiatedLocale().getLanguage()))); + publications.addFilter(filter); + + } else { + publications.addEqualsFilter("language", + GlobalizationHelper. + getNegotiatedLocale().getLanguage()); + } + + publications.addOrder("yearOfPublication desc"); + publications.addOrder("authorsStr"); + publications.addOrder("title"); + + final List publicationIds = + new ArrayList(); + while(publications.next()) { + publicationIds.add((BigDecimal) publications.get("id")); + + } + + exportPublications(format, publicationIds, response); } } else { @@ -520,6 +557,10 @@ public class SciPublicationsServlet extends BaseApplicationServlet { String publicationName = "publication"; final StringBuilder result = new StringBuilder(); + if (exporter.getPreamble() != null) { + result.append(exporter.getPreamble()); + } + for (BigDecimal publicationId : publicationIds) { try { //Get the publication diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporter.java index 8481ea44b..1a1d8644a 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/SciPublicationsExporter.java @@ -42,5 +42,11 @@ public interface SciPublicationsExporter { * @return The data of the publication in the provided export format. */ String exportPublication(Publication publication); + + /** + * @return If the format requires some sort of preamble this method should return it. + * If the format needs no preamble the method must return null. + */ + String getPreamble(); } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/BibTeXExporter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/BibTeXExporter.java index 4c7c6ad7a..3b90fc5db 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/BibTeXExporter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/BibTeXExporter.java @@ -59,4 +59,9 @@ public class BibTeXExporter implements SciPublicationsExporter { public String exportPublication(final Publication publication) { return BibTeXConverters.getInstance().convert(publication); } + + @Override + public String getPreamble() { + return null; + } } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverters.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverters.java index 4d42ff197..7e11c651f 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverters.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/BibTeXConverters.java @@ -22,7 +22,6 @@ import com.arsdigita.cms.contenttypes.Publication; import com.arsdigita.cms.contenttypes.PublicationWithPublisher; import java.util.HashMap; import java.util.Map; -import java.util.ServiceLoader; import org.apache.log4j.Logger; /** diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisExporter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisExporter.java index 15b536e59..2a982261b 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisExporter.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/RisExporter.java @@ -59,4 +59,9 @@ public class RisExporter implements SciPublicationsExporter { public String exportPublication(final Publication publication) { return RisConverters.getInstance().convert(publication); } + + @Override + public String getPreamble() { + return null; + } } diff --git a/ccm-sci-publicationscsvexporter/application.xml b/ccm-sci-publicationscsvexporter/application.xml new file mode 100644 index 000000000..2b9f229d8 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/application.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + Importer for Publications using a CSV file. Only used for internal purposes + at the University of Bremen. + + + \ No newline at end of file diff --git a/ccm-sci-publicationscsvexporter/src/ccm-sci-publicationscsvexporter.config b/ccm-sci-publicationscsvexporter/src/ccm-sci-publicationscsvexporter.config new file mode 100644 index 000000000..959c8b5df --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/ccm-sci-publicationscsvexporter.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ccm-sci-publicationscsvexporter/src/ccm-sci-publicationscsvexporter.load b/ccm-sci-publicationscsvexporter/src/ccm-sci-publicationscsvexporter.load new file mode 100644 index 000000000..6d99d8c93 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/ccm-sci-publicationscsvexporter.load @@ -0,0 +1,14 @@ + + + +
+
+
+ + + + + + + + \ No newline at end of file diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ArticleInCollectedVolumeConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ArticleInCollectedVolumeConverter.java new file mode 100644 index 000000000..f17ac29ed --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ArticleInCollectedVolumeConverter.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.ArticleInCollectedVolume; +import com.arsdigita.cms.contenttypes.CollectedVolume; +import com.arsdigita.cms.contenttypes.Publication; +import java.util.Map; + +import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class ArticleInCollectedVolumeConverter extends PublicationConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof ArticleInCollectedVolume)) { + throw new UnsupportedCcmTypeException( + String.format("The ArticleInCollectedVolumeConverter only " + + "supports publication types which are of the" + + "type ArticleInCollectedVolume or which are extending " + + "ArticleInCollectedVolume. The " + + "provided publication is of type '%s' which " + + "is not of type ArticleInCollectedVolume and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + final ArticleInCollectedVolume article = (ArticleInCollectedVolume) publication; + + final Map values = super.convert(publication); + + values.put(PAGES_FROM, convertIntegerValue(article.getPagesFrom())); + values.put(PAGES_TO, convertIntegerValue(article.getPagesTo())); + values.put(CHAPTER, article.getChapter()); + + if (article.getCollectedVolume() != null) { + final CollectedVolume collectedVolume = article.getCollectedVolume(); + values.put(COLLECTED_VOLUME, collectedVolume.getTitle()); + values.put(COLLECTED_VOLUME_EDITORS, convertAuthors(collectedVolume.getAuthors())); + } + + return values; + } + + @Override + public String getCCMType() { + return ArticleInCollectedVolume.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ArticleInJournalConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ArticleInJournalConverter.java new file mode 100644 index 000000000..b9f22a006 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ArticleInJournalConverter.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.ArticleInJournal; +import com.arsdigita.cms.contenttypes.Publication; +import java.util.Map; + +import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class ArticleInJournalConverter extends PublicationConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof ArticleInJournal)) { + throw new UnsupportedCcmTypeException( + String.format("The ArticleInJournalConverter only " + + "supports publication types which are of the" + + "type ArticleInJournal or which are extending " + + "ArticleInJournal. The " + + "provided publication is of type '%s' which " + + "is not of type ArticleInJournal and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + final ArticleInJournal article = (ArticleInJournal) publication; + + final Map values = super.convert(publication); + + values.put(VOLUME_OF_JOURNAL, convertIntegerValue(article.getVolume())); + values.put(ISSUE_OF_JOURNAL, article.getIssue()); + values.put(PAGES_FROM, convertIntegerValue(article.getPagesFrom())); + values.put(PAGES_TO, convertIntegerValue(article.getPagesTo())); + values.put(PUBLICATION_DATE, convertDateValue(article.getPublicationDate())); + + if (article.getJournal() != null) { + values.put(JOURNAL, article.getJournal().getTitle()); + values.put(JOURNAL_SYMBOL, article.getJournal().getSymbol()); + values.put(ISSN, article.getJournal().getISSN()); + } + + return values; + + } + + @Override + public String getCCMType() { + return ArticleInJournal.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CollectedVolumeConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CollectedVolumeConverter.java new file mode 100644 index 000000000..c9d2c941a --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CollectedVolumeConverter.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.CollectedVolume; +import com.arsdigita.cms.contenttypes.Publication; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class CollectedVolumeConverter extends PublicationWithPublisherConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof CollectedVolume)) { + throw new UnsupportedCcmTypeException( + String.format("The CollectedVolumeConverter only " + + "supports publication types which are of the" + + "type CollectedVolume or which are extending " + + "CollectedVolume. The " + + "provided publication is of type '%s' which " + + "is not of type CollectedVolume and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + final CollectedVolume collectedVolume = (CollectedVolume) publication; + + return super.convert(publication); + + } + + @Override + public String getCCMType() { + return CollectedVolume.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvConverter.java new file mode 100644 index 000000000..1a11d1f25 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvConverter.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.Publication; +import java.util.Map; + +/** + * Interface for the converter classes which are transforming publication objects into a CSV line. + * + * @author Jens Pelzetter + * @version $Id$ + */ +public interface CsvConverter { + + /** + * Converts a publication to CSV. + * + * @param publication The publication to convert. + * @return The values for the CSV line. They are returned as a map, where each entry is + * a column in the CSV line. For the key the values from {@link CsvExporterConstants} are used. + */ + Map convert(Publication publication); + + /** + * + * + * @return The CCM publication type supported by this converter. + */ + String getCCMType(); + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvConverters.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvConverters.java new file mode 100644 index 000000000..72683a884 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvConverters.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.PublicationWithPublisher; +import java.util.HashMap; +import java.util.Map; +import org.apache.log4j.Logger; + +/** + * Registry for the available {@link CsvConverter} implementations. + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class CsvConverters { + + private static final Logger LOGGER = Logger.getLogger(CsvConverters.class); + + private final Map converters = new HashMap(); + + private CsvConverters() { + //Nothing + } + + private static class Instance { + + private final static CsvConverters INSTANCE = new CsvConverters(); + } + + public static CsvConverters getInstance() { + return Instance.INSTANCE; + } + + public static void register(final CsvConverter converter) { + getInstance().registerConverter(converter); + } + + public void registerConverter(final CsvConverter converter) { + converters.put(converter.getCCMType(), converter); + } + + public Map convert(final Publication publication) { + try { + CsvConverter converter; + LOGGER.debug(String.format("Trying to find converter for type '%s'.", + publication.getClass().getName())); + converter = converters.get(publication.getClass().getName()); + + if (converter == null) { + LOGGER.debug("No converter found..."); + if (publication instanceof PublicationWithPublisher) { + LOGGER.debug("Publication is a PublicationWithPublisher, using" + + "converter for this type."); + converter = converters.get(PublicationWithPublisher.class.getName()); + } else { + LOGGER.debug("Publication is a Publication, using" + + "converter for this type."); + converter = converters.get(Publication.class.getName()); + } + } + + if (converter == null) { + LOGGER.error(String.format("Converter is null. This should not happen. Publication " + + "to convert is of type '%s'.", publication.getClass().getName())); + } + + converter = converter.getClass().newInstance(); + + return converter.convert(publication); + } catch (InstantiationException ex) { + LOGGER.warn("Failed to instaniate CSV converter.", ex); + return null; + } catch (IllegalAccessException ex) { + LOGGER.warn("Failed to instaniate CSV converter.", ex); + return null; + } + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporter.java new file mode 100644 index 000000000..696369d55 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporter.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter; +import com.arsdigita.cms.scipublications.imexporter.PublicationFormat; +import java.util.Map; +import javax.activation.MimeType; +import javax.activation.MimeTypeParseException; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class CsvExporter implements SciPublicationsExporter { + + private final static Logger LOGGER = Logger.getLogger(CsvExporter.class); + private final static CsvExporterConfig CONFIG = new CsvExporterConfig(); + + @Override + public PublicationFormat getSupportedFormat() { + try { + return new PublicationFormat("CSV", + new MimeType("text", "csv"), + "csv"); + } catch (MimeTypeParseException ex) { + LOGGER.warn("Failed to create MimeType for PublicationFormat." + + "Using null mimetype instead. Cause: ", ex); + return new PublicationFormat("CSV", + null, + "csv"); + + } + } + + @Override + public String exportPublication(final Publication publication) { + final Map line = CsvConverters.getInstance().convert( + publication); + + final String[] columns = CONFIG.getColumns().split(","); + final String separator = CONFIG.getSeparator(); + + final StringBuilder builder = new StringBuilder(); + + String value; + for (String token : columns) { + value = line.get(CsvExporterConstants.valueOf(token)); + if ((value == null) || value.isEmpty()) { + builder.append(" "); + } else { + builder.append(value); + } + builder.append(separator); + } + + builder.append("\n"); + + return builder.toString(); + } + + @Override + public String getPreamble() { + + final String[] columns = CONFIG.getColumns().split(","); + final String separator = CONFIG.getSeparator(); + + final StringBuilder builder = new StringBuilder(); + + for(String column : columns) { + builder.append(column); + builder.append(separator); + } + builder.append("\n"); + + return builder.toString(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporterConfig.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporterConfig.java new file mode 100644 index 000000000..0e4b311c2 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporterConfig.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.runtime.AbstractConfig; +import com.arsdigita.util.parameter.Parameter; +import com.arsdigita.util.parameter.StringParameter; + +import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class CsvExporterConfig extends AbstractConfig { + + private Parameter columns; + private Parameter separator; + + public CsvExporterConfig() { + super(); + + separator = new StringParameter("com.arsdigita.cms.scipublications.exporter.csv.separator", + Parameter.REQUIRED, + "\t"); + + columns = new StringParameter("com.arsdigita.cms.scipublications.exporter.csv.columns", + Parameter.REQUIRED, + PUBLICATION_ID + "," + + PUBLICATION_TYPE + "," + + AUTHORS + "," + + YEAR + "," + + YEAR_FIRST_PUBLISHED + "," + + TITLE + "," + + PUBLISHER + "," + + PLACE + "," + + EDITION + "," + + ABSTRACT + "," + + MISC + "," + + LANGUAGE_OF_PUBLICATION + "," + + REVIEWED + "," + + VOLUME + "," + + NUMBER + "," + + NUMBER_OF_VOLUMES + "," + + NUMBER_OF_PAGES + "," + + VOLUME_OF_JOURNAL + "," + + ISSUE_OF_JOURNAL + "," + + JOURNAL + "," + + JOURNAL_SYMBOL + "," + + CHAPTER + "," + + PUBLICATION_DATE + "," + + COLLECTED_VOLUME + "," + + COLLECTED_VOLUME_EDITORS + "," + + CONFERENCE + "," + + CONFERENCE_PLACE + "," + + CONFERENCE_DATE_FROM + "," + + CONFERENCE_DATE_TO + "," + + IN_SERIES + "," + + VOLUME_OF_SERIES + "," + + EDITOR_OF_SERIES + "," + + ORGANISATION + "," + + URL + "," + + ISBN + "," + + ISSN + "," + + URN + "," + + DOI + "," + + LAST_ACCESS + ","); + + register(columns); + register(separator); + + loadInfo(); + } + + public String getColumns() { + return (String) get(columns); + } + + public String getSeparator() { + return (String) get(separator); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporterConfig_parameter.properties b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporterConfig_parameter.properties new file mode 100644 index 000000000..f647f77d5 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporterConfig_parameter.properties @@ -0,0 +1,9 @@ +com.arsdigita.cms.scipublications.exporter.csv.separator.title = CSV Exporter Separator +com.arsdigita.cms.scipublications.exporter.csv.separator.purpose = Separator used in CSV file between columns +com.arsdigita.cms.scipublications.exporter.csv.separator.example = | +com.arsdigita.cms.scipublications.exporter.csv.separator.format = [String] + +com.arsdigita.cms.scipublications.exporter.csv.columns.title = CSV Columns +com.arsdigita.cms.scipublications.exporter.csv.columns.purpose = Columns to include into the CSV file. Also defines the order of the columns. +com.arsdigita.cms.scipublications.exporter.csv.columns.example = +com.arsdigita.cms.scipublications.exporter.csv.columns.format = [String] \ No newline at end of file diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporterConstants.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporterConstants.java new file mode 100644 index 000000000..ae96ec86b --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/CsvExporterConstants.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +/** + * Constants used in for CSV Exporter, most of them are the field names used in the maps from which + * which the CSV lines are created. + * + * The constants are ordered alphabetically. + * + * @author Jens Pelzetter + * @version $Id$ + */ +public enum CsvExporterConstants { + + ABSTRACT, + AUTHORS, + + CHAPTER, + COLLECTED_VOLUME, + COLLECTED_VOLUME_EDITORS, + CONFERENCE, + CONFERENCE_DATE_FROM, + CONFERENCE_DATE_TO, + CONFERENCE_PLACE, + + DOI, + + EDITION, + EDITOR_OF_SERIES, + + IN_SERIES, + ISBN, + ISSN, + ISSUE_OF_JOURNAL, + + JOURNAL, + JOURNAL_SYMBOL, + + LANGUAGE_OF_PUBLICATION, + LAST_ACCESS, + + MISC, + + NUMBER, + NUMBER_OF_VOLUMES, + NUMBER_OF_PAGES, + + ORGANISATION, + + PAGES_FROM, + PAGES_TO, + PLACE, + PUBLICATION_DATE, + PUBLICATION_ID, + PUBLICATION_TYPE, + PUBLISHER, + + REVIEWED, + + YEAR, + YEAR_FIRST_PUBLISHED, + + TITLE, + + URL, + URN, + + VOLUME, + VOLUME_OF_JOURNAL, + VOLUME_OF_SERIES + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ExpertiseConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ExpertiseConverter.java new file mode 100644 index 000000000..435440e7a --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ExpertiseConverter.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.Expertise; +import java.util.Map; + +import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class ExpertiseConverter extends PublicationConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof Expertise)) { + throw new UnsupportedCcmTypeException( + String.format("The ExpertiseConverter only " + + "supports publication types which are of the" + + "type Expertise or which are extending " + + "Expertise. The " + + "provided publication is of type '%s' which " + + "is not of type Expertise and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + final Expertise expertise = (Expertise) publication; + + final Map values = super.convert(publication); + + values.put(PLACE, expertise.getPlace()); + values.put(NUMBER_OF_PAGES, convertIntegerValue(expertise.getNumberOfPages())); + if (expertise.getOrganization() != null) { + values.put(ORGANISATION, expertise.getOrganization().getTitle()); + } + + return values; + } + + @Override + public String getCCMType() { + return Expertise.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/GreyLiteratureConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/GreyLiteratureConverter.java new file mode 100644 index 000000000..ac8e3d96d --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/GreyLiteratureConverter.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.GreyLiterature; +import com.arsdigita.cms.contenttypes.Publication; +import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class GreyLiteratureConverter extends UnPublishedConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof GreyLiterature)) { + throw new UnsupportedCcmTypeException( + String.format("The GreyLiteratureConverter only " + + "supports publication types which are of the" + + "type GreyLiterature or which are extending " + + "GreyLiterature. The " + + "provided publication is of type '%s' which " + + "is not of type GreyLiterature and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + final GreyLiterature greyLiterature = (GreyLiterature) publication; + + final Map values = super.convert(publication); + + values.put(PAGES_FROM, convertIntegerValue(greyLiterature.getPagesFrom())); + values.put(PAGES_TO, convertIntegerValue(greyLiterature.getPagesTo())); + + return values; + } + + @Override + public String getCCMType() { + return GreyLiterature.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/InProceedingsConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/InProceedingsConverter.java new file mode 100644 index 000000000..700da95c4 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/InProceedingsConverter.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.InProceedings; +import com.arsdigita.cms.contenttypes.Publication; +import java.util.Map; + +import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class InProceedingsConverter extends PublicationConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof InProceedings)) { + throw new UnsupportedCcmTypeException( + String.format("The InProceedingsConverter only " + + "supports publication types which are of the" + + "type InProceedings or which are extending " + + "InProceedings. The " + + "provided publication is of type '%s' which " + + "is not of type InProceedings and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + final InProceedings inProceedings = (InProceedings) publication; + + final Map values = super.convert(publication); + + values.put(PAGES_FROM, convertIntegerValue(inProceedings.getPagesFrom())); + values.put(PAGES_TO, convertIntegerValue(inProceedings.getPagesTo())); + + if (inProceedings.getProceedings() != null) { + values.put(COLLECTED_VOLUME, inProceedings.getProceedings().getTitle()); + values.put(COLLECTED_VOLUME_EDITORS, convertAuthors(inProceedings.getProceedings(). + getAuthors())); + values.put(CONFERENCE, inProceedings.getProceedings().getNameOfConference()); + values.put(CONFERENCE_PLACE, inProceedings.getProceedings().getPlaceOfConference()); + values.put(CONFERENCE_DATE_FROM, convertDateValue(inProceedings.getProceedings(). + getDateFromOfConference())); + values.put(CONFERENCE_DATE_TO, convertDateValue(inProceedings.getProceedings(). + getDateToOfConference())); + } + + return values; + } + + @Override + public String getCCMType() { + return InProceedings.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/Initializer.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/Initializer.java new file mode 100644 index 000000000..20487cd5b --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/Initializer.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter; +import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporters; +import com.arsdigita.db.DbHelper; +import com.arsdigita.persistence.pdl.ManifestSource; +import com.arsdigita.persistence.pdl.NameFilter; +import com.arsdigita.runtime.CompoundInitializer; +import com.arsdigita.runtime.DomainInitEvent; +import com.arsdigita.runtime.PDLInitializer; +import com.arsdigita.runtime.RuntimeConfig; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class Initializer extends CompoundInitializer { + + public Initializer() { + super(); + + final String url = RuntimeConfig.getConfig().getJDBCURL(); + final int database = DbHelper.getDatabaseFromURL(url); + + add(new PDLInitializer(new ManifestSource("empty.pdl.mf", + new NameFilter((DbHelper.getDatabaseSuffix( + database)), "pdl")))); + } + + @Override + public void init(final DomainInitEvent event) { + super.init(event); + + SciPublicationsExporters.register(new CsvExporter()); + + CsvConverters.register(new ArticleInCollectedVolumeConverter()); + CsvConverters.register(new ArticleInJournalConverter()); + CsvConverters.register(new CollectedVolumeConverter()); + CsvConverters.register(new ExpertiseConverter()); + CsvConverters.register(new GreyLiteratureConverter()); + CsvConverters.register(new InProceedingsConverter()); + CsvConverters.register(new InternetArticleConverter()); + CsvConverters.register(new MonographConverter()); + CsvConverters.register(new ProceedingsConverter()); + CsvConverters.register(new PublicationConverter()); + CsvConverters.register(new PublicationWithPublisherConverter()); + CsvConverters.register(new ReviewConverter()); + CsvConverters.register(new UnPublishedConverter()); + CsvConverters.register(new WorkingPaperConverter()); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/InternetArticleConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/InternetArticleConverter.java new file mode 100644 index 000000000..c6617ff1a --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/InternetArticleConverter.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.InternetArticle; +import com.arsdigita.cms.contenttypes.Publication; +import java.util.Map; + +import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class InternetArticleConverter extends PublicationConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof InternetArticle)) { + throw new UnsupportedCcmTypeException( + String.format("The InternetArticleConverter only " + + "supports publication types which are of the" + + "type InternetArticle or which are extending " + + "InternetArticle. The " + + "provided publication is of type '%s' which " + + "is not of type InternetArticle and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + final InternetArticle article = (InternetArticle) publication; + + final Map values = super.convert(publication); + + values.put(PLACE, article.getPlace()); + values.put(NUMBER, article.getNumber()); + values.put(NUMBER_OF_PAGES, convertIntegerValue(article.getNumberOfPages())); + values.put(EDITION, article.getEdition()); + values.put(ISSN, article.getISSN()); + values.put(LAST_ACCESS, convertDateValue(article.getLastAccessed())); + values.put(PUBLICATION_DATE, convertDateValue(article.getPublicationDate())); + values.put(URL, article.getUrl()); + values.put(URN, article.getUrn()); + values.put(DOI, article.getDoi()); + + return values; + } + + @Override + public String getCCMType() { + return InternetArticle.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/MonographConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/MonographConverter.java new file mode 100644 index 000000000..5903bac9d --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/MonographConverter.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.Monograph; +import com.arsdigita.cms.contenttypes.Publication; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class MonographConverter extends PublicationWithPublisherConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof Monograph)) { + throw new UnsupportedCcmTypeException( + String.format("The MonographConverter only " + + "supports publication types which are of the" + + "type Monograph or which are extending " + + "Monograph. The " + + "provided publication is of type '%s' which " + + "is not of type Monograph and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + final Map values = super.convert(publication); + + return values; + } + + @Override + public String getCCMType() { + return Monograph.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ProceedingsConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ProceedingsConverter.java new file mode 100644 index 000000000..70d9e8464 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ProceedingsConverter.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.Proceedings; +import com.arsdigita.cms.contenttypes.Publication; +import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class ProceedingsConverter extends PublicationWithPublisherConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof Proceedings)) { + throw new UnsupportedCcmTypeException( + String.format("The ProceedingsConverter only " + + "supports publication types which are of the" + + "type Proceedings or which are extending " + + "Proceedings. The " + + "provided publication is of type '%s' which " + + "is not of type Proceedings and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + final Map values = super.convert(publication); + + final Proceedings proceedings = (Proceedings) publication; + + values.put(CONFERENCE, proceedings.getNameOfConference()); + values.put(CONFERENCE_PLACE, proceedings.getPlaceOfConference()); + values.put(CONFERENCE_DATE_FROM, convertDateValue(proceedings.getDateFromOfConference())); + values.put(CONFERENCE_DATE_TO, convertDateValue(proceedings.getDateToOfConference())); + + return values; + } + + @Override + public String getCCMType() { + return Proceedings.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/PublicationConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/PublicationConverter.java new file mode 100644 index 000000000..88a5685b3 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/PublicationConverter.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.AuthorshipCollection; +import com.arsdigita.cms.contenttypes.Publication; +import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*; +import java.util.Calendar; +import java.util.Date; +import java.util.EnumMap; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class PublicationConverter implements CsvConverter { + + @Override + public Map convert(final Publication publication) { + + if (publication == null) { + throw new IllegalArgumentException("Can't convert null values"); + } + + final Map values = new EnumMap( + CsvExporterConstants.class); + + values.put(PUBLICATION_ID, publication.getID().toString()); + values.put(PUBLICATION_TYPE, publication.getClass().getName()); + values.put(TITLE, publication.getTitle()); + values.put(YEAR, convertIntegerValue(publication.getYearOfPublication())); + values.put(YEAR_FIRST_PUBLISHED, convertIntegerValue(publication.getYearFirstPublished())); + values.put(LANGUAGE_OF_PUBLICATION, publication.getLanguageOfPublication()); + values.put(REVIEWED, convertBooleanValue(publication.getReviewed())); + + values.put(AUTHORS, convertAuthors(publication.getAuthors())); + + return values; + } + + protected String convertAuthors(final AuthorshipCollection authors) { + final StringBuilder authorsCol = new StringBuilder(); + + while (authors.next()) { + authorsCol.append(authors.getSurname()); + if (authors.getGivenName() != null) { + authorsCol.append(", "); + authorsCol.append(authors.getGivenName()); + } + authorsCol.append(';'); + } + + return authorsCol.toString(); + } + + protected String convertIntegerValue(final Integer value) { + if (value == null) { + return ""; + } else { + return value.toString(); + } + } + + protected String convertBooleanValue(final Boolean value) { + if (value == null) { + return ""; + } else { + return value.toString(); + } + } + + protected String convertDateValue(final Date value) { + if (value == null) { + return ""; + } else { + final Calendar calender = Calendar.getInstance(); + calender.setTime(value); + + return String.format("%d-%d-%d", calender.get(Calendar.YEAR), + calender.get(Calendar.MONTH), + calender.get(Calendar.DAY_OF_MONTH)); + + } + } + + @Override + public String getCCMType() { + return Publication.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/PublicationWithPublisherConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/PublicationWithPublisherConverter.java new file mode 100644 index 000000000..0d6cc1c78 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/PublicationWithPublisherConverter.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.PublicationWithPublisher; +import java.util.Map; + +import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class PublicationWithPublisherConverter extends PublicationConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof PublicationWithPublisher)) { + throw new UnsupportedCcmTypeException( + String.format("The PublicationWithPublisherConverter only " + + "supports publication types which are of the" + + "type PublicationWithPublisher or which are extending " + + "PublicationWithPublisher. The " + + "provided publication is of type '%s' which " + + "is not of type PublicationWithPublisher and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + final PublicationWithPublisher publicationWithPublisher + = (PublicationWithPublisher) publication; + + final Map values = super.convert(publication); + + values.put(ISBN, publicationWithPublisher.getISBN()); + values.put(VOLUME, convertIntegerValue(publicationWithPublisher.getVolume())); + values.put(NUMBER_OF_VOLUMES, convertIntegerValue(publicationWithPublisher. + getNumberOfVolumes())); + values.put(NUMBER_OF_PAGES, convertIntegerValue( + publicationWithPublisher.getNumberOfPages())); + values.put(EDITION, publicationWithPublisher.getEdition()); + if (publicationWithPublisher.getPublisher() != null) { + values.put(PLACE, publicationWithPublisher.getPublisher().getPlace()); + values.put(PUBLISHER, publicationWithPublisher.getPublisher().getPublisherName()); + } + + return values; + } + + @Override + public String getCCMType() { + return PublicationWithPublisher.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ReviewConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ReviewConverter.java new file mode 100644 index 000000000..4135b297d --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/ReviewConverter.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.Review; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class ReviewConverter extends ArticleInJournalConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof Review)) { + throw new UnsupportedCcmTypeException( + String.format("The ReviewConverter only " + + "supports publication types which are of the" + + "type Review or which are extending " + + "Review. The " + + "provided publication is of type '%s' which " + + "is not of type Review and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + return super.convert(publication); + + } + + @Override + public String getCCMType() { + return Review.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/UnPublishedConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/UnPublishedConverter.java new file mode 100644 index 000000000..a77c361c8 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/UnPublishedConverter.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.UnPublished; +import java.util.Map; + +import static com.arsdigita.cms.scipublications.exporter.csv.CsvExporterConstants.*; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class UnPublishedConverter extends PublicationConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof UnPublished)) { + throw new UnsupportedCcmTypeException( + String.format("The UnPublishedConverter only " + + "supports publication types which are of the" + + "type UnPublished or which are extending " + + "UnPublished. The " + + "provided publication is of type '%s' which " + + "is not of type UnPublished and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + final UnPublished unPublished = (UnPublished) publication; + + final Map values = super.convert(publication); + + values.put(PLACE, unPublished.getPlace()); + values.put(NUMBER, unPublished.getNumber()); + values.put(NUMBER_OF_PAGES, convertIntegerValue(unPublished.getNumberOfPages())); + + if (unPublished.getOrganization() != null) { + values.put(ORGANISATION, unPublished.getOrganization().getTitle()); + } + + return values; + + } + + @Override + public String getCCMType() { + return UnPublished.class.getName(); + } + +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/UnsupportedCcmTypeException.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/UnsupportedCcmTypeException.java new file mode 100644 index 000000000..0f5eba69e --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/UnsupportedCcmTypeException.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +package com.arsdigita.cms.scipublications.exporter.csv; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class UnsupportedCcmTypeException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** + * Creates a new instance of UnsupportedCcmType without detail message. + */ + public UnsupportedCcmTypeException() { + } + + /** + * Constructs an instance of UnsupportedCcmType with the specified detail message. + * @param msg the detail message. + */ + public UnsupportedCcmTypeException(final String msg) { + super(msg); + } + + public UnsupportedCcmTypeException(final Throwable cause) { + super(cause); + } + + public UnsupportedCcmTypeException(final String msg, Throwable cause) { + super(msg, cause); + } +} diff --git a/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/WorkingPaperConverter.java b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/WorkingPaperConverter.java new file mode 100644 index 000000000..6ce49ce80 --- /dev/null +++ b/ccm-sci-publicationscsvexporter/src/com/arsdigita/cms/scipublications/exporter/csv/WorkingPaperConverter.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * This library is free software, you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library, if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.scipublications.exporter.csv; + +import com.arsdigita.cms.contenttypes.Publication; +import com.arsdigita.cms.contenttypes.WorkingPaper; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class WorkingPaperConverter extends UnPublishedConverter { + + @Override + public Map convert(final Publication publication) { + + if (!(publication instanceof WorkingPaper)) { + throw new UnsupportedCcmTypeException( + String.format("The WorkingPaperConverter only " + + "supports publication types which are of the" + + "type WorkingPaper or which are extending " + + "WorkingPaper. The " + + "provided publication is of type '%s' which " + + "is not of type WorkingPaper and does not " + + "extends PubliccationWithPublisher.", + publication.getClass().getName())); + } + + return super.convert(publication); + + } + + @Override + public String getCCMType() { + return WorkingPaper.class.getName(); + } + +}