-
Notifications
You must be signed in to change notification settings - Fork 486
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
send relatedIdentifier to DataCite #4782 #4795
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ac5a485
send relatedIdentifier to DataCite #4782
pdurbin e883110
In the process of testing. This work isn't finished, I just needed to…
benjamin-martinez fa08107
Some changes to how Dataset XML will be sent to DataCite. #4782
benjamin-martinez f436817
#4782 related identifier metadata
sekmiller ca8e332
Generates File DOIs prior to dataset publication #4782
benjamin-martinez 91abbc5
Closing changes. I basically just removed extra loggers and unnecessa…
benjamin-martinez 1c4313c
Merge branch 'develop' into 4782-datacite #4782
benjamin-martinez eeea6f8
Some minor formatting and refactoring changes based on the comments l…
benjamin-martinez 995902b
Changed a logger message from INFO to FINE and then refactored the ge…
benjamin-martinez 0343d1f
Merge branch 'develop' into 4782-datacite #4782
benjamin-martinez fe9a22e
Merge branch 'develop' into 4782-datacite
sekmiller 7d3e216
Merge branch '4782-datacite' of github.com:IQSS/dataverse into 4782-d…
benjamin-martinez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,15 +37,16 @@ public class DOIDataCiteRegisterService { | |
|
||
@PersistenceContext(unitName = "VDCNet-ejbPU") | ||
private EntityManager em; | ||
|
||
@EJB | ||
DataverseServiceBean dataverseService; | ||
|
||
private DataCiteRESTfullClient openClient() throws IOException { | ||
return new DataCiteRESTfullClient(System.getProperty("doi.baseurlstring"), System.getProperty("doi.username"), System.getProperty("doi.password")); | ||
} | ||
|
||
public String createIdentifierLocal(String identifier, Map<String, String> metadata, DvObject dvObject) { | ||
|
||
String xmlMetadata = getMetadataFromDvObject(identifier, metadata, dvObject); | ||
String status = metadata.get("_status").trim(); | ||
String target = metadata.get("_target"); | ||
|
@@ -65,9 +66,10 @@ public String createIdentifierLocal(String identifier, Map<String, String> metad | |
rc.setUrl(target); | ||
} | ||
retString = "success to reserved " + identifier; | ||
|
||
return retString; | ||
} | ||
|
||
public String registerIdentifier(String identifier, Map<String, String> metadata, DvObject dvObject) throws IOException { | ||
String retString = ""; | ||
String xmlMetadata = getMetadataFromDvObject(identifier, metadata, dvObject); | ||
|
@@ -88,64 +90,70 @@ public String registerIdentifier(String identifier, Map<String, String> metadata | |
} catch (UnsupportedEncodingException ex) { | ||
Logger.getLogger(DOIDataCiteRegisterService.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} else{ | ||
} else { | ||
try (DataCiteRESTfullClient client = openClient()) { | ||
retString = client.postMetadata(xmlMetadata); | ||
client.postUrl(identifier.substring(identifier.indexOf(":") + 1), target); | ||
} catch (UnsupportedEncodingException ex) { | ||
Logger.getLogger(DOIDataCiteRegisterService.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} | ||
} | ||
return retString; | ||
} | ||
|
||
public String deactivateIdentifier (String identifier, HashMap<String, String> metadata, DvObject dvObject){ | ||
String retString = ""; | ||
DOIDataCiteRegisterCache rc = findByDOI(identifier); | ||
try (DataCiteRESTfullClient client = openClient()) { | ||
if (rc != null) { | ||
rc.setStatus("unavailable"); | ||
retString = client.inactiveDataset(identifier.substring(identifier.indexOf(":") + 1)); | ||
} | ||
} catch (IOException io) { | ||
|
||
public String deactivateIdentifier(String identifier, HashMap<String, String> metadata, DvObject dvObject) { | ||
String retString = ""; | ||
DOIDataCiteRegisterCache rc = findByDOI(identifier); | ||
try (DataCiteRESTfullClient client = openClient()) { | ||
if (rc != null) { | ||
rc.setStatus("unavailable"); | ||
retString = client.inactiveDataset(identifier.substring(identifier.indexOf(":") + 1)); | ||
} | ||
return retString; | ||
} catch (IOException io) { | ||
|
||
} | ||
return retString; | ||
} | ||
private String getMetadataFromDvObject(String identifier, Map<String, String> metadata,DvObject dvObject) { | ||
|
||
private String getMetadataFromDvObject(String identifier, Map<String, String> metadata, DvObject dvObject) { | ||
|
||
Dataset dataset = null; | ||
if (dvObject instanceof Dataset){ | ||
|
||
if (dvObject instanceof Dataset) { | ||
dataset = (Dataset) dvObject; | ||
} else { | ||
dataset = (Dataset) dvObject.getOwner(); | ||
} | ||
} | ||
|
||
DataCiteMetadataTemplate metadataTemplate = new DataCiteMetadataTemplate(); | ||
metadataTemplate.setIdentifier(identifier.substring(identifier.indexOf(':') + 1)); | ||
metadataTemplate.setIdentifier(identifier.substring(identifier.indexOf(':') + 1)); | ||
metadataTemplate.setCreators(Util.getListFromStr(metadata.get("datacite.creator"))); | ||
metadataTemplate.setAuthors(dataset.getLatestVersion().getDatasetAuthors()); | ||
if (dvObject.isInstanceofDataset()) { | ||
metadataTemplate.setDescription(dataset.getLatestVersion().getDescriptionPlainText()); | ||
} | ||
if (dvObject.isInstanceofDataFile()) { | ||
DataFile df = (DataFile) dvObject; | ||
String fileDescription =df.getDescription(); | ||
metadataTemplate.setDescription(fileDescription == null ? "" :fileDescription ); | ||
String fileDescription = df.getDescription(); | ||
metadataTemplate.setDescription(fileDescription == null ? "" : fileDescription); | ||
String datasetPid = df.getOwner().getGlobalId().asString(); | ||
metadataTemplate.setDatasetIdentifier(datasetPid); | ||
} else { | ||
metadataTemplate.setDatasetIdentifier(""); | ||
} | ||
|
||
metadataTemplate.setContacts(dataset.getLatestVersion().getDatasetContacts()); | ||
metadataTemplate.setProducers(dataset.getLatestVersion().getDatasetProducers()); | ||
metadataTemplate.setTitle(dvObject.getDisplayName()); | ||
String producerString = dataverseService.findRootDataverse().getName(); | ||
String producerString = dataverseService.findRootDataverse().getName(); | ||
if (producerString.isEmpty()) { | ||
producerString = ":unav"; | ||
} | ||
metadataTemplate.setPublisher(producerString); | ||
metadataTemplate.setPublisherYear(metadata.get("datacite.publicationyear")); | ||
String xmlMetadata = metadataTemplate.generateXML(); | ||
logger.log(Level.FINE, "XML to send to DataCite: {0}", xmlMetadata); | ||
|
||
String xmlMetadata = metadataTemplate.generateXML(dvObject); | ||
logger.log(Level.INFO, "XML to send to DataCite: {0}", xmlMetadata); | ||
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 should probably be back to fine |
||
return xmlMetadata; | ||
} | ||
|
||
|
@@ -188,14 +196,14 @@ public String modifyIdentifier(String identifier, HashMap<String, String> metada | |
try (DataCiteRESTfullClient client = openClient()) { | ||
retString = client.postMetadata(xmlMetadata); | ||
client.postUrl(identifier.substring(identifier.indexOf(":") + 1), target); | ||
|
||
} catch (UnsupportedEncodingException ex) { | ||
logger.log(Level.SEVERE, null, ex); | ||
} catch ( RuntimeException rte ) { | ||
|
||
} catch (RuntimeException rte) { | ||
logger.log(Level.SEVERE, "Error creating DOI at DataCite: {0}", rte.getMessage()); | ||
logger.log(Level.SEVERE, "Exception", rte); | ||
|
||
} | ||
} | ||
} else if (status.equals("unavailable")) { | ||
|
@@ -281,6 +289,8 @@ class DataCiteMetadataTemplate { | |
|
||
private String xmlMetadata; | ||
private String identifier; | ||
private String datasetIdentifier; | ||
private List<String> datafileIdentifiers; | ||
private List<String> creators; | ||
private String title; | ||
private String publisher; | ||
|
@@ -325,6 +335,14 @@ public void setAuthors(List<DatasetAuthor> authors) { | |
public DataCiteMetadataTemplate() { | ||
} | ||
|
||
public List<String> getDatafileIdentifiers() { | ||
return datafileIdentifiers; | ||
} | ||
|
||
public void setDatafileIdentifiers(List<String> datafileIdentifiers) { | ||
this.datafileIdentifiers = datafileIdentifiers; | ||
} | ||
|
||
public DataCiteMetadataTemplate(String xmlMetaData) { | ||
this.xmlMetadata = xmlMetaData; | ||
Document doc = Jsoup.parseBodyFragment(xmlMetaData); | ||
|
@@ -351,7 +369,7 @@ public DataCiteMetadataTemplate(String xmlMetaData) { | |
} | ||
} | ||
|
||
public String generateXML() { | ||
public String generateXML(DvObject dvObject) { | ||
// Can't use "UNKNOWN" here because DataCite will respond with "[facet 'pattern'] the value 'unknown' is not accepted by the pattern '[\d]{4}'" | ||
String publisherYearFinal = "9999"; | ||
// FIXME: Investigate why this.publisherYear is sometimes null now that pull request #4606 has been merged. | ||
|
@@ -406,10 +424,73 @@ public String generateXML() { | |
} | ||
contributorsElement.append("</contributor>"); | ||
} | ||
|
||
String relIdentifiers = generateRelatedIdentifiers(dvObject); | ||
|
||
xmlMetadata = xmlMetadata.replace("${relatedIdentifiers}", relIdentifiers); | ||
|
||
xmlMetadata = xmlMetadata.replace("{$contributors}", contributorsElement.toString()); | ||
return xmlMetadata; | ||
} | ||
|
||
private String generateRelatedIdentifiers(DvObject dvObject) { | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
if (dvObject.isInstanceofDataset()) { | ||
Dataset dataset = (Dataset) dvObject; | ||
if (!dataset.getFiles().isEmpty() && !(dataset.getFiles().get(0).getIdentifier() == null)) { | ||
|
||
datafileIdentifiers = new ArrayList<>(); | ||
for (DataFile dataFile : dataset.getFiles()) { | ||
String add = ""; | ||
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 use a stringbuilder for performance? |
||
sb.append(""); | ||
if (!dataFile.getGlobalId().asString().isEmpty()) { | ||
add = "<relatedIdentifier relatedIdentifierType=\"DOI\" relationType=\"HasPart\"" | ||
+ ">" + dataFile.getGlobalId() + "</relatedIdentifier>"; | ||
if (sb.toString().isEmpty()) { | ||
sb.append("<relatedIdentifiers>"); | ||
} | ||
sb.append(add); | ||
} | ||
} | ||
|
||
if (!sb.toString().isEmpty()) { | ||
sb.append("</relatedIdentifiers>"); | ||
} | ||
} | ||
} else if (dvObject.isInstanceofDataFile()) { | ||
DataFile df = (DataFile) dvObject; | ||
sb.append("<relatedIdentifiers>"); | ||
sb.append("<relatedIdentifier relatedIdentifierType=\"DOI\" relationType=\"IsPartOf\"" | ||
+ ">" + df.getOwner().getGlobalId() + "</relatedIdentifier>"); | ||
sb.append("</relatedIdentifiers>"); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
public void generateFileIdentifiers(DvObject dvObject) { | ||
|
||
if (dvObject.isInstanceofDataset()) { | ||
Dataset dataset = (Dataset) dvObject; | ||
|
||
if (!dataset.getFiles().isEmpty() && !(dataset.getFiles().get(0).getIdentifier() == null)) { | ||
|
||
datafileIdentifiers = new ArrayList<>(); | ||
for (DataFile dataFile : dataset.getFiles()) { | ||
datafileIdentifiers.add(dataFile.getIdentifier()); | ||
int x = xmlMetadata.indexOf("</relatedIdentifiers>") - 1; | ||
xmlMetadata = xmlMetadata.replace("{relatedIdentifier}", dataFile.getIdentifier()); | ||
xmlMetadata = xmlMetadata.substring(0, x) + "<relatedIdentifier relatedIdentifierType=\"hasPart\" " | ||
+ "relationType=\"doi\">${relatedIdentifier}</relatedIdentifier>" + template.substring(x, template.length() - 1); | ||
|
||
} | ||
|
||
} else { | ||
xmlMetadata = xmlMetadata.replace("<relatedIdentifier relatedIdentifierType=\"hasPart\" relationType=\"doi\">${relatedIdentifier}</relatedIdentifier>", ""); | ||
} | ||
} | ||
} | ||
|
||
public static String getTemplate() { | ||
return template; | ||
} | ||
|
@@ -426,6 +507,10 @@ public void setIdentifier(String identifier) { | |
this.identifier = identifier; | ||
} | ||
|
||
public void setDatasetIdentifier(String datasetIdentifier) { | ||
this.datasetIdentifier = datasetIdentifier; | ||
} | ||
|
||
public List<String> getCreators() { | ||
return creators; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Kinda picky, but some of the indentation and whitespace in this file could be cleaned up. Other ones seem ok though.
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.
fyi, alt shift f does this for a full file.