From 0dd86b9bb27f96892dad4243a7669760c3db93d9 Mon Sep 17 00:00:00 2001
From: jensp
Date: Thu, 12 Jan 2012 14:00:12 +0000
Subject: [PATCH] =?UTF-8?q?Tuning=20f=C3=BCr=20die=20Publikations-Exporter?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
git-svn-id: https://svn.libreccm.org/ccm/trunk@1443 8810af33-2d31-482b-a856-94f89814c4df
---
.../SciPublicationsServlet.java | 225 ++++++++++++++----
.../ArticleInCollectedVolumeConverter.java | 21 +-
.../ArticleInCollectedVolumeConverter.java | 9 +-
3 files changed, 200 insertions(+), 55 deletions(-)
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 5e0fe5d80..67c3148a6 100644
--- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsServlet.java
+++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/SciPublicationsServlet.java
@@ -26,14 +26,21 @@ import com.arsdigita.bebop.PageFactory;
import com.arsdigita.categorization.CategorizedCollection;
import com.arsdigita.categorization.Category;
import com.arsdigita.cms.ContentBundle;
+import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
+import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.Publication;
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporter;
import com.arsdigita.cms.scipublications.exporter.SciPublicationsExporters;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainObjectFactory;
+import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.kernel.ACSObject;
-import com.arsdigita.persistence.OID;
+import com.arsdigita.kernel.Kernel;
+import com.arsdigita.persistence.DataQuery;
+import com.arsdigita.persistence.Filter;
+import com.arsdigita.persistence.FilterFactory;
+import com.arsdigita.persistence.SessionManager;
import com.arsdigita.templating.PresentationManager;
import com.arsdigita.templating.Templating;
import com.arsdigita.web.Application;
@@ -50,43 +57,28 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
/**
- *
- * The SciPublicationsServlet processes the
- * {@link HttpServletRequest} and calls the requested actions.
- * The available actions are:
- *
- *
- * export
- * -
- *
- * The export action exports content items of the type
+ *
The
+ * SciPublicationsServlet processes the
+ * {@link HttpServletRequest} and calls the requested actions. The available
+ * actions are:
export -
The
+ * export action exports content items of the type
* {@link Publication} in several formats, like BibTeX or RIS.
- * The export action has the following query parameters:
- *
- *
- * format
- * - Specifies the format which is used to export the publications.
- * publication
- * - Specifies the publication(s) to export using the ID(s) of the
- * publications.
- * This parameter can occur more
- * than one time. In this case, all publications specified by the parameters
- * will be exported as a single file in specified format
- * category
- * - Specifies a category using the OID of the category. If this
- * parameter is present, all publications in the category and the subcategories
- * of the category will exported as a single file in the specified format.
- *
- *
- * The format argument is mandatory. Also their must be either one
- * or more publication parameters or a category
- * parameter. If the URL is not valid, the Servlet will respond with the
- * BAD_REQUEST (400) HTTP status code. If one of the specified publications or
- * the specified category can't be found, the Servlet will respond with the
- * NOT_FOUND (404) HTTP status code.
- *
- *
- *
+ * The export action has the following query parameters:
format
+ * - Specifies the format which is used to export the publications.
publication
+ * - Specifies the publication(s) to export using the ID(s) of the
+ * publications. This parameter can occur more than one time. In this case, all
+ * publications specified by the parameters will be exported as a single file in
+ * specified format
category - Specifies a category
+ * using the OID of the category. If this parameter is present, all publications
+ * in the category and the subcategories of the category will exported as a
+ * single file in the specified format.
The
+ * format argument is mandatory. Also their must be either one or
+ * more
+ * publication parameters or a
+ * category parameter. If the URL is not valid, the Servlet will
+ * respond with the BAD_REQUEST (400) HTTP status code. If one of the specified
+ * publications or the specified category can't be found, the Servlet will
+ * respond with the NOT_FOUND (404) HTTP status code.
*
* @author Jens Pelzetter
*/
@@ -112,7 +104,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
if ("/".equals(request.getPathInfo())) {
path = "";
} else if (request.getPathInfo().startsWith("/")
- && request.getPathInfo().endsWith("/")) {
+ && request.getPathInfo().endsWith("/")) {
path = request.getPathInfo().substring(1, request.getPathInfo().
length() - 1);
} else if (request.getPathInfo().startsWith("/")) {
@@ -149,7 +141,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
page.add(form);
page.lock();
-
+
Document document = page.buildDocument(request, response);
PresentationManager presentationManager = Templating.
getPresentationManager();
@@ -185,8 +177,9 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
}
if (parameters.containsKey("category")) {
- /* If the category parameter is present, retrieve the
- * specified category and exports all publications in it.
+ /*
+ * If the category parameter is present, retrieve the specified
+ * category and exports all publications in it.
*/
Publication publication;
SciPublicationsExporter exporter;
@@ -335,6 +328,134 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
//Export the publictions.
exportPublications(format, publicationIds, response);
+ } else if (parameters.containsKey("orgaunitId")) {
+
+ final BigDecimal orgaunitId = new BigDecimal(parameters.get(
+ "orgaunitId")[0]);
+
+ final GenericOrganizationalUnit orgaunit =
+ new GenericOrganizationalUnit(
+ orgaunitId);
+
+ final DataQuery publicationsQuery =
+ SessionManager.getSession().
+ retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfPublicationsForOrgaUnitOneRowPerAuthor");
+
+ final List orgaunitIds = new ArrayList();
+
+ if (parameters.containsKey("recursive")
+ && ("false".equals(parameters.get("recursive")[0]))) {
+ orgaunitIds.add(orgaunit.getID().toString());
+ } else {
+ final DataQuery subordinateQuery =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getIdsOfSubordinateOrgaUnitsRecursivly");
+ subordinateQuery.setParameter("orgaunitId", orgaunitId.
+ toString());
+
+ while (subordinateQuery.next()) {
+ orgaunitIds.add(subordinateQuery.get("orgaunitId").
+ toString());
+ }
+ }
+
+ publicationsQuery.setParameter("orgaunitIds", orgaunitIds);
+
+ if (parameters.containsKey("year")) {
+ publicationsQuery.addFilter(String.format("year = %s",
+ parameters.get(
+ "year")[0]));
+ }
+
+ if (Kernel.getConfig().languageIndependentItems()) {
+ FilterFactory ff = publicationsQuery.getFilterFactory();
+ Filter filter = ff.or().
+ addFilter(ff.equals("language", GlobalizationHelper.
+ getNegotiatedLocale().getLanguage())).
+ addFilter(ff.and().
+ addFilter(
+ ff.equals("language",
+ GlobalizationHelper.LANG_INDEPENDENT)).
+ addFilter(ff.notIn("parent",
+ "com.arsdigita.navigation.getParentIDsOfMatchedItems").
+ set("language", GlobalizationHelper.
+ getNegotiatedLocale().getLanguage())));
+ publicationsQuery.addFilter(filter);
+
+ } else {
+ publicationsQuery.addEqualsFilter("language",
+ GlobalizationHelper.
+ getNegotiatedLocale().getLanguage());
+ }
+
+ final List publicationIds =
+ new ArrayList();
+ while (publicationsQuery.next()) {
+ publicationIds.add((BigDecimal) publicationsQuery.get(
+ "publicationId"));
+ }
+
+ exportPublications(format, publicationIds, response);
+
+ } else if (parameters.containsKey("authorId")) {
+ final DataQuery publicationsQuery =
+ SessionManager.getSession().retrieveQuery(
+ "com.arsdigita.cms.contenttypes.getPublicationsForAuthor");
+
+ final BigDecimal authorId = new BigDecimal(parameters.get(
+ "authorId")[0]);
+ final GenericPerson author = new GenericPerson(authorId);
+ final StringBuilder authorFilterBuilder = new StringBuilder();
+ authorFilterBuilder.append('(');
+ authorFilterBuilder.append(String.format("authorId = %s",
+ authorId.toString()));
+
+ if (author.getAlias() != null) {
+ addAuthorAliasToFilter(authorFilterBuilder,
+ author.getAlias());
+ }
+
+ authorFilterBuilder.append(')');
+
+ publicationsQuery.addFilter(authorFilterBuilder.toString());
+
+ if (parameters.containsKey("year")) {
+ publicationsQuery.addFilter(String.format("yearOfPublication = %s",
+ parameters.get(
+ "year")[0]));
+ }
+
+ if (Kernel.getConfig().languageIndependentItems()) {
+ FilterFactory ff = publicationsQuery.getFilterFactory();
+ Filter filter = ff.or().
+ addFilter(ff.equals("language", GlobalizationHelper.
+ getNegotiatedLocale().getLanguage())).
+ addFilter(ff.and().
+ addFilter(
+ ff.equals("language",
+ GlobalizationHelper.LANG_INDEPENDENT)).
+ addFilter(ff.notIn("parent",
+ "com.arsdigita.navigation.getParentIDsOfMatchedItems").
+ set("language", GlobalizationHelper.
+ getNegotiatedLocale().getLanguage())));
+ publicationsQuery.addFilter(filter);
+
+ } else {
+ publicationsQuery.addEqualsFilter("language",
+ GlobalizationHelper.
+ getNegotiatedLocale().getLanguage());
+ }
+
+ final List publicationIds =
+ new ArrayList();
+ while (publicationsQuery.next()) {
+ publicationIds.add((BigDecimal) publicationsQuery.get(
+ "publicationId"));
+ }
+
+ 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."
@@ -342,7 +463,6 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
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.");
- return;
}
} else {
@@ -393,6 +513,7 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
Publication publication = null;
String publicationName = "publication";
+ StringBuilder result = new StringBuilder();
for (BigDecimal publicationId : publicationIds) {
try {
@@ -401,8 +522,9 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
logger.debug(String.format("OID of publication: %s",
publication.getOID()));
//Specialize the publication
- publication = (Publication) DomainObjectFactory.newInstance(publication.
- getOID());
+ publication =
+ (Publication) DomainObjectFactory.newInstance(
+ publication.getOID());
} catch (DataObjectNotFoundException ex) {
logger.warn(String.format("No publication found for id '%s'.",
publicationId.toPlainString()), ex);
@@ -418,7 +540,8 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
publication.getClass().getName()));
//Write the exported publication data to the response.
- response.getWriter().append(exporter.exportPublication(publication));
+ //response.getWriter().append(exporter.exportPublication(publication));
+ result.append(exporter.exportPublication(publication));
//response.getWriter().append('\n');
publicationName = publication.getName();
@@ -444,5 +567,17 @@ public class SciPublicationsServlet extends BaseApplicationServlet {
getFileExtension()));
}
+
+ result.append(result.toString());
+ }
+
+ private void addAuthorAliasToFilter(final StringBuilder builder,
+ final GenericPerson alias) {
+ builder.append(String.format("or authorId = %s",
+ alias.getID().toString()));
+
+ if (alias.getAlias() != null) {
+ addAuthorAliasToFilter(builder, alias.getAlias());
+ }
}
}
diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ArticleInCollectedVolumeConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ArticleInCollectedVolumeConverter.java
index 64c4f0adf..caddcd96f 100644
--- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ArticleInCollectedVolumeConverter.java
+++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/bibtex/converters/ArticleInCollectedVolumeConverter.java
@@ -28,11 +28,12 @@ import com.arsdigita.cms.scipublications.exporter.bibtex.builders.UnsupportedFie
import org.apache.log4j.Logger;
/**
- * Converts an {@link ArticleInCollectedVolume} to a BibTeX
+ * Converts an {@link ArticleInCollectedVolume} to a BibTeX
* incollection reference.
*
* @author Jens Pelzetter
- * @version $Id$
+ * @version $Id: ArticleInCollectedVolumeConverter.java 740 2011-02-07 18:56:18Z
+ * jensp $
*/
public class ArticleInCollectedVolumeConverter extends AbstractBibTeXConverter {
@@ -111,16 +112,22 @@ public class ArticleInCollectedVolumeConverter extends AbstractBibTeXConverter {
}
if (article.getPagesFrom() != null) {
- builder.setField(BibTeXField.PAGES,
- String.format("%s - %s",
- article.getPagesFrom(),
- article.getPagesTo()));
+ if (article.getPagesTo() == null) {
+ builder.setField(BibTeXField.PAGES,
+ String.format("%s",
+ article.getPagesFrom()));
+ } else {
+ builder.setField(BibTeXField.PAGES,
+ String.format("%s - %s",
+ article.getPagesFrom(),
+ article.getPagesTo()));
+ }
}
} catch (UnsupportedFieldException ex) {
logger.warn("Tried to set unsupported BibTeX field while "
- + "converting a publication");
+ + "converting a publication", ex);
}
return builder.toBibTeX();
diff --git a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInCollectedVolumeConverter.java b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInCollectedVolumeConverter.java
index 43338b38f..1a1282d2f 100644
--- a/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInCollectedVolumeConverter.java
+++ b/ccm-sci-publications/src/com/arsdigita/cms/scipublications/exporter/ris/ArticleInCollectedVolumeConverter.java
@@ -26,7 +26,8 @@ import com.arsdigita.cms.contenttypes.Publication;
* Converts a {@link ArticleInCollectedVolume} to a RIS reference.
*
* @author Jens Pelzetter
- * @version $Id$
+ * @version $Id: ArticleInCollectedVolumeConverter.java 740 2011-02-07 18:56:18Z
+ * jensp $
*/
public class ArticleInCollectedVolumeConverter extends AbstractRisConverter {
@@ -63,8 +64,10 @@ public class ArticleInCollectedVolumeConverter extends AbstractRisConverter {
if (article.getPagesFrom() != null) {
getRisBuilder().addField(RisFields.SP,
article.getPagesFrom().toString());
- getRisBuilder().addField(RisFields.EP,
- article.getPagesTo().toString());
+ if (article.getPagesTo() != null) {
+ getRisBuilder().addField(RisFields.EP,
+ article.getPagesTo().toString());
+ }
}
return getRisBuilder().toRis();