Skip to content

Commit

Permalink
#550 Map publication state, introduced abstract CommonType
Browse files Browse the repository at this point in the history
  • Loading branch information
Possommi committed Jun 13, 2024
1 parent 86ecd62 commit 016ba1f
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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: <code>/api/v1/cs/sys/values/publicationTypeValue</code>
* */
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() {
}
}
Original file line number Diff line number Diff line change
@@ -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: <code>/api/v1/fs/res/state/publication</code>
* */
public class PublicationState extends CommonType {
public PublicationState() {
}
}
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.fs.res.state.PublicationState;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Response;
import org.apache.logging.log4j.LogManager;
Expand All @@ -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);
Expand All @@ -39,11 +40,32 @@ 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<PublicationState> pubState = response.readEntity(
new GenericType<List<PublicationState>>() {
});

return switch (value) {
case "confirmed" ->
pubState.stream().filter(state -> "validiert" .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")) {
Expand All @@ -60,7 +82,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,20 @@
</xsl:if>
</xsl:copy>
</xsl:template>

<xsl:template match="//servflags/servflag[@type='status']">
<xsl:copy>
<xsl:copy-of select="*|@*"/>
</xsl:copy>

<xsl:variable name="status" select="."/>
<xsl:variable name="his-key" select="fn:document(concat('HISinOne:state:', $status))"/>

<xsl:if test="$his-key">
<servflag type="status" authorityURI="{$ThUniBib.HISinOne.BaseURL}">
<xsl:value-of select="$his-key"/>
</servflag>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 016ba1f

Please sign in to comment.