Skip to content

Commit

Permalink
#550 Add his/res visibilityValue value as mods:classification
Browse files Browse the repository at this point in the history
  • Loading branch information
Possommi committed Jun 14, 2024
1 parent 00b8721 commit 95e5f12
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected JsonObject toJSON(MCRContent source) throws IOException {
addProperty(jsonObject, "//modsContainer/mods:physicalDescription/mods:extent", xml, "numberOfPages");

addCreators(jsonObject, xml);
addQualifiedObjectID(jsonObject, "//mods:classification[contains(@valueURI, '/cs/sys/values/visibilityValue')]", xml, "visibilityValue");
addQualifiedObjectID(jsonObject, "//mods:classification[contains(@valueURI, '/fs/res/state/publication')]", xml, "status");
addQualifiedObjectID(jsonObject, "//mods:genre[@authorityURI='" + HISInOneClient.HIS_IN_ONE_BASE_URL + "']", xml, "publicationType");
addQualifiedObjectIDs(jsonObject,"//mods:language/mods:languageTerm[@authorityURI='" + HISInOneClient.HIS_IN_ONE_BASE_URL + "']", xml,"languages");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.cs.sys.values.VisibilityValue;
import de.uni_jena.thunibib.his.api.v1.fs.res.state.PublicationState;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Response;
Expand All @@ -18,11 +19,14 @@
import javax.xml.transform.URIResolver;
import java.util.List;
import java.util.Optional;

/**
* Usage:<br/>
* <code>HISinOne:[language | genre | state | visibility]:[value]</code>
* */
public class HISinOneResolver implements URIResolver {

public enum SUPPORTED_URI_PARTS {
language, genre, state
language, genre, state, visibility
}

private static final Logger LOGGER = LogManager.getLogger(HISinOneResolver.class);
Expand All @@ -42,11 +46,31 @@ public Source resolve(String href, String base) throws TransformerException {
return new JDOMSource(new Element("int").setText(String.valueOf(resolveGenre(value))));
case state:
return new JDOMSource(new Element("int").setText(String.valueOf(resolveState(value))));
case visibility:
return new JDOMSource(new Element("int").setText(String.valueOf(resolveVisibility(value))));
}

throw new TransformerException("Unknown entity: " + entity);
}

private int resolveVisibility(String value) {
try (HISInOneClient hisClient = HISinOneClientFactory.create();
Response response = hisClient.get("cs/sys/values/visibilityValue")) {

List<VisibilityValue> visState = response.readEntity(
new GenericType<List<VisibilityValue>>() {
});

return switch (value) {
case "confirmed", "unchecked" ->
visState.stream().filter(state -> "public" .equals(state.getUniqueName())).findFirst().get()
.getId();
default -> visState.stream().filter(state -> "hidden" .equals(state.getUniqueName())).findFirst()
.get().getId();
};
}
}

private int resolveState(String value) {
try (HISInOneClient hisClient = HISinOneClientFactory.create();
Response response = hisClient.get("fs/res/state/publication")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<xsl:template match="mods:mods">
<xsl:copy>
<!-- add state classification element -->
<!-- Set state class -->
<xsl:variable name="status" select="//servflags/servflag[@type='status']"/>
<xsl:variable name="status-his-key" select="fn:document(concat('HISinOne:state:', $status))"/>

Expand All @@ -31,6 +31,14 @@
</mods:classification>
</xsl:if>

<!-- Set visibility class -->
<xsl:variable name="visibility-his-key" select="fn:document(concat('HISinOne:visibility:', $status))"/>
<xsl:if test="$visibility-his-key">
<mods:classification authorityURI="{$ThUniBib.HISinOne.BaseURL}" valueURI="{$ThUniBib.HISinOne.BaseURL}{$ThUniBib.HISinOne.BaseURL.API.Path}cs/sys/values/visibilityValue">
<xsl:value-of select="$visibility-his-key"/>
</mods:classification>
</xsl:if>

<!-- Retain original mods:mods -->
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
Expand Down

0 comments on commit 95e5f12

Please sign in to comment.