Skip to content

Commit

Permalink
issue IQSS#5277: first implementation step for exporting related publ…
Browse files Browse the repository at this point in the history
…ication to DataCite
  • Loading branch information
pkiraly committed Jan 20, 2022
1 parent 40c6f30 commit 7c4ccf3
Showing 1 changed file with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -23,6 +24,8 @@
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
Expand Down Expand Up @@ -540,34 +543,63 @@ public String generateXML(DvObject dvObject) {
private String generateRelatedIdentifiers(DvObject dvObject) {

StringBuilder sb = new StringBuilder();
List<String> relatedIdentifiers = new ArrayList<>();
if (dvObject.isInstanceofDataset()) {
Dataset dataset = (Dataset) dvObject;
for (DatasetField field : dataset.getLatestVersion().getDatasetFields()) {
if (field.getDatasetFieldType().getName().equals("publication")) {
for (DatasetFieldCompoundValue compoundValue : field.getDatasetFieldCompoundValues()) {
String publicationCitation = null;
String publicationIDType = null;
String publicationIDNumber = null;
String publicationURL = null;
for (DatasetField child : compoundValue.getChildDatasetFields()) {
switch (child.getDatasetFieldType().getName()) {
case "publicationCitation": publicationCitation = child.getValue(); break;
case "publicationIDType": publicationIDType = child.getValue(); break;
case "publicationIDNumber": publicationIDNumber = child.getValue(); break;
case "publicationURL": publicationURL = child.getValue(); break;
default: break;
}
}
if (StringUtils.isNotBlank(publicationIDType) && StringUtils.isNotBlank(publicationIDNumber)) {
relatedIdentifiers.add(serializeIdenifier(publicationIDType, "Cites", publicationIDNumber));
}
}
}
}
if (!dataset.getFiles().isEmpty() && !(dataset.getFiles().get(0).getIdentifier() == null)) {

datafileIdentifiers = new ArrayList<>();
for (DataFile dataFile : dataset.getFiles()) {
if (!dataFile.getGlobalId().asString().isEmpty()) {
if (sb.toString().isEmpty()) {
sb.append("<relatedIdentifiers>");
}
sb.append("<relatedIdentifier relatedIdentifierType=\"DOI\" relationType=\"HasPart\">" + dataFile.getGlobalId() + "</relatedIdentifier>");
relatedIdentifiers.add(serializeIdenifier("DOI", "HasPart", dataFile.getGlobalId().toString()));
}
}

if (!sb.toString().isEmpty()) {
sb.append("</relatedIdentifiers>");
}
}
} else if (dvObject.isInstanceofDataFile()) {
DataFile df = (DataFile) dvObject;
relatedIdentifiers.add(serializeIdenifier("DOI", "IsPartOf", df.getOwner().getGlobalId().toString()));
}

if (!relatedIdentifiers.isEmpty()) {
sb.append("<relatedIdentifiers>");
sb.append("<relatedIdentifier relatedIdentifierType=\"DOI\" relationType=\"IsPartOf\""
+ ">" + df.getOwner().getGlobalId() + "</relatedIdentifier>");
sb.append(StringUtils.join(relatedIdentifiers, "\n"));
sb.append("</relatedIdentifiers>");
}
return sb.toString();
}

private String serializeIdenifier(String schema, String relation, String identifier) {
if (!schema.toUpperCase().equals("DOI"))
identifier = schema.toLowerCase() + ":" + identifier;
return String.format(
"<relatedIdentifier relatedIdentifierType=\"%s\" relationType=\"%s\">%s</relatedIdentifier>",
schema.toUpperCase(), relation, identifier
);
}

public void generateFileIdentifiers(DvObject dvObject) {

if (dvObject.isInstanceofDataset()) {
Expand Down

0 comments on commit 7c4ccf3

Please sign in to comment.