Skip to content

Commit

Permalink
#550 Resolve publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
Possommi committed Jul 16, 2024
1 parent 7d342d1 commit 130c022
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package de.uni_jena.thunibib.his.api.v1.cs.sys.values.publisher;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.uni_jena.thunibib.his.api.v1.cs.sys.values.LanguageValue;
import de.uni_jena.thunibib.his.api.v1.cs.sys.values.SysValue;

/**
* Endpoint for <strong>searching</strong> publishers.
*
* PublisherWrappedValue
*
* Path: <code>/api/v1/fs/res/wrapped/publisher?q=</code>
* */
@JsonIgnoreProperties(ignoreUnknown = true)
public class PublisherWrappedValue extends SysValue {
@JsonProperty("_foreigntext")
String _foreigntext;

@JsonProperty("place")
String place;

@JsonProperty("label")
String label;

@JsonProperty("language")
LanguageValue language;

public String getForeignText() {
return _foreigntext;
}

public String getPlace() {
return place;
}

public String getLabel() {
return label;
}

public static String getPath() {
return "fs/res/wrapped/publisher";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ protected JsonObject toJSON(MCRContent source) throws IOException {
addProperty(jsonObject, "//mods:mods/mods:abstract", xml, "textAbstract", true);
addProperty(jsonObject, "//mods:mods/mods:originInfo/mods:dateIssued[1]", xml, "releaseYear", true);
addProperty(jsonObject, "//mods:mods/mods:originInfo/mods:edition", xml, "edition", true);
addProperty(jsonObject, "//mods:mods/mods:originInfo/mods:publisher", xml, "publisher", true);
addProperty(jsonObject, "//mods:mods/mods:titleInfo/mods:subTitle", xml, "subtitle", true);
addProperty(jsonObject, "//mods:mods/mods:titleInfo/mods:title", xml, "title", true);
addProperty(jsonObject, "//mods:mods/mods:note[not(@type='intern')]", xml, "commentary", false);

addExtent(jsonObject, xml);
addCreators(jsonObject, xml);

addQualifiedObjectID(jsonObject, "//mods:mods/mods:classification[contains(@valueURI, 'publisher')]", xml, "publisher");
addQualifiedObjectID(jsonObject, "//mods:mods/mods:classification[contains(@valueURI, 'peerReviewedValue')]", xml, "peerReviewed");
addQualifiedObjectID(jsonObject, "//mods:mods/mods:classification[contains(@valueURI, 'publicationAccessTypeValue')]", xml, "access");
addQualifiedObjectID(jsonObject, "//mods:mods/mods:classification[contains(@valueURI, 'publicationCreatorTypeValue')]", xml, "publicationCreatorType");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import de.uni_jena.thunibib.his.api.v1.cs.sys.values.SubjectAreaValue;
import de.uni_jena.thunibib.his.api.v1.cs.sys.values.SysValue;
import de.uni_jena.thunibib.his.api.v1.cs.sys.values.VisibilityValue;
import de.uni_jena.thunibib.his.api.v1.cs.sys.values.publisher.PublisherWrappedValue;
import de.uni_jena.thunibib.his.api.v1.fs.res.publication.DocumentType;
import de.uni_jena.thunibib.his.api.v1.fs.res.publication.GlobalIdentifierType;
import de.uni_jena.thunibib.his.api.v1.fs.res.state.PublicationState;
Expand All @@ -30,6 +31,8 @@
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand All @@ -49,6 +52,7 @@ public class HISinOneResolver implements URIResolver {
private static final Map<String, SysValue> DOCUMENT_TYPE_MAP = new HashMap<>();
private static final Map<String, SysValue> GENRE_TYPE_MAP = new HashMap<>();
private static final Map<String, SysValue> IDENTIFIER_TYPE_MAP = new HashMap<>();
private static final Map<String, SysValue> PUBLISHER_MAP = new HashMap<>();
private static final Map<String, SysValue> PEER_REVIEWED_TYPE_MAP = new HashMap<>();
private static final Map<String, SysValue> PUBLICATION_ACCESS_TYPE_MAP = new HashMap<>();
private static final Map<String, SysValue> RESEARCH_AREA_TYPE_MAP = new HashMap<>();
Expand All @@ -64,6 +68,7 @@ public enum SUPPORTED_URI_PARTS {
globalIdentifiers,
language,
peerReviewed,
publisher,
publicationAccessType,
researchAreaKdsf,
state,
Expand All @@ -86,6 +91,7 @@ public Source resolve(String href, String base) throws TransformerException {
case genre -> resolveGenre(value);
case globalIdentifiers -> resolveIdentifierType(value);
case language -> resolveLanguage(value);
case publisher -> resolvePublisher(value);
case peerReviewed -> resolvePeerReviewedType(value);
case publicationAccessType -> resolvePublicationAccessType(value);
case researchAreaKdsf -> resolveResearchAreaKdsf(value);
Expand All @@ -99,6 +105,39 @@ public Source resolve(String href, String base) throws TransformerException {
return new JDOMSource(new Element("int").setText(String.valueOf(sysValue.getId())));
}

private SysValue resolvePublisher(String value) {
String decodedValue = URLDecoder.decode(value, StandardCharsets.UTF_8);

if (PUBLISHER_MAP.containsKey(decodedValue)) {
return PUBLISHER_MAP.get(decodedValue);
}

Map<String, String> params = new HashMap<>();
params.put("q", decodedValue);

try (HISInOneClient hisClient = HISinOneClientFactory.create();
Response response = hisClient.get(PublisherWrappedValue.getPath(), params)) {

if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
return SysValue.NotObtainedSysValue;
}

List<PublisherWrappedValue> publishers = response.readEntity(
new GenericType<List<PublisherWrappedValue>>() {
});

List<PublisherWrappedValue> resultList = publishers.stream()
.filter(pwv -> pwv.getUniqueName().equals(decodedValue))
.toList();

SysValue r = !resultList.isEmpty() ? resultList.get(0) : SysValue.EmptySysValue;
if (r instanceof PublisherWrappedValue) {
PUBLISHER_MAP.put(decodedValue, r);
}
return r;
}
}

/**
* Resolves the his-id by the given peerreviewed category id.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<xsl:copy>
<xsl:comment>Begin - transformer 'mods-resolve-his-keys'</xsl:comment>

<!-- Publisher -->
<xsl:call-template name="publisher"/>

<!-- PeerReviewedValue -->
<xsl:call-template name="peerReviewed"/>

Expand Down Expand Up @@ -56,6 +59,17 @@
</xsl:copy>
</xsl:template>

<xsl:template name="publisher">
<xsl:if test="mods:originInfo/mods:publisher">
<xsl:variable name="publisher-text" select="fn:encode-for-uri(mods:originInfo/mods:publisher)"/>
<xsl:variable name="publisher-id" select="fn:document(concat('hisinone:publisher:', $publisher-text))"/>

<mods:classification authorityURI="{$ThUniBib.HISinOne.BaseURL}" valueURI="{$ThUniBib.HISinOne.BaseURL}{$ThUniBib.HISinOne.BaseURL.API.Path}fs/res/publisher">
<xsl:value-of select="$publisher-id"/>
</mods:classification>
</xsl:if>
</xsl:template>

<xsl:template name="peerReviewed">
<xsl:if test="mods:classification[fn:contains(@valueURI, 'peerreviewed#')]">
<xsl:variable name="categId" select="fn:substring-after(mods:classification[fn:contains(@valueURI, 'peerreviewed#')]/@valueURI, '#')"/>
Expand Down

0 comments on commit 130c022

Please sign in to comment.