When creating a new zenodo version keep only the latest version file (ref #221)
This commit is contained in:
parent
ea0290fb03
commit
be97645bf0
|
@ -1310,7 +1310,20 @@ public class DataManagementPlanManager {
|
||||||
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");
|
||||||
String updateUrl = links.get("self") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
String updateUrl = links.get("self") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||||
|
try {
|
||||||
restTemplate.put(updateUrl, request);
|
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.
|
// Second step, add the file to the entry.
|
||||||
|
@ -1318,7 +1331,7 @@ public class DataManagementPlanManager {
|
||||||
fileHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
fileHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
LinkedMultiValueMap<String, Object> addFileMap = new LinkedMultiValueMap<>();
|
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());
|
addFileMap.add("filename", file.getName());
|
||||||
FileSystemResource fileSystemResource = new FileSystemResource(file);
|
FileSystemResource fileSystemResource = new FileSystemResource(file);
|
||||||
addFileMap.add("file", fileSystemResource);
|
addFileMap.add("file", fileSystemResource);
|
||||||
|
|
Loading…
Reference in New Issue