Skip to content

Commit

Permalink
update rights in Datacite metadata and in Datacite Register
Browse files Browse the repository at this point in the history
  • Loading branch information
juancorr committed Mar 4, 2024
1 parent 173ff55 commit 7c850b6
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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;

import javax.ejb.EJB;
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;
Expand Down Expand Up @@ -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("<rights rightsURI=\"").append(licenseURI).append("\">").append(licenseName).append("</rights>");
else
rightsElement.append("<rights>").append(licenseName).append("</rights>");
}
} else if (termsOfUse.getTermsOfAccess()!= null) {
rightsElement.append("<rights>").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(termsOfUse.getTermsOfAccess()))).append("</rights>");
} else if (termsOfUse.getTermsOfUse()!= null) {
rightsElement.append("<rights>").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(termsOfUse.getTermsOfUse()))).append("</rights>");
} else if (termsOfUse.getConditions()!= null) {
rightsElement.append("<rights>").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(termsOfUse.getConditions()))).append("</rights>");
} else if (termsOfUse.getRestrictions()!= null) {
rightsElement.append("<rights>").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(termsOfUse.getRestrictions()))).append("</rights>");
}
}
}
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -173,6 +175,7 @@ public static String getMetadataFromDvObject(String identifier, Map<String, Stri
metadataTemplate.setIdentifier(identifier.substring(identifier.indexOf(':') + 1));
metadataTemplate.setCreators(Util.getListFromStr(metadata.get("datacite.creator")));
metadataTemplate.setAuthors(dataset.getLatestVersion().getDatasetAuthors());
metadataTemplate.setTermsOfUse(dataset.getLatestVersion().getTermsOfUseAndAccess()); // Madroño. Send rights to DataCite
if (dvObject.isInstanceofDataset()) {
//While getDescriptionPlainText strips < and > from HTML, it leaves '&' (at least so we need to xml escape as well
String description = StringEscapeUtils.escapeXml10(dataset.getLatestVersion().getDescriptionPlainText());
Expand Down Expand Up @@ -389,6 +392,7 @@ class DataCiteMetadataTemplate {
private String publisherYear;
private List<DatasetAuthor> authors;
private String description;
private TermsOfUseAndAccess termsOfUse; // Madroño. Send rights to DataCite
private List<String[]> contacts;
private List<String[]> producers;

Expand Down Expand Up @@ -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("<rights rightsURI=\"").append(licenseURI).append("\">").append(licenseName).append("</rights>");
else
rightsElement.append("<rights>").append(licenseName).append("</rights>");
}
} else if (getTermsOfUse().getTermsOfAccess()!= null) {
rightsElement.append("<rights>").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(getTermsOfUse().getTermsOfAccess()))).append("</rights>");
} else if (getTermsOfUse().getTermsOfUse()!= null) {
rightsElement.append("<rights>").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(getTermsOfUse().getTermsOfUse()))).append("</rights>");
} else if (getTermsOfUse().getConditions()!= null) {
rightsElement.append("<rights>").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(getTermsOfUse().getConditions()))).append("</rights>");
} else if (getTermsOfUse().getRestrictions()!= null) {
rightsElement.append("<rights>").append(StringEscapeUtils.escapeXml10(MarkupChecker.stripAllTags(getTermsOfUse().getRestrictions()))).append("</rights>");
}
}
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());
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
<description descriptionType="Abstract">${description}</description>
</descriptions>
<contributors>{$contributors}</contributors>
<rightsList>${MADROÑO_rightsList}</rightsList>
</resource>

0 comments on commit 7c850b6

Please sign in to comment.