When creating a new version on zenodo update also it's metadata in order to corespond to the current DMP version (ref #221)
This commit is contained in:
parent
0d59cce33c
commit
acca3bf411
|
@ -343,7 +343,7 @@ public class DataManagementPlanManager {
|
||||||
|
|
||||||
String fileName = "";
|
String fileName = "";
|
||||||
if (versioned) {
|
if (versioned) {
|
||||||
fileName = dmpEntity.getLabel() + "_v" + dmpEntity.getVersion();
|
fileName = dmpEntity.getLabel() + " v" + dmpEntity.getVersion();
|
||||||
} else {
|
} else {
|
||||||
fileName = dmpEntity.getLabel();
|
fileName = dmpEntity.getLabel();
|
||||||
}
|
}
|
||||||
|
@ -1289,16 +1289,18 @@ public class DataManagementPlanManager {
|
||||||
"}";
|
"}";
|
||||||
HttpEntity<String> request = new HttpEntity<>(createData, headers);
|
HttpEntity<String> request = new HttpEntity<>(createData, headers);
|
||||||
Map createResponse = null;
|
Map createResponse = null;
|
||||||
|
LinkedHashMap<String, String> links = null;
|
||||||
if (dmp.getVersion() == 0) {
|
if (dmp.getVersion() == 0) {
|
||||||
String createUrl = this.environment.getProperty("zenodo.url") + "deposit/depositions" + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
String createUrl = this.environment.getProperty("zenodo.url") + "deposit/depositions" + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||||
createResponse = restTemplate.postForObject(createUrl, request, Map.class);
|
createResponse = restTemplate.postForObject(createUrl, request, Map.class);
|
||||||
|
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||||
} else {
|
} else {
|
||||||
//It requires more than one step to create a new version
|
//It requires more than one step to create a new version
|
||||||
//First, get the deposit related to the concept DOI
|
//First, get the deposit related to the concept DOI
|
||||||
String listUrl = this.environment.getProperty("zenodo.url") + "deposit/depositions" + "?q=conceptdoi:\"" + this.getPreviousDOI(dmp.getGroupId(), dmp.getId()) + "\"&access_token=" + this.environment.getProperty("zenodo.access_token");
|
String listUrl = this.environment.getProperty("zenodo.url") + "deposit/depositions" + "?q=conceptdoi:\"" + this.getPreviousDOI(dmp.getGroupId(), dmp.getId()) + "\"&access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||||
ResponseEntity<Map[]> listResponses = restTemplate.getForEntity(listUrl, Map[].class);
|
ResponseEntity<Map[]> listResponses = restTemplate.getForEntity(listUrl, Map[].class);
|
||||||
createResponse = listResponses.getBody()[0];
|
createResponse = listResponses.getBody()[0];
|
||||||
LinkedHashMap<String, String> links = (LinkedHashMap<String, String>) createResponse.get("links");
|
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||||
//Second, make the new version (not in the links?)
|
//Second, make the new version (not in the links?)
|
||||||
String newVersionUrl = links.get("self") + "/actions/newversion" + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
String newVersionUrl = links.get("self") + "/actions/newversion" + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||||
createResponse = restTemplate.postForObject(newVersionUrl, null, Map.class);
|
createResponse = restTemplate.postForObject(newVersionUrl, null, Map.class);
|
||||||
|
@ -1306,20 +1308,9 @@ public class DataManagementPlanManager {
|
||||||
//Third, get the new deposit
|
//Third, get the new deposit
|
||||||
String latestDraftUrl = links.get("latest_draft") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
String latestDraftUrl = links.get("latest_draft") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||||
createResponse = restTemplate.getForObject(latestDraftUrl, Map.class);
|
createResponse = restTemplate.getForObject(latestDraftUrl, Map.class);
|
||||||
/* String fileListUrl = links.get("latest_draft") + "/files" + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||||
try {
|
String updateUrl = links.get("self") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||||
//And finally remove pre-existing files from it
|
restTemplate.put(updateUrl, request);
|
||||||
ResponseEntity<Map[]> fileListResponse = restTemplate.getForEntity(fileListUrl, Map[].class);
|
|
||||||
for (Map file : fileListResponse.getBody()) {
|
|
||||||
String fileDeleteUrl = links.get("latest_draft") + "/files/" + file.get("id") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
|
||||||
restTemplate.delete(fileDeleteUrl);
|
|
||||||
}
|
|
||||||
}catch (Exception e) {
|
|
||||||
//In case the last step fail delete the latest Deposit it in order to create a new one (only one at a time is allowed)
|
|
||||||
restTemplate.delete(latestDraftUrl);
|
|
||||||
throw e;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second step, add the file to the entry.
|
// Second step, add the file to the entry.
|
||||||
|
@ -1333,7 +1324,6 @@ public class DataManagementPlanManager {
|
||||||
addFileMap.add("file", fileSystemResource);
|
addFileMap.add("file", fileSystemResource);
|
||||||
HttpEntity<MultiValueMap<String, Object>> addFileMapRequest = new HttpEntity<>(addFileMap, fileHeaders);
|
HttpEntity<MultiValueMap<String, Object>> addFileMapRequest = new HttpEntity<>(addFileMap, fileHeaders);
|
||||||
|
|
||||||
LinkedHashMap<String, String> links = (LinkedHashMap<String, String>) createResponse.get("links");
|
|
||||||
String addFileUrl = links.get("files") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
String addFileUrl = links.get("files") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||||
ResponseEntity<String> addFileResponse = restTemplate.postForEntity(addFileUrl, addFileMapRequest, String.class);
|
ResponseEntity<String> addFileResponse = restTemplate.postForEntity(addFileUrl, addFileMapRequest, String.class);
|
||||||
Files.deleteIfExists(file.toPath());
|
Files.deleteIfExists(file.toPath());
|
||||||
|
|
Loading…
Reference in New Issue