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

2471 destroy command should unregister doi #6060

Merged
merged 4 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -77,7 +77,20 @@ protected Map<String, String> addBasicMetadata(DvObject dvObjectIn, Map<String,
metadata.put("datacite.publisher", producerString);
metadata.put("datacite.publicationyear", generateYear(dvObjectIn));
return metadata;
}
}

protected HashMap<String, String> addMetadataForDestroyedDataset(DvObject dvObjectIn) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the return type be Map instead of the more specific HashMap?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Will change.

HashMap<String, String> metadata = new HashMap<>();
String authorString = ":unav";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this special string from?

String producerString = ":unav";
String titleString = "This item has been removed from publication";

metadata.put("datacite.creator", authorString);
metadata.put("datacite.title", titleString);
metadata.put("datacite.publisher", producerString);
metadata.put("datacite.publicationyear", "9999");
Copy link
Contributor

@landreev landreev Aug 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @bencomp, that special strings should generally be defined as constants somewhere.
Also, I find this a little confusing that this method is in AbstractGlobalIdServiceBean - but it does something that's very specific to the Datacite metadata. I understand you are modeling this method after the already existing method above (addBasicMetadata()) that does the same thing... I'm assuming we do this in the "abstract" bean because this datacite metadata format is used by both the Datacite and EZID DOI implementations. I still feel this could be confusing for the next person working with this code; could you rename these methods, to somehow indicate that they are specific to the DOI implementations - but not to Handles (that extends the same Abstract service class); something like addDOIMetadataForDestroyedDataset() etc.?

return metadata;
}

