Skip to content

Commit

Permalink
#550 Added class PublicationHisResTransformer and configured transfor…
Browse files Browse the repository at this point in the history
…mer res-json-detailed

Configured transformer res-json-detailed
  • Loading branch information
Possommi committed Jun 12, 2024
1 parent 65a8d52 commit 2b7d506
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 15 deletions.
7 changes: 5 additions & 2 deletions common/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -21,6 +20,10 @@
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
</dependency>
<dependency>
<groupId>org.mycore</groupId>
<artifactId>mycore-base</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* This file is part of *** M y C o R e ***
* See http://www.mycore.de/ for details.
*
* MyCoRe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyCoRe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>.
*/

package de.uni_jena.thunibib.common.content.transformer;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.filter.Filters;
import org.mycore.common.content.MCRContent;
import org.mycore.common.content.transformer.MCRToJSONTransformer;
import org.xml.sax.SAXException;

import java.io.IOException;

import static org.mycore.common.MCRConstants.MODS_NAMESPACE;
import static org.mycore.common.MCRConstants.XPATH_FACTORY;

public class PublicationHisResTransformer extends MCRToJSONTransformer {

protected JsonObject toJSON(MCRContent source) throws IOException {
try {
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:originInfo/mods:dateIssued[1]", xml, "releaseYear");
add(jsonObject, "//mods:mods/mods:originInfo/mods:publisher", xml, "publisher");
add(jsonObject, "//mods:mods/mods:abstract", xml, "textAbstract");
addCreators(jsonObject, xml);

return jsonObject;
} catch (JDOMException | SAXException e) {
throw new IOException(
"Could not generate JSON from " + source.getClass().getSimpleName() + ": " + source.getSystemId(), e);
}
}

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();
/* nameParts */
nameElement
.getChildren("namePart", MODS_NAMESPACE)
.forEach(namePart -> {
var typeOfName = switch (namePart.getAttributeValue("type")) {
case "given" -> "firstname";
case "family" -> "creatorname";
default -> "unknown";
};
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);
});

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

private void add(JsonObject jsonObject, String xpath, Document xml, String name) {
XPATH_FACTORY.compile(xpath, Filters.element(), null, MODS_NAMESPACE)
.evaluate(xml)
.forEach(e -> jsonObject.addProperty(name, e.getText()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ MCR.ContentTransformer.import.DBTList.Steps = import.DBTId
MCR.ContentTransformer.import.DBTList.Filter = supportedmods
MCR.ContentTransformer.import.DBTList2MCRObj.Class = org.mycore.common.content.transformer.MCRXSLTransformer
MCR.ContentTransformer.import.DBTList2MCRObj.Stylesheet = xsl/import/dbt2mods-genre2uri.xsl,xsl/import-mods2mycoreobject.xsl

MCR.ContentTransformer.res-json.Class = de.uni_jena.thunibib.common.content.transformer.PublicationHisResTransformer
MCR.ContentTransformer.res-json-detailed.Class = org.mycore.common.content.transformer.MCRTransformerPipe
MCR.ContentTransformer.res-json-detailed.Steps = mods-xml-detailed,res-json
3 changes: 1 addition & 2 deletions jena-thulb/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down
49 changes: 38 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.mycore</groupId>
<artifactId>mycore-parent</artifactId>
<version>49</version>
<relativePath/>
<relativePath />
</parent>
<groupId>de.uni-jena.thulb.ubo</groupId>
<artifactId>ThUniBib</artifactId>
Expand All @@ -19,6 +18,7 @@

<properties>
<jakarta.servlet-api.version>6.0.0</jakarta.servlet-api.version>
<jdom.version>2.0.6.1</jdom.version>
<mycore.version>2022.06.3-SNAPSHOT</mycore.version>
<oaipmh.version>2.1</oaipmh.version>
<solr.version>8.11.3</solr.version>
Expand All @@ -41,6 +41,28 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>com.github.ekryd.sortpom</groupId>
<artifactId>sortpom-maven-plugin</artifactId>
<executions>
<execution>
<id>verify-sort-pom</id>
<goals>
<goal>sort</goal>
</goals>
<phase>validate</phase>
<configuration>
<createBackupFile>false</createBackupFile>
<expandEmptyElements>false</expandEmptyElements>
<spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement>
<keepBlankLines>true</keepBlankLines>
<sortDependencies>${sortpom.sortDeps}</sortDependencies>
<sortOrderFile>${sortpom.sortFile}</sortOrderFile>
<sortProperties>true</sortProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -88,6 +110,11 @@
<artifactId>solr-solrj</artifactId>
<version>${solr.version}</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>${jdom.version}</version>
</dependency>
<dependency>
<groupId>org.mycore</groupId>
<artifactId>mycore-base</artifactId>
Expand All @@ -100,23 +127,23 @@
</dependency>
<dependency>
<groupId>org.mycore</groupId>
<artifactId>oaipmh-harvester</artifactId>
<version>${oaipmh.version}</version>
<artifactId>mycore-orcid</artifactId>
<version>${mycore.version}</version>
</dependency>
<dependency>
<groupId>org.mycore</groupId>
<artifactId>oaipmh</artifactId>
<version>${oaipmh.version}</version>
<artifactId>mycore-user2</artifactId>
<version>${mycore.version}</version>
</dependency>
<dependency>
<groupId>org.mycore</groupId>
<artifactId>mycore-orcid</artifactId>
<version>${mycore.version}</version>
<artifactId>oaipmh</artifactId>
<version>${oaipmh.version}</version>
</dependency>
<dependency>
<groupId>org.mycore</groupId>
<artifactId>mycore-user2</artifactId>
<version>${mycore.version}</version>
<artifactId>oaipmh-harvester</artifactId>
<version>${oaipmh.version}</version>
</dependency>
<dependency>
<groupId>org.mycore.ubo</groupId>
Expand Down

0 comments on commit 2b7d506

Please sign in to comment.