Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #5277: first implementation step for exporting related publicat… #8357

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, "IsCitedBy", 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