Skip to content

Commit

Permalink
#550 Map languages and extent
Browse files Browse the repository at this point in the history
  • Loading branch information
Possommi committed Jun 12, 2024
1 parent 2b7d506 commit ddef6d3
Showing 1 changed file with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ protected JsonObject toJSON(MCRContent source) throws IOException {
Document xml = source.asXML();
JsonObject jsonObject = new JsonObject();

add(jsonObject, "//mods:mods/mods:titleInfo/mods:title", xml, "title");
add(jsonObject, "//mods:mods/mods:titleInfo/mods:subTitle", xml, "subtitle");
add(jsonObject, "//mods:mods/mods:originInfo/mods:edition", xml, "edition");
add(jsonObject, "//mods:mods/mods:abstract", xml, "textAbstract");
add(jsonObject, "//mods:mods/mods:originInfo/mods:dateIssued[1]", xml, "releaseYear");
add(jsonObject, "//mods:mods/mods:originInfo/mods:edition", xml, "edition");
add(jsonObject, "//mods:mods/mods:originInfo/mods:publisher", xml, "publisher");
add(jsonObject, "//mods:mods/mods:abstract", xml, "textAbstract");
add(jsonObject, "//mods:mods/mods:titleInfo/mods:subTitle", xml, "subtitle");
add(jsonObject, "//mods:mods/mods:titleInfo/mods:title", xml, "title");
add(jsonObject, "//mods:physicalDescription/mods:extent", xml, "numberOfPages");

addCreators(jsonObject, xml);
addLanguages(jsonObject, xml);

return jsonObject;
} catch (JDOMException | SAXException e) {
Expand All @@ -54,13 +57,33 @@ protected JsonObject toJSON(MCRContent source) throws IOException {
}
}

private void addLanguages(JsonObject jsonObject, Document xml) {
final JsonArray languages = new JsonArray();
XPATH_FACTORY.compile("//mods:language/mods:languageTerm[@type='code']/text()", Filters.text(), null,
MODS_NAMESPACE)
.evaluate(xml)
.forEach(text -> {
JsonObject item = new JsonObject();
item.addProperty("id", "TODO-GET-ID-FROM-HIS---" + text.getText());
languages.add(item);
});

if (languages.size() > 0) {
jsonObject.add("languages", languages);
}
}

private 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)
.evaluate(xml)
.forEach(nameElement -> {
final JsonObject name = new JsonObject();

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

/* nameParts */
nameElement
.getChildren("namePart", MODS_NAMESPACE)
Expand Down

0 comments on commit ddef6d3

Please sign in to comment.