Minor refactoring
This commit is contained in:
parent
d00b4d5e59
commit
03619a65fc
|
@ -1309,18 +1309,20 @@ public class DataManagementPlanManager {
|
|||
String latestDraftUrl = links.get("latest_draft") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||
createResponse = restTemplate.getForObject(latestDraftUrl, Map.class);
|
||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||
String updateUrl = links.get("self") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||
//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
|
||||
String updateUrl = links.get("self") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||
restTemplate.put(updateUrl, request);
|
||||
String fileListUrl = links.get("latest_draft") + "/files" + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||
//And finally remove pre-existing files from it
|
||||
String fileListUrl = links.get("self") + "/files" + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||
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");
|
||||
String fileDeleteUrl = links.get("self") + "/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)
|
||||
//In case the last two steps 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue