Minor refactoring

This commit is contained in:
George Kalampokis 2020-02-26 10:51:47 +02:00
parent d00b4d5e59
commit 03619a65fc
1 changed files with 6 additions and 4 deletions

View File

@ -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;
}