diff --git a/common/src/main/java/de/uni_jena/thunibib/his/api/v1/CommonType.java b/common/src/main/java/de/uni_jena/thunibib/his/api/v1/CommonType.java new file mode 100644 index 000000000..bae16a45c --- /dev/null +++ b/common/src/main/java/de/uni_jena/thunibib/his/api/v1/CommonType.java @@ -0,0 +1,70 @@ +package de.uni_jena.thunibib.his.api.v1; + +import com.fasterxml.jackson.annotation.JsonProperty; + +abstract public class CommonType { + @JsonProperty("id") + private int id; + @JsonProperty("lockVersion") + private int lockVersion; + @JsonProperty("objGuid") + private String objGuid; + @JsonProperty("shorttext") + private String shortText; + @JsonProperty("defaulttext") + private String defaultText; + @JsonProperty("longtext") + private String longText; + @JsonProperty("text") + private String text; + @JsonProperty("hiskeyId") + private int hisKeyId; + @JsonProperty("sortorder") + private int sortOrder; + @JsonProperty("uniquename") + private String uniqueName; + + public int getId() { + return id; + } + + public int getLockVersion() { + return lockVersion; + } + + public String getObjGuid() { + return objGuid; + } + + public String getShortText() { + return shortText; + } + + public String getDefaultText() { + return defaultText; + } + + public String getLongText() { + return longText; + } + + public String getText() { + return text; + } + + public int getHisKeyId() { + return hisKeyId; + } + + public int getSortOrder() { + return sortOrder; + } + + public String getUniqueName() { + return uniqueName; + } + + public String toString() { + return id + ":" + uniqueName; + } +} diff --git a/common/src/main/java/de/uni_jena/thunibib/his/api/v1/cs/sys/values/PublicationTypeValue.java b/common/src/main/java/de/uni_jena/thunibib/his/api/v1/cs/sys/values/PublicationTypeValue.java index 7298f9365..e6c2c219e 100644 --- a/common/src/main/java/de/uni_jena/thunibib/his/api/v1/cs/sys/values/PublicationTypeValue.java +++ b/common/src/main/java/de/uni_jena/thunibib/his/api/v1/cs/sys/values/PublicationTypeValue.java @@ -1,73 +1,11 @@ package de.uni_jena.thunibib.his.api.v1.cs.sys.values; -import com.fasterxml.jackson.annotation.JsonProperty; +import de.uni_jena.thunibib.his.api.v1.CommonType; /** * Path: /api/v1/cs/sys/values/publicationTypeValue * */ -public class PublicationTypeValue { - @JsonProperty("id") - private int id; - @JsonProperty("lockVersion") - private int lockVersion; - @JsonProperty("objGuid") - private String objGuid; - @JsonProperty("shorttext") - private String shortText; - @JsonProperty("defaulttext") - private String defaultText; - @JsonProperty("longtext") - private String longText; - @JsonProperty("text") - private String text; - @JsonProperty("hiskeyId") - private int hisKeyId; - @JsonProperty("sortorder") - private int sortOrder; - @JsonProperty("uniquename") - private String uniqueName; - - public int getId() { - return id; - } - - public int getLockVersion() { - return lockVersion; - } - - public String getObjGuid() { - return objGuid; - } - - public String getShortText() { - return shortText; - } - - public String getDefaultText() { - return defaultText; - } - - public String getLongText() { - return longText; - } - - public String getText() { - return text; - } - - public int getHisKeyId() { - return hisKeyId; - } - - public int getSortOrder() { - return sortOrder; - } - - public String getUniqueName() { - return uniqueName; - } - - public String toString() { - return id + ":" + uniqueName; +public class PublicationTypeValue extends CommonType { + public PublicationTypeValue() { } } diff --git a/common/src/main/java/de/uni_jena/thunibib/his/api/v1/fs/res/state/PublicationState.java b/common/src/main/java/de/uni_jena/thunibib/his/api/v1/fs/res/state/PublicationState.java new file mode 100644 index 000000000..a04c6dba7 --- /dev/null +++ b/common/src/main/java/de/uni_jena/thunibib/his/api/v1/fs/res/state/PublicationState.java @@ -0,0 +1,11 @@ +package de.uni_jena.thunibib.his.api.v1.fs.res.state; + +import de.uni_jena.thunibib.his.api.v1.CommonType; + +/** + * Path: /api/v1/fs/res/state/publication + * */ +public class PublicationState extends CommonType { + public PublicationState() { + } +} diff --git a/common/src/main/java/de/uni_jena/thunibib/his/content/transformer/PublicationHisResTransformer.java b/common/src/main/java/de/uni_jena/thunibib/his/content/transformer/PublicationHisResTransformer.java index 525145d50..863d0662a 100644 --- a/common/src/main/java/de/uni_jena/thunibib/his/content/transformer/PublicationHisResTransformer.java +++ b/common/src/main/java/de/uni_jena/thunibib/his/content/transformer/PublicationHisResTransformer.java @@ -44,17 +44,23 @@ protected JsonObject toJSON(MCRContent source) throws IOException { Document xml = source.asXML(); JsonObject jsonObject = new JsonObject(); - add(jsonObject, "//modsContainer/mods:mods/mods:abstract", xml, "textAbstract"); - add(jsonObject, "//modsContainer/mods:mods/mods:originInfo/mods:dateIssued[1]", xml, "releaseYear"); - add(jsonObject, "//modsContainer/mods:mods/mods:originInfo/mods:edition", xml, "edition"); - add(jsonObject, "//modsContainer/mods:mods/mods:originInfo/mods:publisher", xml, "publisher"); - add(jsonObject, "//modsContainer/mods:mods/mods:titleInfo/mods:subTitle", xml, "subtitle"); - add(jsonObject, "//modsContainer/mods:mods/mods:titleInfo/mods:title", xml, "title"); - add(jsonObject, "//modsContainer/mods:physicalDescription/mods:extent", xml, "numberOfPages"); + addProperty(jsonObject, "//modsContainer/mods:mods/mods:abstract", xml, "textAbstract"); + addProperty(jsonObject, "//modsContainer/mods:mods/mods:originInfo/mods:dateIssued[1]", xml, "releaseYear"); + addProperty(jsonObject, "//modsContainer/mods:mods/mods:originInfo/mods:edition", xml, "edition"); + addProperty(jsonObject, "//modsContainer/mods:mods/mods:originInfo/mods:publisher", xml, "publisher"); + addProperty(jsonObject, "//modsContainer/mods:mods/mods:titleInfo/mods:subTitle", xml, "subtitle"); + addProperty(jsonObject, "//modsContainer/mods:mods/mods:titleInfo/mods:title", xml, "title"); + addProperty(jsonObject, "//modsContainer/mods:physicalDescription/mods:extent", xml, "numberOfPages"); addCreators(jsonObject, xml); - addLanguages(jsonObject, xml); - addPublicationType(jsonObject, xml); + addQualifiedObjectID(jsonObject, "//mods:genre[@authorityURI='" + HISInOneClient.HIS_IN_ONE_BASE_URL + "']", + xml, "publicationType"); + addQualifiedObjectID(jsonObject, + "//servflag[@type='status'][@authorityURI='" + HISInOneClient.HIS_IN_ONE_BASE_URL + "']", + xml, "status"); + addQualifiedObjectIDs(jsonObject, + "//mods:language/mods:languageTerm[@authorityURI='" + HISInOneClient.HIS_IN_ONE_BASE_URL + "']", xml, + "languages"); return jsonObject; } catch (JDOMException | SAXException e) { @@ -63,38 +69,6 @@ protected JsonObject toJSON(MCRContent source) throws IOException { } } - private void addPublicationType(JsonObject jsonObject, Document xml) { - Optional.ofNullable( - XPATH_FACTORY.compile("//mods:genre[@authorityURI='" + HISInOneClient.HIS_IN_ONE_BASE_URL + "']/text()", - Filters.text(), null, MODS_NAMESPACE).evaluateFirst(xml)) - .ifPresent(genre -> { - JsonObject documentType = new JsonObject(); - documentType.addProperty("id", Integer.parseInt(genre.getText())); - jsonObject.add("publicationType", documentType); - }); - } - - private void addLanguages(JsonObject jsonObject, Document xml) { - final JsonArray languages = new JsonArray(); - - XPATH_FACTORY.compile( - "//mods:language/mods:languageTerm[@authorityURI='" + HISInOneClient.HIS_IN_ONE_BASE_URL + "']/text()", - Filters.text(), null, MODS_NAMESPACE).evaluate(xml) - .forEach(text -> { - try { - JsonObject item = new JsonObject(); - item.addProperty("id", Integer.parseInt(text.getText())); - languages.add(item); - } catch (NumberFormatException e) { - LOGGER.error(e); - } - }); - - if (languages.size() > 0) { - jsonObject.add("languages", languages); - } - } - private void addCreators(JsonObject jsonObject, Document xml) { final JsonArray creators = new JsonArray(); @@ -155,9 +129,66 @@ private void addCreators(JsonObject jsonObject, Document xml) { } } - private void add(JsonObject jsonObject, String xpath, Document xml, String name) { + private void addProperty(JsonObject jsonObject, String xpath, Document xml, String name) { XPATH_FACTORY.compile(xpath, Filters.element(), null, MODS_NAMESPACE) .evaluate(xml) .forEach(e -> jsonObject.addProperty(name, e.getText())); } + + /** + * @param jsonObject the json object + * @param xpath the xpath + * @param xml the xml + * @param propertyName the name of the property + * + *
+     *     "propertyName": [
+     *     {
+     *       "id": 5
+     *     },
+     *     {
+     *      "id
+     *     }, ...]
+     *  
+ * */ + private void addQualifiedObjectIDs(JsonObject jsonObject, String xpath, Document xml, String propertyName) { + final JsonArray jsonArray = new JsonArray(); + + XPATH_FACTORY.compile(xpath, Filters.element(), null, MODS_NAMESPACE).evaluate(xml) + .forEach(text -> { + try { + JsonObject item = new JsonObject(); + item.addProperty("id", Integer.parseInt(text.getText())); + jsonArray.add(item); + } catch (NumberFormatException e) { + LOGGER.error(e); + } + }); + + if (jsonArray.size() > 0) { + jsonObject.add(propertyName, jsonArray); + } + } + + /** + * @param jsonObject the json object + * @param xpath the xpath + * @param xml the xml + * @param propertyName the name of the property + * + *
+     *     "propertyName": {
+     *     "id": integer value determined by xpath
+     *   }
+     *  
+ * */ + private void addQualifiedObjectID(JsonObject jsonObject, String xpath, Document xml, String propertyName) { + Optional.ofNullable( + XPATH_FACTORY.compile(xpath, Filters.element(), null, MODS_NAMESPACE).evaluateFirst(xml)) + .ifPresent(genre -> { + JsonObject documentType = new JsonObject(); + documentType.addProperty("id", Integer.parseInt(genre.getText())); + jsonObject.add(propertyName, documentType); + }); + } } diff --git a/common/src/main/java/de/uni_jena/thunibib/his/xml/HISinOneResolver.java b/common/src/main/java/de/uni_jena/thunibib/his/xml/HISinOneResolver.java index ad55750fa..787ea31df 100644 --- a/common/src/main/java/de/uni_jena/thunibib/his/xml/HISinOneResolver.java +++ b/common/src/main/java/de/uni_jena/thunibib/his/xml/HISinOneResolver.java @@ -4,6 +4,7 @@ import de.uni_jena.thunibib.his.api.HISinOneClientFactory; import de.uni_jena.thunibib.his.api.v1.cs.sys.values.LanguageValue; import de.uni_jena.thunibib.his.api.v1.cs.sys.values.PublicationTypeValue; +import de.uni_jena.thunibib.his.api.v1.fs.res.state.PublicationState; import jakarta.ws.rs.core.GenericType; import jakarta.ws.rs.core.Response; import org.apache.logging.log4j.LogManager; @@ -21,7 +22,7 @@ public class HISinOneResolver implements URIResolver { public enum SUPPORTED_URI_PARTS { - language, genre + language, genre, state } private static final Logger LOGGER = LogManager.getLogger(HISinOneResolver.class); @@ -39,11 +40,35 @@ public Source resolve(String href, String base) throws TransformerException { return new JDOMSource(new Element("int").setText(String.valueOf(resolveLanguage(value)))); case genre: return new JDOMSource(new Element("int").setText(String.valueOf(resolveGenre(value)))); + case state: + return new JDOMSource(new Element("int").setText(String.valueOf(resolveState(value)))); } throw new TransformerException("Unknown entity: " + entity); } + private int resolveState(String value) { + try (HISInOneClient hisClient = HISinOneClientFactory.create(); + Response response = hisClient.get("fs/res/state/publication")) { + + List pubState = response.readEntity( + new GenericType>() { + }); + + return switch (value) { + case "confirmed", "unchecked" -> + pubState.stream().filter(state -> "validiert" .equals(state.getUniqueName())).findFirst().get() + .getId(); + case "review" -> + pubState.stream().filter(state -> "Dateneingabe" .equals(state.getUniqueName())).findFirst().get() + .getId(); + default -> + pubState.stream().filter(state -> "zur Validierung" .equals(state.getUniqueName())).findFirst() + .get().getId(); + }; + } + } + private int resolveGenre(String ubogenre) { try (HISInOneClient hisClient = HISinOneClientFactory.create(); Response response = hisClient.get("cs/sys/values/publicationTypeValue")) { @@ -60,7 +85,7 @@ private int resolveGenre(String ubogenre) { int id; if (tpv.isEmpty()) { id = pubTypeValues.stream() - .filter(pubType -> "Sonstiger Publikationstyp".equals(pubType.getUniqueName())) + .filter(pubType -> "Sonstiger Publikationstyp" .equals(pubType.getUniqueName())) .findFirst().get().getId(); } else { id = tpv.get().getId(); diff --git a/common/src/main/resources/xsl/mycoreobject-mods-resolve-his-keys.xsl b/common/src/main/resources/xsl/mycoreobject-mods-resolve-his-keys.xsl index 7bf15dd7a..4da5477d7 100644 --- a/common/src/main/resources/xsl/mycoreobject-mods-resolve-his-keys.xsl +++ b/common/src/main/resources/xsl/mycoreobject-mods-resolve-his-keys.xsl @@ -46,4 +46,20 @@ + + + + + + + + + + + + + + + +