-
Notifications
You must be signed in to change notification settings - Fork 488
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
Changes from 2 commits
46e19f5
990fc28
bd9491f
4cd5863
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
HashMap<String, String> metadata = new HashMap<>(); | ||
String authorString = ":unav"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
return metadata; | ||
} | ||
|
||
protected String getTargetUrl(DvObject dvObjectIn) { | ||
logger.log(Level.FINE,"getTargetUrl"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -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: "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would you not use logging? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does this special value come from? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this |
||
} | ||
} catch (RuntimeException e) { | ||
logger.log(Level.INFO, identifier, e); | ||
|
@@ -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()); | ||
|
@@ -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); | ||
|
There was a problem hiding this comment.
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 specificHashMap
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Will change.