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