When generating DOI it will remain unpublished until the DMP got published, add reference identifier to the DMP (public overview) and add collaborators (associated users and researchers) to DOI generation (ref #257)
This commit is contained in:
parent
f397ce6c72
commit
7784547bea
|
@ -794,6 +794,7 @@ public class DataManagementPlanManager {
|
|||
});
|
||||
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||
sendNotification(dmp, user, NotificationType.DMP_PUBLISH);
|
||||
this.createZenodoDoi(dmp.getId(), principal, null);
|
||||
}
|
||||
|
||||
public void makeFinalize(UUID id, Principal principal, DatasetsToBeFinalized datasetsToBeFinalized) throws Exception {
|
||||
|
@ -1610,8 +1611,8 @@ public class DataManagementPlanManager {
|
|||
throw new Exception("User is not authorized to invoke this action");
|
||||
if (!dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()))
|
||||
throw new Exception("DMP is not finalized");
|
||||
if (dmp.getDoi() != null)
|
||||
throw new Exception("DMP already has a DOI");
|
||||
/*if (dmp.getDoi() != null)
|
||||
throw new Exception("DMP already has a DOI");*/
|
||||
|
||||
String zenodoToken = "";
|
||||
try {
|
||||
|
@ -1626,18 +1627,51 @@ public class DataManagementPlanManager {
|
|||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
String createData = "{\n" +
|
||||
" \"metadata\": {\n" +
|
||||
" \"title\": \"" + dmp.getLabel() + "\",\n" +
|
||||
" \"upload_type\": \"publication\",\n" +
|
||||
" \"publication_type\": \"datamanagementplan\",\n" +
|
||||
" \"description\": \"" + (dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>") + "\",\n" +
|
||||
" \"version\": \"" + dmp.getVersion() + "\",\n" +
|
||||
" \"creators\": [{\n" +
|
||||
" \t\t\"name\": \"" + dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getName() + "\",\n" +
|
||||
" \t\t\"affiliation\": \"OpenDMP\"}]\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
String createData = null;
|
||||
StringBuilder dataBuilder = new StringBuilder();
|
||||
dataBuilder.append("{\n \"metadata\": {\n");
|
||||
dataBuilder.append( " \"title\": \"").append(dmp.getLabel()).append("\",\n");
|
||||
dataBuilder.append(" \"upload_type\": \"publication\",\n");
|
||||
dataBuilder.append(" \"publication_type\": \"datamanagementplan\",\n");
|
||||
dataBuilder.append(" \"description\": \"").append((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>")).append("\",\n");
|
||||
dataBuilder.append(" \"version\": \"").append(dmp.getVersion()).append("\",\n");
|
||||
dataBuilder.append(" \"related_identifiers\": [{\n");
|
||||
dataBuilder.append(" \t\t\"identifier\": \"").append((this.environment.getProperty("dmp.domain") + "/explore-plans/publicOverview/" + id.toString())).append("\",\n");
|
||||
dataBuilder.append(" \t\t\"relation\": \"isIdenticalTo\"}],\n");
|
||||
dataBuilder.append(" \"contributors\": [");
|
||||
int i = 0;
|
||||
for(UserDMP userDMP: dmp.getUsers()) {
|
||||
if (i > 0) {
|
||||
dataBuilder.append(",\n");
|
||||
}
|
||||
dataBuilder.append("{\n");
|
||||
dataBuilder.append(" \t\t\"name\": \"").append(userDMP.getUser().getName()).append("\",\n");
|
||||
dataBuilder.append(" \t\t\"type\": \"").append("ProjectMember").append("\",\n");
|
||||
dataBuilder.append(" \t\t\"affiliation\": \"OpenDMP\"\n}");
|
||||
i++;
|
||||
}
|
||||
for(Researcher researcher: dmp.getResearchers()) {
|
||||
if (i > 0) {
|
||||
dataBuilder.append(",\n");
|
||||
}
|
||||
dataBuilder.append("{\n");
|
||||
dataBuilder.append(" \t\t\"name\": \"").append(researcher.getLabel()).append("\",\n");
|
||||
dataBuilder.append(" \t\t\"type\": \"").append("Researcher").append("\",\n");
|
||||
String referenceHead = researcher.getReference().split(":")[0];
|
||||
String referenceTail = researcher.getReference().replace(referenceHead + ":", "");
|
||||
dataBuilder.append(" \t\t\"affiliation\": \"" + referenceHead + "\"");
|
||||
if (referenceHead.toUpperCase().equals("ORCID")) {
|
||||
dataBuilder.append(",\n \t\t\"orcid\": \"" + referenceTail + "\"");
|
||||
}
|
||||
dataBuilder.append("\n}");
|
||||
i++;
|
||||
}
|
||||
dataBuilder.append("],\n");
|
||||
dataBuilder.append(" \"creators\": [{\n");
|
||||
dataBuilder.append(" \t\t\"name\": \"").append(dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getName()).append("\",\n");
|
||||
dataBuilder.append(" \t\t\"affiliation\": \"OpenDMP\"}]\n");
|
||||
dataBuilder.append(" }\n").append("}");
|
||||
createData = dataBuilder.toString();
|
||||
JsonNode createDataJSON = new ObjectMapper().readTree(createData);
|
||||
HttpEntity<JsonNode> request = new HttpEntity<>(createDataJSON, headers);
|
||||
Map createResponse = null;
|
||||
|
@ -1645,12 +1679,14 @@ public class DataManagementPlanManager {
|
|||
String previousDOI = this.getPreviousDOI(dmp.getGroupId(), dmp.getId());
|
||||
String unpublishedUrl = null;
|
||||
String publishUrl = null;
|
||||
String finalDoi = null;
|
||||
try {
|
||||
|
||||
if (previousDOI == null) {
|
||||
String createUrl = this.environment.getProperty("zenodo.url") + "deposit/depositions" + "?access_token=" + zenodoToken;
|
||||
createResponse = restTemplate.postForEntity(createUrl, request, Map.class).getBody();
|
||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||
finalDoi = (String) createResponse.get("conceptdoi");
|
||||
} else {
|
||||
unpublishedUrl = this.getUnpublishedDOI(previousDOI, zenodoToken, dmp.getVersion());
|
||||
if (unpublishedUrl == null) {
|
||||
|
@ -1668,6 +1704,7 @@ public class DataManagementPlanManager {
|
|||
String latestDraftUrl = links.get("latest_draft") + "?access_token=" + zenodoToken;
|
||||
createResponse = restTemplate.getForObject(latestDraftUrl, Map.class);
|
||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||
finalDoi = (String) createResponse.get("conceptdoi");
|
||||
//At this point it might fail to perform the next requests so enclose them with try catch
|
||||
try {
|
||||
//Forth, update the new deposit's metadata
|
||||
|
@ -1710,11 +1747,16 @@ public class DataManagementPlanManager {
|
|||
} else {
|
||||
publishUrl = unpublishedUrl + "?access_token=" + zenodoToken;
|
||||
}
|
||||
Map<String, Object> publishResponce = restTemplate.postForObject(publishUrl, "", Map.class);
|
||||
if (dmp.isPublic()) {
|
||||
Map<String, Object> publishResponce = restTemplate.postForObject(publishUrl, "", Map.class);
|
||||
finalDoi = (String) publishResponce.get("conceptdoi");
|
||||
}
|
||||
|
||||
dmp.setDoi((String) publishResponce.get("conceptdoi"));
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
|
||||
return (String) publishResponce.get("conceptdoi");
|
||||
if (finalDoi != null) {
|
||||
dmp.setDoi(finalDoi);
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
|
||||
}
|
||||
return finalDoi;
|
||||
} catch (HttpClientErrorException | HttpServerErrorException ex) {
|
||||
ObjectMapper ob = new ObjectMapper();
|
||||
Map<String, String> parsedException = ob.readValue(ex.getResponseBodyAsString(), HashMap.class);
|
||||
|
|
Loading…
Reference in New Issue