protected String getTargetUrl(DvObject dvObjectIn) {
logger.log(Level.FINE,"getTargetUrl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,19 @@ public String registerIdentifier(String identifier, Map<String, String> metadata

public String deactivateIdentifier(String identifier, HashMap<String, String> metadata, DvObject dvObject) {
String retString = "";
DOIDataCiteRegisterCache rc = findByDOI(identifier);

try {
DataCiteRESTfullClient client = getClient();
if (rc != null) {
rc.setStatus("unavailable");
retString = client.inactiveDataset(identifier.substring(identifier.indexOf(":") + 1));
}
String metadataString = getMetadataForDeactivateIdentifier(identifier, metadata, dvObject);
retString = client.postMetadata(metadataString);
retString = client.inactiveDataset(identifier.substring(identifier.indexOf(":") + 1));
} catch (IOException io) {

}
return retString;
}

public static String getMetadataFromDvObject(String identifier, Map<String, String> metadata, DvObject dvObject) {
public static String getMetadataFromDvObject(String identifier, Map<String, String> metadata, DvObject dvObject) {

Dataset dataset = null;

Expand Down Expand Up @@ -189,6 +188,32 @@ public static String getMetadataFromDvObject(String identifier, Map<String, Stri
return xmlMetadata;
}

public static String getMetadataForDeactivateIdentifier(String identifier, Map<String, String> metadata, DvObject dvObject) {

System.out.print("Start of getMetadataForDeactivateIdentifier: ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you not use logging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is debug code that should have been removed altogether. I will delete it.

DataCiteMetadataTemplate metadataTemplate = new DataCiteMetadataTemplate();
metadataTemplate.setIdentifier(identifier.substring(identifier.indexOf(':') + 1));
metadataTemplate.setCreators(Util.getListFromStr(metadata.get("datacite.creator")));

metadataTemplate.setDescription(":unav");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this special value come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The special values here come from the DataCite Metadata schema https://support.datacite.org/docs/schema-values-unknown-information-v41

My intent for this is to mask any identifying information since the Dataset in question has been destroyed by Dataverse and in the opinion of the Dataverse admin should never have been created/published.


String title =metadata.get("datacite.title");

System.out.print("Map metadata title: "+ metadata.get("datacite.title"));

metadataTemplate.setAuthors(null);

metadataTemplate.setTitle(title);
String producerString = ":unav";

metadataTemplate.setPublisher(producerString);
metadataTemplate.setPublisherYear(metadata.get("datacite.publicationyear"));

String xmlMetadata = metadataTemplate.generateXML(dvObject);
logger.log(Level.FINE, "XML to send to DataCite: {0}", xmlMetadata);
return xmlMetadata;
}

public String modifyIdentifier(String identifier, HashMap<String, String> metadata, DvObject dvObject) throws IOException {

String xmlMetadata = getMetadataFromDvObject(identifier, metadata, dvObject);
Expand Down Expand Up @@ -279,6 +304,8 @@ public HashMap<String, String> getMetadata(String identifier) throws IOException
DOIDataCiteRegisterCache rc = findByDOI(identifier);
if (rc != null) {
metadata.put("_status", rc.getStatus());
} else {
metadata.put("_status", "public");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this public be a constant?

}
} catch (RuntimeException e) {
logger.log(Level.INFO, identifier, e);
Expand Down Expand Up @@ -418,8 +445,9 @@ public String generateXML(DvObject dvObject) {
.replace("${publisher}", this.publisher)
.replace("${publisherYear}", publisherYearFinal)
.replace("${description}", this.description);

StringBuilder creatorsElement = new StringBuilder();
if (!authors.isEmpty()) {
if (authors!= null && !authors.isEmpty()) {
for (DatasetAuthor author : authors) {
creatorsElement.append("<creator><creatorName>");
creatorsElement.append(author.getName().getDisplayValue());
Expand Down Expand Up @@ -450,21 +478,26 @@ public String generateXML(DvObject dvObject) {
xmlMetadata = xmlMetadata.replace("${creators}", creatorsElement.toString());

StringBuilder contributorsElement = new StringBuilder();
for (String[] contact : this.getContacts()) {
if (!contact[0].isEmpty()) {
contributorsElement.append("<contributor contributorType=\"ContactPerson\"><contributorName>" + contact[0] + "</contributorName>");
if (!contact[1].isEmpty()) {
contributorsElement.append("<affiliation>" + contact[1] + "</affiliation>");
if (this.getContacts() != null) {
for (String[] contact : this.getContacts()) {
if (!contact[0].isEmpty()) {
contributorsElement.append("<contributor contributorType=\"ContactPerson\"><contributorName>" + contact[0] + "</contributorName>");
if (!contact[1].isEmpty()) {
contributorsElement.append("<affiliation>" + contact[1] + "</affiliation>");
}
contributorsElement.append("</contributor>");
}
contributorsElement.append("</contributor>");
}
}
for (String[] producer : this.getProducers()) {
contributorsElement.append("<contributor contributorType=\"Producer\"><contributorName>" + producer[0] + "</contributorName>");
if (!producer[1].isEmpty()) {
contributorsElement.append("<affiliation>" + producer[1] + "</affiliation>");

if (this.getProducers() != null) {
for (String[] producer : this.getProducers()) {
contributorsElement.append("<contributor contributorType=\"Producer\"><contributorName>" + producer[0] + "</contributorName>");
if (!producer[1].isEmpty()) {
contributorsElement.append("<affiliation>" + producer[1] + "</affiliation>");
}
contributorsElement.append("</contributor>");
}
contributorsElement.append("</contributor>");
}

String relIdentifiers = generateRelatedIdentifiers(dvObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ public void deleteIdentifier(DvObject dvObject) throws Exception {
}

String idStatus = doiMetadata.get("_status");

if ( idStatus != null ) {
switch ( idStatus ) {
case "reserved":
case "draft":
logger.log(Level.INFO, "Delete status is reserved..");
try {
doiDataCiteRegisterService.deleteIdentifier(identifier);
Expand All @@ -189,15 +189,15 @@ public void deleteIdentifier(DvObject dvObject) throws Exception {
break;

case "public":
case "findable":
//if public then it has been released set to unavailable and reset target to n2t url
updateIdentifierStatus(dvObject, "unavailable");
HashMap<String, String> metadata = addMetadataForDestroyedDataset(dvObject);
metadata.put("_status", "registered");
metadata.put("_target", getTargetUrl(dvObject));
doiDataCiteRegisterService.modifyIdentifier(identifier, metadata, dvObject);
doiDataCiteRegisterService.deactivateIdentifier(identifier, metadata, dvObject);
break;
}
return;
}
if (idStatus != null && idStatus.equals("public")) {
//if public then it has been released set to unavailable and reset target to n2t url
doiDataCiteRegisterService.deactivateIdentifier(identifier, doiMetadata, dvObject);
}
}

Expand Down