Skip to content

Commit

Permalink
preserve all identifiers in ssoar metadata (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolandka committed Aug 24, 2016
1 parent da96498 commit 2f204ec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>infolis</groupId>
<artifactId>metaDataTransformer</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
Expand Down Expand Up @@ -47,4 +47,4 @@
</dependency>
</dependencies>
<name>metaDataTransformer</name>
</project>
</project>
35 changes: 28 additions & 7 deletions src/main/java/infolis/metaDataTransformer/output/OutputWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class OutputWriter {

String lang = null, abstractDesc = null, title = null, identifier = null, uri = null;
List<String> authors = new ArrayList<>(), subjects = new ArrayList<>();
List<String> authors = new ArrayList<>(), subjects = new ArrayList<>(), identifiers = new ArrayList<>();
String outputPath = null, fileName = null;

public OutputWriter(String lang, String abstractDesc, String title, String identifier, String uri, List<String> authors, List<String> subjects, String outputPath, String fileName) {
Expand All @@ -36,6 +36,17 @@ public OutputWriter(String lang, String abstractDesc, String title, String ident
this.outputPath = outputPath;
this.fileName = fileName;
}

public OutputWriter(String lang, String abstractDesc, String title, List<String> identifiers, List<String> authors, List<String> subjects, String outputPath, String fileName) {
this.lang = lang;
this.abstractDesc = abstractDesc;
this.title = title;
this.identifiers = identifiers;
this.authors = authors;
this.subjects = subjects;
this.outputPath = outputPath;
this.fileName = fileName;
}

public void writeOutput() {
DocumentBuilderFactory icFactory = DocumentBuilderFactory.newInstance();
Expand All @@ -50,9 +61,11 @@ public void writeOutput() {
node.appendChild(header);

// append child elements to root element
Element identifierEle = docOut.createElement("identifier");
identifierEle.setTextContent(identifier);
header.appendChild(identifierEle);
if (null != identifier) {
Element identifierEle = docOut.createElement("identifier");
identifierEle.setTextContent(identifier);
header.appendChild(identifierEle);
}

Element metadata = docOut.createElement("metadata");
node.appendChild(metadata);
Expand All @@ -72,9 +85,17 @@ public void writeOutput() {
langEle.setTextContent(lang);
ns1.appendChild(langEle);

Element uriEle = docOut.createElement("dc:identifier");
uriEle.setTextContent(uri);
ns1.appendChild(uriEle);
if (null != uri) {
Element uriEle = docOut.createElement("dc:identifier");
uriEle.setTextContent(uri);
ns1.appendChild(uriEle);
}

for (String id : identifiers) {
Element idEle = docOut.createElement("dc:identifier");
idEle.setTextContent(id);
ns1.appendChild(idEle);
}

Element absEle = docOut.createElement("dc:description");
absEle.setTextContent(abstractDesc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public static void main(String args[]) throws ParserConfigurationException, SAXE
File inDir = new File(inputPath);
for (File f : inDir.listFiles()) {

String lang = null, abstractDesc = null, title = null, identifier = null, uri = null;
List<String> authors = new ArrayList<>(), subjects = new ArrayList<>();
String lang = null, abstractDesc = null, title = null;
List<String> authors = new ArrayList<>(), subjects = new ArrayList<>(),
identifiers = new ArrayList<>();

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Expand All @@ -46,7 +47,7 @@ public static void main(String args[]) throws ParserConfigurationException, SAXE
NodeList fieldNodesHeader = doc.getElementsByTagName("ns0:identifier");
for (int j = 0; j < fieldNodesHeader.getLength(); j++) {
Node fieldNode = fieldNodesHeader.item(j);
identifier = fieldNode.getTextContent();
identifiers.add(fieldNode.getTextContent());
}

NodeList fieldNodesBegin = doc.getElementsByTagName("ns1:dcvalue");
Expand Down Expand Up @@ -85,13 +86,13 @@ public static void main(String args[]) throws ParserConfigurationException, SAXE
if (element.getTextContent().equals("title") && language != null && language.getTextContent().equals(lang) && qualifier ==null) {
title = fieldNode.getTextContent();
}
if (element.getTextContent().equals("identifier") && qualifier != null && qualifier.getTextContent().equals("uri")) {
uri = fieldNode.getTextContent();
if (element.getTextContent().equals("identifier")) {
identifiers.add(fieldNode.getTextContent());
}
}
}

OutputWriter writer = new OutputWriter(lang, abstractDesc, title, identifier, uri, authors, subjects, outputPath, f.getName());
OutputWriter writer = new OutputWriter(lang, abstractDesc, title, identifiers, authors, subjects, outputPath, f.getName());
writer.writeOutput();

}
Expand Down

0 comments on commit 2f204ec

Please sign in to comment.