When creating a new zenodo version keep only the latest version file (ref #221)

This commit is contained in:
George Kalampokis 2020-02-24 12:12:53 +02:00
parent ea0290fb03
commit be97645bf0
1 changed files with 15 additions and 2 deletions

View File

@ -1310,7 +1310,20 @@ public class DataManagementPlanManager {
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");
restTemplate.put(updateUrl, request);
try {
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
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.
@ -1318,7 +1331,7 @@ public class DataManagementPlanManager {
fileHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
LinkedMultiValueMap<String, Object> addFileMap = new LinkedMultiValueMap<>();
File file = getWordDocument(id.toString(), principal, configLoader, true);
File file = getWordDocument(id.toString(), principal, configLoader);
addFileMap.add("filename", file.getName());
FileSystemResource fileSystemResource = new FileSystemResource(file);
addFileMap.add("file", fileSystemResource);