Skip to content

Commit

Permalink
#550 Updated addCreators(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
Possommi committed Dec 13, 2024
1 parent 2e86c8c commit 5e33401
Showing 1 changed file with 12 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import de.uni_jena.thunibib.his.api.v1.cs.psv.PersonIdentifier;
import de.uni_jena.thunibib.his.xml.HISInOneServiceFlag;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -10,6 +11,7 @@
import org.jdom2.JDOMException;
import org.jdom2.Namespace;
import org.jdom2.filter.Filters;
import org.jdom2.xpath.XPathExpression;
import org.mycore.common.MCRConstants;
import org.mycore.common.content.MCRContent;
import org.mycore.common.content.transformer.MCRToJSONTransformer;
Expand All @@ -18,6 +20,7 @@
import java.util.List;
import java.util.Optional;

import static de.uni_jena.thunibib.his.api.client.HISInOneClient.API_PATH;
import static de.uni_jena.thunibib.his.api.client.HISInOneClient.HIS_IN_ONE_BASE_URL;
import static org.mycore.common.MCRConstants.MODS_NAMESPACE;
import static org.mycore.common.MCRConstants.XPATH_FACTORY;
Expand Down Expand Up @@ -61,10 +64,8 @@ protected JsonObject toJSON(MCRContent source) throws IOException {
addProperty(jsonObject, "//mods:mods/mods:part/mods:detail[@type='volume']/mods:number", xml, "volume", true);

addExtent(jsonObject, xml);
addSampleCreator(jsonObject);
/** TODO: Remove comments in production
addCreators(jsonObject, xml);
*/
addCreators(jsonObject, xml);

addQualifiedObjectID(jsonObject, "//mods:mods/mods:classification[contains(@valueURI, 'publicationResourceValue')]", xml,"publicationResource");
addQualifiedObjectID(jsonObject, "//mods:mods/mods:classification[contains(@valueURI, 'publisher')]", xml,"publisher");
addQualifiedObjectID(jsonObject, "//mods:mods/mods:classification[contains(@valueURI, 'peerReviewedValue')]", xml, "peerReviewedProcess");
Expand Down Expand Up @@ -171,14 +172,17 @@ protected void addSampleCreator(JsonObject jsonObject) {
protected void addCreators(JsonObject jsonObject, Document xml) {
final JsonArray creators = new JsonArray();

XPATH_FACTORY.compile("//mods:mods/mods:name[@type='personal']", Filters.element(), null, MODS_NAMESPACE)
String tCond = "mods:nameIdentifier[contains(@typeURI, '" + HIS_IN_ONE_BASE_URL + API_PATH
+ PersonIdentifier.getPath() + "')]";

XPATH_FACTORY
.compile("//mods:mods/mods:name[@type='personal'][" + tCond + "]", Filters.element(), null, MODS_NAMESPACE)
.evaluate(xml)
.forEach(nameElement -> {
final JsonObject name = new JsonObject();

/* id of person in HISinOne */
name.addProperty("id", "TODO-GET-ID-FROM-HIS");

XPathExpression<Element> idExpr = XPATH_FACTORY.compile(tCond, Filters.element(), null, MODS_NAMESPACE);
name.addProperty("id", idExpr.evaluateFirst(nameElement).getText());
/* nameParts */
nameElement
.getChildren("namePart", MODS_NAMESPACE)
Expand All @@ -190,36 +194,6 @@ protected void addCreators(JsonObject jsonObject, Document xml) {
};
name.addProperty(typeOfName, namePart.getText());
});

/* nameIdentifiers */
final JsonArray personIdentifiers = new JsonArray();
nameElement.
getChildren("nameIdentifier", MODS_NAMESPACE)
.stream()
.filter(identifierElement -> identifierElement.getAttributeValue("type") != null)
.forEach(identifierElement -> {
JsonObject identifier = new JsonObject();
JsonObject identifierType = new JsonObject();

identifier.addProperty("identifier", identifierElement.getText());
identifier.add("identifierType", identifierType);

identifierType.addProperty("id", identifierElement.getAttributeValue("type"));
personIdentifiers.add(identifier);
});
name.add("personIdentifiers", personIdentifiers);

/* affiliations */
nameElement.getChildren("affiliation", MODS_NAMESPACE)
.stream()
.findFirst()
.ifPresent(affElement -> {
JsonArray affiliations = new JsonArray();
JsonObject affiliation = new JsonObject();
affiliation.addProperty("defaulttext", affElement.getText());
affiliations.add(affiliation);
name.add("affiliations", affiliations);
});
creators.add(name);
});

Expand Down

0 comments on commit 5e33401

Please sign in to comment.