Skip to content

Commit

Permalink
#550 Added Response post(String path, String body, Map<String, String…
Browse files Browse the repository at this point in the history
…> params) to HISInOneClient interface
  • Loading branch information
Possommi committed Nov 4, 2024
1 parent 64acd5d commit d2a1f72
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ default Response get(String path, Map<String, String> params) {
return get(path, params, false);
}

default Response get(String path, boolean omitToken){
default Response get(String path, boolean omitToken) {
return get(path, null, omitToken);
}

default Response post(String path, String body) {
return post(path, body, null);
}

Response get(String path, Map<String, String> params, boolean omitToken);

Response post(String path, String body);
Response post(String path, String body, Map<String, String> params);

Response put(String path, String body);
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ public Response get(String path, Map<String, String> parameters, boolean omitTok
}

@Override
public Response post(String path, String bodySource) {
public Response post(String path, String bodySource, Map<String, String> parameters) {
WebTarget webTarget = getJerseyClient()
.target(HISInOneClientDefaultImpl.HIS_IN_ONE_BASE_URL + API_PATH)
.path(path);

if (parameters != null) {
for (Map.Entry<String, String> entry : parameters.entrySet()) {
webTarget = webTarget.queryParam(entry.getKey(), entry.getValue());
}
}

Token token;
try {
token = fetchToken();
Expand All @@ -85,6 +91,7 @@ public Response post(String path, String bodySource) {
invocationBuilder.header("Authorization", getAuthorizationHeaderValue(AuthType.Bearer, token.getAccessToken()));

Entity<String> body = Entity.entity(bodySource, MediaType.APPLICATION_JSON);

Response response = invocationBuilder.post(body);

return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.logging.log4j.Logger;
import org.jdom2.Element;
import org.jdom2.transform.JDOMSource;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.datamodel.classifications2.MCRCategory;
import org.mycore.datamodel.classifications2.MCRCategoryDAOFactory;
import org.mycore.datamodel.classifications2.MCRCategoryID;
Expand Down Expand Up @@ -56,7 +55,7 @@
*
* Usage
* <p>
* <code>hisinone:&lt;resolve|create&gt;:&lt;[requested field]&gt;:&lt;creatorType|documentType|journal|publication|publicationAccessType|publicationResource|publicationType|globalIdentifiers|language|peerReviewed|publisher|researchAreaKdsf|subjectArea|state|thesisType|visibility&gt;:[value]</code>
* <code>hisinone:&lt;resolve|create&gt;:&lt;[requested field]&gt;:&lt;creatorType|documentType|journal|publication|publicationAccessType|publicationResource|publicationType|globalIdentifiers|language|peerReviewed|person|publisher|researchAreaKdsf|subjectArea|state|thesisType|visibility&gt;:[value]</code>
* </p>
*
* Note
Expand All @@ -68,8 +67,6 @@
* */
public class HISinOneResolver implements URIResolver {
private static final Logger LOGGER = LogManager.getLogger(HISinOneResolver.class);
private static final String JOURNAL_TRANSFORMER = MCRConfiguration2.getStringOrThrow(
"ThUniBib.HISinOne.Journal.Transformer.Name");

private static final Map<String, LanguageValue> LANGUAGE_TYPE_MAP = new HashMap<>();
private static final Map<String, SysValue> CREATOR_TYPE_MAP = new HashMap<>();
Expand Down Expand Up @@ -97,6 +94,7 @@ public enum ResolvableTypes {
journal,
language,
peerReviewed,
person,
publication,
publicationAccessType,
publicationResource,
Expand Down Expand Up @@ -126,6 +124,11 @@ public Source resolve(String href, String base) throws TransformerException {
hostGenre = parts[5];
}

String idValue = null;
if (ResolvableTypes.person.name().equals(entity)) {
idValue = parts[5];
}

fromValue = parts.length > 4 ? URLDecoder.decode(parts[4], StandardCharsets.UTF_8) : "";

var sysValue = switch (ResolvableTypes.valueOf(entity)) {
Expand All @@ -135,6 +138,7 @@ public Source resolve(String href, String base) throws TransformerException {
case journal -> Mode.resolve.equals(mode) ? resolveJournal(fromValue) : createParent(fromValue);
case language -> resolveLanguage(fromValue);
case peerReviewed -> resolvePeerReviewedType(fromValue);
case person -> resolvePerson(fromValue, idValue);
case publication -> Mode.resolve.equals(mode) ? resolvePublication(fromValue) : createParent(fromValue);
case publicationAccessType -> resolvePublicationAccessType(fromValue);
case publicationResource -> resolvePublicationResourceType(fromValue);
Expand All @@ -152,6 +156,18 @@ public Source resolve(String href, String base) throws TransformerException {
return new JDOMSource(new Element("int").setText(String.valueOf(getFieldValue(sysValue, field))));
}

/**
* Resolves a person by a given identifier and the type of the identifier.
*
* @param type the type of the identifier
* @param value the value of the identifier
*
* @return {@link SysValue}
*/
protected SysValue resolvePerson(String type, String value) {
return SysValue.UnresolvedSysValue;
}

protected SysValue resolveJournal(String fromValue) {
if (!exists(fromValue)) {
return SysValue.UnresolvedSysValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ MCR.ContentTransformer.mods-create-his-keys.Class
MCR.ContentTransformer.mods-create-his-keys.TransformerFactoryClass = net.sf.saxon.TransformerFactoryImpl
MCR.ContentTransformer.mods-create-his-keys.Stylesheet = xsl/mycoreobject-mods-create-unresolved-his-keys.xsl

# This transformer enriches the MODS with lead_id, resolves his keys and creates missing his keys
MCR.ContentTransformer.mods-resolve-create-his-keys.Class = org.mycore.common.content.transformer.MCRTransformerPipe
MCR.ContentTransformer.mods-resolve-create-his-keys.Steps = mods-xml-detailed,mods-resolve-his-keys,mods-create-his-keys

# Transformer for converting Publication to json format used by HISinOne
MCR.ContentTransformer.res-publication-json.Class = de.uni_jena.thunibib.his.content.transformer.PublicationHisResTransformer
MCR.ContentTransformer.res-publication-json-detailed.Class = org.mycore.common.content.transformer.MCRTransformerPipe
Expand All @@ -183,9 +187,5 @@ MCR.ContentTransformer.res-journal-json.Class
MCR.ContentTransformer.res-json-journal-base.Class = org.mycore.common.content.transformer.MCRTransformerPipe
MCR.ContentTransformer.res-json-journal-base.Steps = mods-xml-detailed,mods-resolve-his-keys,mods-create-his-keys,res-journal-json

# This transformer enriches the MODS with lead_id, resolves his keys and creates missing his keys
MCR.ContentTransformer.mods-resolve-create-his-keys.Class = org.mycore.common.content.transformer.MCRTransformerPipe
MCR.ContentTransformer.mods-resolve-create-his-keys.Steps = mods-xml-detailed,mods-resolve-his-keys,mods-create-his-keys

MCR.URIResolver.ModuleResolver.hisinone = de.uni_jena.thunibib.his.xml.HISinOneResolver
MCR.Jersey.Resource.Packages = %MCR.Jersey.Resource.Packages%,de.uni_jena.thunibib.his.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

<xsl:template match="mods:mods">
<xsl:copy>
<xsl:comment>Begin - transformer 'mods-create-unresolved-his-keys'</xsl:comment>

<!-- TODO Check user role -->
<xsl:apply-templates select="mods:classification[@authorityURI = $ThUniBib.HISinOne.BaseURL][text() = '-1']" mode="create"/>
<xsl:apply-templates select="mods:relatedItem[@otherTypeAuth = $ThUniBib.HISinOne.BaseURL][text() = '-1']" mode="create"/>
Expand All @@ -37,6 +35,7 @@

<!-- Create unresolved host -->
<xsl:template match="mods:relatedItem[@xlink:href][@otherType='host'][@otherTypeAuth = $ThUniBib.HISinOne.BaseURL][@otherTypeAuthURI][1]" mode="create">
<xsl:comment>Begin - transformer 'xsl/mods-create-unresolved-his-keys.xsl'</xsl:comment>

<xsl:variable name="host" select="@xlink:href"/>
<xsl:variable name="host-genre" select="fn:substring-after(@otherTypeAuthURI, '/fs/res/')"/>
Expand All @@ -60,10 +59,13 @@
<xsl:value-of select="$host-his-id"/>
</mods:relatedItem>
</xsl:if>

<xsl:comment>End - transformer 'xsl/mods-create-unresolved-his-keys.xsl'</xsl:comment>
</xsl:template>

<!-- Create unresolved publisher -->
<xsl:template mode="create" match="mods:classification[fn:contains(@valueURI, 'fs/res/publisher') and @authorityURI = $ThUniBib.HISinOne.BaseURL]">
<xsl:comment>Begin - transformer 'xsl/mods-create-unresolved-his-keys.xsl'</xsl:comment>

<xsl:variable name="publisher-text" select="fn:encode-for-uri(../mods:originInfo/mods:publisher)"/>
<xsl:variable name="publisher-id" select="fn:document(concat('hisinone:create:id:publisher:', $publisher-text))"/>
Expand All @@ -72,9 +74,9 @@
<xsl:copy-of select="@*"/>
<xsl:value-of select="$publisher-id"/>
</mods:classification>
<xsl:comment>End - transformer 'xsl/mods-create-unresolved-his-keys.xsl'</xsl:comment>
</xsl:template>

<!-- Remove all elements with unresolved values -->
<xsl:template match="node()[text() = '-1']"/>

</xsl:stylesheet>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<xsl:output method="xml" indent="yes"/>

<xsl:param name="MCR.user2.matching.lead_id"/>
<xsl:param name="ThUniBib.HISinOne.BaseURL"/>
<xsl:param name="ThUniBib.HISinOne.BaseURL.API.Path"/>
<xsl:param name="WebApplicationBaseURL"/>
Expand All @@ -25,7 +26,7 @@

<xsl:template match="mods:mods">
<xsl:copy>
<xsl:comment>Begin - transformer 'mods-resolve-his-keys'</xsl:comment>
<xsl:comment>Begin - transformer 'xsl/mods-resolve-his-keys.xsl'</xsl:comment>

<!-- Resolve the related item (HIS -> Journal, Übergeordnete Publikation)-->
<xsl:call-template name="related-item-host"/>
Expand Down Expand Up @@ -60,12 +61,38 @@
<!-- Map identifiers like doi, urn, ... -->
<xsl:call-template name="globalIdentifiers"/>

<xsl:comment>End - transformer 'mods-resolve-his-keys'</xsl:comment>
<xsl:comment>End - transformer 'xsl/mods-resolve-his-keys.xsl'</xsl:comment>
<!-- Retain original mods:mods -->
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="mods:name[@type='personal']">
<xsl:variable name="his-id">
<xsl:choose>
<xsl:when test="mods:nameIdentifier[@type = $MCR.user2.matching.lead_id]">
<xsl:value-of select="fn:document(concat('hisinone:resolve:id:person:', $MCR.user2.matching.lead_id, ':', mods:nameIdentifier[@type = $MCR.user2.matching.lead_id][1]/text()))"/>
</xsl:when>
<xsl:when test="mods:nameIdentifier[@type = 'orcid']">
<xsl:value-of select="fn:document(concat('hisinone:resolve:id:person:orcid:', mods:nameIdentifier[@type = 'orcid'][1]/text()))"/>
</xsl:when>
</xsl:choose>
</xsl:variable>

<xsl:copy>
<xsl:copy-of select="*|@*"/>
<xsl:if test="string-length($his-id) &gt; 0">
<xsl:comment>Begin - transformer 'xsl/mods-resolve-his-keys.xsl'</xsl:comment>

<mods:nameIdentifier typeURI="{$ThUniBib.HISinOne.BaseURL}{$ThUniBib.HISinOne.BaseURL.API.Path}cs/psv/person/identifier">
<xsl:value-of select="$his-id"/>
</mods:nameIdentifier>

<xsl:comment>End - transformer 'xsl/mods-resolve-his-keys.xsl'</xsl:comment>
</xsl:if>
</xsl:copy>
</xsl:template>

<xsl:template name="related-item-host">
<xsl:variable name="host" select="mods:relatedItem[@type = 'host']/@xlink:href"/>
<xsl:variable name="host-genre" select="mods:relatedItem[@type = 'host']/mods:genre[@type='intern']/fn:substring-after(@valueURI, '#')"/>
Expand Down Expand Up @@ -243,10 +270,9 @@
<xsl:copy-of select="*|@*"/>
</xsl:copy>

<xsl:comment>Begin - transformer 'mods-resolve-his-keys'</xsl:comment>
<xsl:comment>Begin - transformer 'xsl/mods-resolve-his-keys.xsl'</xsl:comment>

<!-- publicationTypeValue -->

<xsl:variable name="related-item-genre">
<xsl:choose>
<xsl:when test="string-length(substring-after(../mods:relatedItem[@type]/mods:genre/@valueURI, '#')) &gt; 0">
Expand Down Expand Up @@ -284,7 +310,7 @@
</mods:genre>
</xsl:if>

<xsl:comment>End - transformer 'mods-resolve-his-keys'</xsl:comment>
<xsl:comment>End - transformer 'xsl/mods-resolve-his-keys.xsl'</xsl:comment>
</xsl:template>

<xsl:template match="mods:language">
Expand All @@ -295,13 +321,13 @@
<xsl:variable name="his-key" select="fn:document(concat('hisinone:resolve:id:language:', $rfc5646))"/>

<xsl:if test="$his-key">
<xsl:comment>Begin - transformer 'mods-resolve-his-keys'</xsl:comment>
<xsl:comment>Begin - transformer 'xsl/mods-resolve-his-keys.xsl'</xsl:comment>

<mods:languageTerm authorityURI="{$ThUniBib.HISinOne.BaseURL}" type="code">
<xsl:value-of select="$his-key"/>
</mods:languageTerm>

<xsl:comment>End - transformer 'mods-resolve-his-keys'</xsl:comment>
<xsl:comment>End - transformer 'xsl/mods-resolve-his-keys.xsl'</xsl:comment>
</xsl:if>
</xsl:copy>
</xsl:template>
Expand Down

0 comments on commit d2a1f72

Please sign in to comment.