slub.team team mailing list archive
-
slub.team team
-
Mailing list archive
-
Message #00422
[Merge] lp:~zeutschel/goobi-production/extended-jersey-api into lp:goobi-production
Matthias Ronge has proposed merging lp:~zeutschel/goobi-production/extended-jersey-api into lp:goobi-production.
Requested reviews:
Saxon State Library Team (slub.team)
For more details, see:
https://code.launchpad.net/~zeutschel/goobi-production/extended-jersey-api/+merge/133640
This adds two more outputs to the Jersey API. …/rest/catalogueConfiguration:
<catalogueConfiguration>
<interface>SUB</interface>
<interface>GBV</interface>
[…]
<mediaType key="monograph">
<label lang="de">Monographie</label>
<label lang="en">Monograph</label>
<receivingValue>Aa</receivingValue>
<receivingValue>Oa</receivingValue>
<tiffHeaderTag>Monographie</tiffHeaderTag>
</mediaType>
<mediaType key="periodical">
<label lang="de">Zeitschrift</label>
<label lang="en">Periodical</label>
[…]
…/rest/projects:
<projects>
<project key="Signaturengruppe ars.hydr.">
<template key="Digitalisierungsprojekt_ars_hydr">
<collection>Autobiographica</collection>
<collection>DigiWunschbuch</collection>
[…]
</template>
<field key="Titel">
<required>true</required>
<source>vorlage</source>
<ughbinding>true</ughbinding>
<insertionLevel>topstruct</insertionLevel>
</field>
<field key="Schrifttyp">
<required>false</required>
<source>werk</source>
<option label="gemischt">gemischt</option>
<option label="Fraktur">Fraktur</option>
<option label="Antiqua">Antiqua</option>
<ughbinding>false</ughbinding>
</field>
[…]
--
https://code.launchpad.net/~zeutschel/goobi-production/extended-jersey-api/+merge/133640
Your team Saxon State Library Team is requested to review the proposed merge of lp:~zeutschel/goobi-production/extended-jersey-api into lp:goobi-production.
=== added file 'lib/lava3-core.jar'
Binary files lib/lava3-core.jar 1970-01-01 00:00:00 +0000 and lib/lava3-core.jar 2012-11-09 10:34:26 +0000 differ
=== modified file 'src/de/sub/goobi/beans/Projekt.java'
--- src/de/sub/goobi/beans/Projekt.java 2011-12-20 08:07:09 +0000
+++ src/de/sub/goobi/beans/Projekt.java 2012-11-09 10:34:26 +0000
@@ -22,6 +22,7 @@
package de.sub.goobi.beans;
+import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
@@ -29,12 +30,25 @@
import java.util.List;
import java.util.Set;
+import javax.xml.bind.annotation.*;
+
import org.goobi.production.flow.statistics.StepInformation;
+import org.goobi.webapi.beans.Field;
import de.sub.goobi.helper.ProjectHelper;
import de.sub.goobi.helper.enums.MetadataFormat;
-
+@XmlAccessorType(XmlAccessType.NONE)
+// This annotation is to instruct the Jersey API not to generate arbitrary XML
+// elements. Further XML elements can be added as needed by annotating with
+// @XmlElement, but their respective names should be wisely chosen according to
+// the Coding Guidelines (e.g. *english* names).
+@XmlType(propOrder = { "template", "fieldConfig" })
+// This annotation declares the desired order of XML elements generated and
+// rather serves for better legibility of the generated XML. The list must be
+// exhaustive and the properties have to be named according to their respective
+// getter function, e.g. @XmlElement(name="field") getFieldConfig() must be
+// referenced as "fieldConfig" here, not "field" as one might expect.
public class Projekt implements Serializable {
private static final long serialVersionUID = -8543713331407761617L;
private Integer id;
@@ -73,6 +87,14 @@
private Integer numberOfPages;
private Integer numberOfVolumes;
+ @XmlElement(name = "template")
+ public List<Prozess> template; // The ‘template’ variable is populated from
+ // org.goobi.webapi.resources.Projects when
+ // calling ${SERVLET_CONTEXT}/rest/projects
+ // to output the templates available within
+ // a project as XML child nodes of the
+ // respective project.
+
public Projekt() {
prozesse = new HashSet<Prozess>();
benutzer = new HashSet<Benutzer>();
@@ -118,6 +140,7 @@
this.prozesse = prozesse;
}
+ @XmlAttribute(name="key")
public String getTitel() {
return titel;
}
@@ -437,4 +460,9 @@
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
+
+ @XmlElement(name="field")
+ public List<Field> getFieldConfig() throws IOException{
+ return Field.getFieldConfigForProject(this);
+ }
}
=== modified file 'src/de/sub/goobi/beans/Prozess.java'
--- src/de/sub/goobi/beans/Prozess.java 2012-07-30 11:42:24 +0000
+++ src/de/sub/goobi/beans/Prozess.java 2012-11-09 10:34:26 +0000
@@ -36,11 +36,17 @@
import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
import org.apache.log4j.Logger;
import org.goobi.io.BackupFileRotation;
import org.goobi.production.api.property.xmlbasedprovider.Status;
import org.goobi.production.export.ExportDocket;
+import org.jdom.JDOMException;
import ugh.dl.Fileformat;
import ugh.exceptions.PreferencesException;
@@ -54,6 +60,7 @@
import de.sub.goobi.beans.property.IGoobiEntity;
import de.sub.goobi.beans.property.IGoobiProperty;
import de.sub.goobi.config.ConfigMain;
+import de.sub.goobi.config.DigitalCollections;
import de.sub.goobi.helper.FilesystemHelper;
import de.sub.goobi.helper.Helper;
import de.sub.goobi.helper.Messages;
@@ -67,6 +74,11 @@
import de.sub.goobi.persistence.BenutzerDAO;
import de.sub.goobi.persistence.ProzessDAO;
+@XmlAccessorType(XmlAccessType.NONE)
+// This annotation is to instruct the Jersey API not to generate arbitrary XML
+// elements. Further XML elements can be added as needed by annotating with
+// @XmlElement, but their respective names should be wisely chosen according to
+// the Coding Guidelines (e.g. *english* names).
public class Prozess implements Serializable, IGoobiEntity {
private static final Logger myLogger = Logger.getLogger(Prozess.class);
private static final long serialVersionUID = -6503348094655786275L;
@@ -144,6 +156,7 @@
this.istTemplate = istTemplate;
}
+ @XmlAttribute(name="key")
public String getTitel() {
return titel;
}
@@ -946,4 +959,9 @@
}
return "";
}
+
+ @XmlElement(name = "collection")
+ public List<String> getPossibleDigitalCollections() throws JDOMException, IOException {
+ return DigitalCollections.possibleDigitalCollectionsForProcess(this);
+ }
}
=== modified file 'src/de/sub/goobi/config/ConfigOpac.java'
--- src/de/sub/goobi/config/ConfigOpac.java 2012-02-22 07:43:02 +0000
+++ src/de/sub/goobi/config/ConfigOpac.java 2012-11-09 10:34:26 +0000
@@ -26,12 +26,16 @@
import java.util.ArrayList;
import java.util.HashMap;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
import de.sub.goobi.helper.Helper;
+@XmlRootElement(name="catalogueConfiguration")
public class ConfigOpac {
private XMLConfiguration config;
private static String configPfad;
@@ -107,6 +111,7 @@
/**
* return all configured Catalogue-Titles from Configfile
* ================================================================*/
+ @XmlElement(name="interface")
public ArrayList<String> getAllCatalogueTitles() {
ArrayList<String> myList = new ArrayList<String>();
int countCatalogues = config.getMaxIndex("catalogue");
@@ -133,6 +138,7 @@
/**
* return all configured Doctype-Titles from Configfile
* ================================================================*/
+ @XmlElement(name="mediaType")
public ArrayList<ConfigOpacDoctype> getAllDoctypes() {
ArrayList<ConfigOpacDoctype> myList = new ArrayList<ConfigOpacDoctype>();
for (String title : getAllDoctypeTitles()) {
=== modified file 'src/de/sub/goobi/config/ConfigOpacDoctype.java'
--- src/de/sub/goobi/config/ConfigOpacDoctype.java 2011-12-20 08:07:09 +0000
+++ src/de/sub/goobi/config/ConfigOpacDoctype.java 2012-11-09 10:34:26 +0000
@@ -25,8 +25,14 @@
//TODO: Move this into the GetOPAC Package
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import javax.faces.context.FacesContext;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+
+import org.goobi.webapi.beans.Label;
+import org.goobi.webapi.beans.Label.KeyAttribute;
public class ConfigOpacDoctype {
private String title = "";
@@ -38,6 +44,10 @@
private HashMap<String, String> labels;
private ArrayList<String> mappings;
+ public ConfigOpacDoctype() { // stupid Jersey API requires no-arg default constructor which is never used
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
public ConfigOpacDoctype(String inTitle, String inRulesetType, String inTifHeaderType, boolean inPeriodical, boolean inMultiVolume,
boolean inContainedWork, HashMap<String, String> inLabels, ArrayList<String> inMappings) {
title = inTitle;
@@ -50,6 +60,7 @@
mappings = inMappings;
}
+ @XmlAttribute(name="key")
public String getTitle() {
return title;
}
@@ -58,6 +69,7 @@
return rulesetType;
}
+ @XmlElement(name="tiffHeaderTag")
public String getTifHeaderType() {
return tifHeaderType;
}
@@ -78,6 +90,12 @@
return labels;
}
+ @XmlElement(name="label")
+ public List<Label> getLabelsForJerseyApi() {
+ return Label.toListOfLabels(labels, KeyAttribute.LANGUAGE);
+ }
+
+ @XmlElement(name="receivingValue")
public ArrayList<String> getMappings() {
return mappings;
}
=== added file 'src/org/goobi/webapi/beans/Field.java'
--- src/org/goobi/webapi/beans/Field.java 1970-01-01 00:00:00 +0000
+++ src/org/goobi/webapi/beans/Field.java 2012-11-09 10:34:26 +0000
@@ -0,0 +1,73 @@
+package org.goobi.webapi.beans;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.goobi.webapi.beans.Label.KeyAttribute;
+
+import de.sub.goobi.beans.Projekt;
+import de.sub.goobi.config.ConfigProjects;
+
+@XmlType(propOrder = { "required", "from", "option", "ughbinding", "docstruct" })
+public class Field {
+
+ @SuppressWarnings("unused")
+ @XmlAttribute
+ private String key;
+ @SuppressWarnings("unused")
+ @XmlElement
+ private boolean required;
+ @SuppressWarnings("unused")
+ @XmlElement
+ private List<Label> option;
+ @SuppressWarnings("unused")
+ @XmlElement(name="source")
+ private String from;
+ @SuppressWarnings("unused")
+ @XmlElement
+ private Boolean ughbinding;
+ @SuppressWarnings("unused")
+ @XmlElement(name="insertionLevel")
+ private String docstruct;
+
+ public static List<Field> getFieldConfigForProject(Projekt project) throws IOException {
+ List<Field> fields = new ArrayList<Field>();
+
+ ConfigProjects projectConfig = new ConfigProjects(project);
+ Integer numFields = projectConfig.getParamList("createNewProcess.itemlist.item").size();
+
+ for (Integer field = 0; field < numFields; field++) {
+ Field fieldConfig = new Field();
+ String fieldRef = "createNewProcess.itemlist.item(" + field + ")";
+ fieldConfig.key = projectConfig.getParamString(fieldRef);
+
+ fieldConfig.from = projectConfig.getParamString(fieldRef + "[@from]");
+ if (projectConfig.getParamBoolean(fieldRef + "[@ughbinding]")) {
+ fieldConfig.ughbinding = Boolean.TRUE;
+ fieldConfig.docstruct = projectConfig.getParamString(fieldRef + "[@docstruct]");
+ } else {
+ fieldConfig.ughbinding = Boolean.FALSE;
+ }
+ Integer selectEntries = projectConfig.getParamList(fieldRef + ".select").size();
+ if (selectEntries > 0) {
+ Map<String, String> selectConfig = new HashMap<String, String>();
+ for (Integer selectEntry = 0; selectEntry < selectEntries; selectEntry++) {
+ String key = projectConfig.getParamString(fieldRef + ".select(" + selectEntry + ")");
+ String value = projectConfig.getParamString(fieldRef + ".select(" + selectEntry + ")[@label]");
+ selectConfig.put(key, value);
+ }
+ fieldConfig.option = Label.toListOfLabels(selectConfig, KeyAttribute.LABEL);
+ }
+ fieldConfig.required = projectConfig.getParamBoolean(fieldRef + "[@required]");
+ fields.add(fieldConfig);
+ }
+ return fields;
+ }
+}
=== added file 'src/org/goobi/webapi/beans/Label.java'
--- src/org/goobi/webapi/beans/Label.java 1970-01-01 00:00:00 +0000
+++ src/org/goobi/webapi/beans/Label.java 2012-11-09 10:34:26 +0000
@@ -0,0 +1,53 @@
+package org.goobi.webapi.beans;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlValue;
+
+import com.sharkysoft.util.UnreachableCodeException;
+
+/**
+ * The Label class provides serialization for Map<String,String> objects where
+ * keys are language identifiers (examples include “en”, “de”, …) and values are
+ * texts in the respective language. This is necessary because Maps
+ * unfortunately do not natively serialize to XML.
+ *
+ * @author Matthias Ronge <matthias.ronge@xxxxxxxxxxxx>
+ */
+public class Label {
+ public enum KeyAttribute {
+ LABEL, LANGUAGE
+ }
+
+ @XmlAttribute(name = "label")
+ public String label;
+
+ @XmlAttribute(name = "lang")
+ public String language;
+
+ @XmlValue
+ public String value;
+
+ public static List<Label> toListOfLabels(Map<String, String> data, KeyAttribute keyAttribute) {
+ List<Label> result = new ArrayList<Label>();
+ for (String key : data.keySet()) {
+ Label entry = new Label();
+ switch (keyAttribute) {
+ case LABEL:
+ entry.label = key;
+ break;
+ case LANGUAGE:
+ entry.language = key;
+ break;
+ default:
+ throw new UnreachableCodeException();
+ }
+ entry.value = data.get(key);
+ result.add(entry);
+ }
+ return result;
+ }
+}
\ No newline at end of file
=== added file 'src/org/goobi/webapi/beans/ProjectsRootNode.java'
--- src/org/goobi/webapi/beans/ProjectsRootNode.java 1970-01-01 00:00:00 +0000
+++ src/org/goobi/webapi/beans/ProjectsRootNode.java 2012-11-09 10:34:26 +0000
@@ -0,0 +1,34 @@
+package org.goobi.webapi.beans;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import de.sub.goobi.beans.Projekt;
+
+/**
+ * The ProjectsRootNode class is necessary to control the XML root element’s
+ * name to be ‘projects’. Simply annotating the de.sub.goobi.beans.Projekt class
+ * with @XmlRootElement(name = "project") results in a wrapping element named
+ * <projekts> who’s name is still derived from the classes’ name, not from the
+ * ‘name’ property set in the annotation and cannot be changed otherwise.
+ *
+ * @author Matthias Ronge <matthias.ronge@xxxxxxxxxxxx>
+ */
+@XmlRootElement(name = "projects")
+public class ProjectsRootNode {
+ @SuppressWarnings("unused")
+ @XmlElement(name = "project")
+ private ArrayList<Projekt> projects;
+
+ public ProjectsRootNode() { // stupid Jersey API requires no-arg default constructor which is never used
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public ProjectsRootNode(Collection<Projekt> data) {
+ projects = new ArrayList<Projekt>(data);
+ }
+
+}
\ No newline at end of file
=== added file 'src/org/goobi/webapi/resources/CatalogueConfiguration.java'
--- src/org/goobi/webapi/resources/CatalogueConfiguration.java 1970-01-01 00:00:00 +0000
+++ src/org/goobi/webapi/resources/CatalogueConfiguration.java 2012-11-09 10:34:26 +0000
@@ -0,0 +1,46 @@
+/*
+ * This file is part of the Goobi Application - a Workflow tool for the support
+ * of mass digitization.
+ *
+ * Visit the websites for more information. - http://gdz.sub.uni-goettingen.de -
+ * http://www.goobi.org - http://launchpad.net/goobi-production
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program 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 General Public License for more
+ * details. You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.goobi.webapi.resources;
+
+import java.io.IOException;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import de.sub.goobi.config.ConfigOpac;
+
+/**
+ * The CatalogueConfiguration class provides the Jersey API URL pattern
+ * ${SERVLET_CONTEXT}/rest/catalogueConfiguration which returns the major data
+ * from the ConfigOpac() configuration class in XML or JSON format.
+ *
+ * @author Matthias Ronge <matthias.ronge@xxxxxxxxxxxx>
+ */
+@Path("/catalogueConfiguration")
+public class CatalogueConfiguration {
+
+ @GET
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ public ConfigOpac getCatalogueConfiguration() throws IOException {
+ return new ConfigOpac();
+ }
+}
=== added file 'src/org/goobi/webapi/resources/Projects.java'
--- src/org/goobi/webapi/resources/Projects.java 1970-01-01 00:00:00 +0000
+++ src/org/goobi/webapi/resources/Projects.java 2012-11-09 10:34:26 +0000
@@ -0,0 +1,74 @@
+/*
+ * This file is part of the Goobi Application - a Workflow tool for the support
+ * of mass digitization.
+ *
+ * Visit the websites for more information. - http://gdz.sub.uni-goettingen.de -
+ * http://www.goobi.org - http://launchpad.net/goobi-production
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program 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 General Public License for more
+ * details. You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.goobi.webapi.resources;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.goobi.webapi.beans.ProjectsRootNode;
+
+import de.sub.goobi.beans.Projekt;
+import de.sub.goobi.beans.Prozess;
+import de.sub.goobi.helper.Helper;
+
+/**
+ * The CatalogueConfiguration class provides the Jersey API URL pattern
+ * ${SERVLET_CONTEXT}/rest/projects which returns the major data from the
+ * project configuration in XML or JSON format.
+ *
+ * @author Matthias Ronge <matthias.ronge@xxxxxxxxxxxx>
+ */
+@Path("/projects")
+public class Projects {
+
+ @GET
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ public ProjectsRootNode getAllProjectsWithTheirRespectiveTemplates() throws IOException {
+ Map<Projekt, Set<Prozess>> data = new HashMap<Projekt, Set<Prozess>>();
+
+ @SuppressWarnings("unchecked")
+ List<Prozess> processes = (List<Prozess>) Helper.getHibernateSession().createCriteria(Prozess.class).list();
+ for (Prozess process : processes) {
+ if (process.isIstTemplate()) {
+ Projekt project = process.getProjekt();
+ Set<Prozess> templates = data.containsKey(project) ? data.get(project) : new HashSet<Prozess>();
+ templates.add(process);
+ data.put(project, templates);
+ }
+ }
+ List<Projekt> result = new ArrayList<Projekt>();
+ for(Projekt project : data.keySet()){
+ project.template = new ArrayList<Prozess>(data.get(project));
+ result.add(project);
+ }
+ return new ProjectsRootNode(result);
+ }
+}
Follow ups