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

5559 data cite pass proper code for missing data #5676

Merged
merged 7 commits into from
Mar 25, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,28 @@ protected Map<String, String> getUpdateMetadata(DvObject dvObjectIn) {
protected Map<String, String> addBasicMetadata(DvObject dvObjectIn, Map<String, String> metadata) {

String authorString = dvObjectIn.getAuthorString();

if (authorString.isEmpty()) {
if (authorString.isEmpty() || authorString.contains(DatasetField.NA_VALUE)) {
authorString = ":unav";
}

String producerString = dataverseService.findRootDataverse().getName();

if (producerString.isEmpty()) {
if (producerString.isEmpty() || producerString.equals(DatasetField.NA_VALUE)) {
producerString = ":unav";
}


String titleString = dvObjectIn.getCurrentName();

if (titleString.isEmpty() || titleString.equals(DatasetField.NA_VALUE)) {
titleString = ":unav";
}

metadata.put("datacite.creator", authorString);
metadata.put("datacite.title", dvObjectIn.getCurrentName());
metadata.put("datacite.title", titleString);
metadata.put("datacite.publisher", producerString);
metadata.put("datacite.publicationyear", generateYear(dvObjectIn));
metadata.put("datacite.publicationyear", generateYear(dvObjectIn));
return metadata;
}
}

protected String getTargetUrl(DvObject dvObjectIn) {
logger.log(Level.FINE,"getTargetUrl");
Expand Down Expand Up @@ -418,7 +423,7 @@ public String getMetadataFromDvObject(String identifier, Map<String, String> met
metadataTemplate.setProducers(dataset.getLatestVersion().getDatasetProducers());
metadataTemplate.setTitle(dvObject.getCurrentName());
String producerString = dataverseService.findRootDataverse().getName();
if (producerString.isEmpty()) {
if (producerString.isEmpty() || producerString.equals(DatasetField.NA_VALUE) ) {
producerString = ":unav";
}
metadataTemplate.setPublisher(producerString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,18 @@ public static String getMetadataFromDvObject(String identifier, Map<String, Stri
metadataTemplate.setCreators(Util.getListFromStr(metadata.get("datacite.creator")));
metadataTemplate.setAuthors(dataset.getLatestVersion().getDatasetAuthors());
if (dvObject.isInstanceofDataset()) {
metadataTemplate.setDescription(dataset.getLatestVersion().getDescriptionPlainText());
String description = dataset.getLatestVersion().getDescriptionPlainText();
if (description.isEmpty() || description.equals(DatasetField.NA_VALUE)) {
description = ":unav";
}
metadataTemplate.setDescription(description);
}
if (dvObject.isInstanceofDataFile()) {
DataFile df = (DataFile) dvObject;
//Note: File metadata is not escaped like dataset metadata is, so adding an xml escape here.
//This could/should be removed if the datafile methods add escaping
String fileDescription = StringEscapeUtils.escapeXml(df.getDescription());
metadataTemplate.setDescription(fileDescription == null ? "" : fileDescription);
metadataTemplate.setDescription(fileDescription == null ? ":unav" : fileDescription);
String datasetPid = df.getOwner().getGlobalId().asString();
metadataTemplate.setDatasetIdentifier(datasetPid);
} else {
Expand All @@ -167,9 +171,14 @@ public static String getMetadataFromDvObject(String identifier, Map<String, Stri
//Note file title is not currently escaped the way the dataset title is, so adding it here.
title = StringEscapeUtils.escapeXml(title);
}

if (title.isEmpty() || title.equals(DatasetField.NA_VALUE)) {
title = ":unav";
}

metadataTemplate.setTitle(title);
String producerString = dataset.getLatestVersion().getRootDataverseNameforCitation();
if (producerString.isEmpty()) {
if (producerString.isEmpty() || producerString.equals(DatasetField.NA_VALUE)) {
producerString = ":unav";
}
metadataTemplate.setPublisher(producerString);
Expand Down Expand Up @@ -410,28 +419,34 @@ public String generateXML(DvObject dvObject) {
.replace("${publisherYear}", publisherYearFinal)
.replace("${description}", this.description);
StringBuilder creatorsElement = new StringBuilder();
for (DatasetAuthor author : authors) {
creatorsElement.append("<creator><creatorName>");
creatorsElement.append(author.getName().getDisplayValue());
creatorsElement.append("</creatorName>");
if (!authors.isEmpty()) {
for (DatasetAuthor author : authors) {
creatorsElement.append("<creator><creatorName>");
creatorsElement.append(author.getName().getDisplayValue());
creatorsElement.append("</creatorName>");

if (author.getIdType() != null && author.getIdValue() != null && !author.getIdType().isEmpty() && !author.getIdValue().isEmpty() && author.getAffiliation() != null && !author.getAffiliation().getDisplayValue().isEmpty()) {
if (author.getIdType() != null && author.getIdValue() != null && !author.getIdType().isEmpty() && !author.getIdValue().isEmpty() && author.getAffiliation() != null && !author.getAffiliation().getDisplayValue().isEmpty()) {

if (author.getIdType().equals("ORCID")) {
creatorsElement.append("<nameIdentifier schemeURI=\"https://orcid.org/\" nameIdentifierScheme=\"ORCID\">" + author.getIdValue() + "</nameIdentifier>");
}
if (author.getIdType().equals("ISNI")) {
creatorsElement.append("<nameIdentifier schemeURI=\"http://isni.org/isni/\" nameIdentifierScheme=\"ISNI\">" + author.getIdValue() + "</nameIdentifier>");
if (author.getIdType().equals("ORCID")) {
creatorsElement.append("<nameIdentifier schemeURI=\"https://orcid.org/\" nameIdentifierScheme=\"ORCID\">" + author.getIdValue() + "</nameIdentifier>");
}
if (author.getIdType().equals("ISNI")) {
creatorsElement.append("<nameIdentifier schemeURI=\"http://isni.org/isni/\" nameIdentifierScheme=\"ISNI\">" + author.getIdValue() + "</nameIdentifier>");
}
if (author.getIdType().equals("LCNA")) {
creatorsElement.append("<nameIdentifier schemeURI=\"http://id.loc.gov/authorities/names/\" nameIdentifierScheme=\"LCNA\">" + author.getIdValue() + "</nameIdentifier>");
}
}
if (author.getIdType().equals("LCNA")) {
creatorsElement.append("<nameIdentifier schemeURI=\"http://id.loc.gov/authorities/names/\" nameIdentifierScheme=\"LCNA\">" + author.getIdValue() + "</nameIdentifier>");
if (author.getAffiliation() != null && !author.getAffiliation().getDisplayValue().isEmpty()) {
creatorsElement.append("<affiliation>" + author.getAffiliation().getDisplayValue() + "</affiliation>");
}
creatorsElement.append("</creator>");
}
if (author.getAffiliation() != null && !author.getAffiliation().getDisplayValue().isEmpty()) {
creatorsElement.append("<affiliation>" + author.getAffiliation().getDisplayValue() + "</affiliation>");
}
creatorsElement.append("</creator>");

} else {
creatorsElement.append("<creator><creatorName>:unav</creatorName></creator>");
}

xmlMetadata = xmlMetadata.replace("${creators}", creatorsElement.toString());

StringBuilder contributorsElement = new StringBuilder();
Expand Down