From 7c850b62930f1077bda1c01702bf7607a37aca8b Mon Sep 17 00:00:00 2001 From: juancorr Date: Mon, 4 Mar 2024 17:42:15 +0100 Subject: [PATCH] update rights in Datacite metadata and in Datacite Register --- .../AbstractGlobalIdServiceBean.java | 42 +++++++++++++++++++ .../dataverse/DOIDataCiteRegisterService.java | 38 +++++++++++++++++ .../dataverse/datacite_metadata_template.xml | 1 + 3 files changed, 81 insertions(+) diff --git a/src/main/java/edu/harvard/iq/dataverse/AbstractGlobalIdServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/AbstractGlobalIdServiceBean.java index f6cbd01ece0..0342a08124c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/AbstractGlobalIdServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/AbstractGlobalIdServiceBean.java @@ -1,6 +1,8 @@ package edu.harvard.iq.dataverse; +import edu.harvard.iq.dataverse.license.License; import edu.harvard.iq.dataverse.settings.SettingsServiceBean; +import edu.harvard.iq.dataverse.util.MarkupChecker; import edu.harvard.iq.dataverse.util.SystemConfig; import java.io.InputStream; @@ -8,6 +10,7 @@ import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; +import org.apache.commons.text.StringEscapeUtils; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -295,6 +298,45 @@ public String generateXML(DvObject dvObject) { String relIdentifiers = generateRelatedIdentifiers(dvObject); + // MADROÑO BEGIN: Send rights to DataCite + StringBuilder rightsElement= new StringBuilder(); + Dataset dataset; + + if (dvObject instanceof Dataset) { + dataset = (Dataset) dvObject; + } else { + dataset = (Dataset) dvObject.getOwner(); + } + + TermsOfUseAndAccess termsOfUse; + if (dataset!= null) { + termsOfUse= dataset.getLatestVersion().getTermsOfUseAndAccess(); + if (termsOfUse!= null) { + License license= termsOfUse.getLicense(); + if (license != null) { + String licenseName= license.getName(); + String licenseURI= license.getUri().toString(); + if (licenseName!= null) { + if (licenseURI!= null) + rightsElement.append("").append(licenseName).append(""); + else + rightsElement.append("").append(licenseName).append(""); + } + } else if (termsOfUse.getTermsOfAccess()!= null) { + rightsElement.append("").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(termsOfUse.getTermsOfAccess()))).append(""); + } else if (termsOfUse.getTermsOfUse()!= null) { + rightsElement.append("").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(termsOfUse.getTermsOfUse()))).append(""); + } else if (termsOfUse.getConditions()!= null) { + rightsElement.append("").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(termsOfUse.getConditions()))).append(""); + } else if (termsOfUse.getRestrictions()!= null) { + rightsElement.append("").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(termsOfUse.getRestrictions()))).append(""); + } + } + } + xmlMetadata = xmlMetadata.replace("${MADROÑO_rightsList}", rightsElement); + // MADROÑO END: Send rights to DataCite + + xmlMetadata = xmlMetadata.replace("${relatedIdentifiers}", relIdentifiers); xmlMetadata = xmlMetadata.replace("{$contributors}", contributorsElement.toString()); diff --git a/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterService.java b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterService.java index 218e4c85474..65aa5fb9d06 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterService.java +++ b/src/main/java/edu/harvard/iq/dataverse/DOIDataCiteRegisterService.java @@ -6,6 +6,8 @@ package edu.harvard.iq.dataverse; import edu.harvard.iq.dataverse.branding.BrandingUtil; +import edu.harvard.iq.dataverse.license.License; +import edu.harvard.iq.dataverse.util.MarkupChecker; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -173,6 +175,7 @@ public static String getMetadataFromDvObject(String identifier, Map from HTML, it leaves '&' (at least so we need to xml escape as well String description = StringEscapeUtils.escapeXml10(dataset.getLatestVersion().getDescriptionPlainText()); @@ -389,6 +392,7 @@ class DataCiteMetadataTemplate { private String publisherYear; private List authors; private String description; + private TermsOfUseAndAccess termsOfUse; // Madroño. Send rights to DataCite private List contacts; private List producers; @@ -531,6 +535,32 @@ public String generateXML(DvObject dvObject) { String relIdentifiers = generateRelatedIdentifiers(dvObject); + // MADROÑO BEGIN: Send rights to DataCite + StringBuilder rightsElement= new StringBuilder(); + if (getTermsOfUse()!= null) { + License license= getTermsOfUse().getLicense(); + if (license != null) { + String licenseName= license.getName(); + String licenseURI= license.getUri().toString(); + if (licenseName!= null) { + if (licenseURI!= null) + rightsElement.append("").append(licenseName).append(""); + else + rightsElement.append("").append(licenseName).append(""); + } + } else if (getTermsOfUse().getTermsOfAccess()!= null) { + rightsElement.append("").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(getTermsOfUse().getTermsOfAccess()))).append(""); + } else if (getTermsOfUse().getTermsOfUse()!= null) { + rightsElement.append("").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(getTermsOfUse().getTermsOfUse()))).append(""); + } else if (getTermsOfUse().getConditions()!= null) { + rightsElement.append("").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(getTermsOfUse().getConditions()))).append(""); + } else if (getTermsOfUse().getRestrictions()!= null) { + rightsElement.append("").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(getTermsOfUse().getRestrictions()))).append(""); + } + } + xmlMetadata = xmlMetadata.replace("${MADROÑO_rightsList}", rightsElement.toString()); + // MADROÑO END: Send rights to DataCite + xmlMetadata = xmlMetadata.replace("${relatedIdentifiers}", relIdentifiers); xmlMetadata = xmlMetadata.replace("{$contributors}", contributorsElement.toString()); @@ -631,6 +661,10 @@ public String getPublisher() { return publisher; } + public TermsOfUseAndAccess getTermsOfUse() { // Madroño. Send rights to DataCite + return termsOfUse; + } + public void setPublisher(String publisher) { this.publisher = publisher; } @@ -642,6 +676,10 @@ public String getPublisherYear() { public void setPublisherYear(String publisherYear) { this.publisherYear = publisherYear; } + + void setTermsOfUse(TermsOfUseAndAccess termsOfUse) { // Madroño. Send rights to DataCite + this.termsOfUse= termsOfUse; + } } class Util { diff --git a/src/main/resources/edu/harvard/iq/dataverse/datacite_metadata_template.xml b/src/main/resources/edu/harvard/iq/dataverse/datacite_metadata_template.xml index abe7ce79972..a7d581b13d5 100644 --- a/src/main/resources/edu/harvard/iq/dataverse/datacite_metadata_template.xml +++ b/src/main/resources/edu/harvard/iq/dataverse/datacite_metadata_template.xml @@ -15,4 +15,5 @@ ${description} {$contributors} + ${MADROÑO_rightsList}