Update Zenodo's file API

This commit is contained in:
George Kalampokis 2020-08-25 17:30:29 +03:00
parent fa86258197
commit e1368e270a
1 changed files with 4 additions and 10 deletions

View File

@ -1901,23 +1901,17 @@ public class DataManagementPlanManager {
if (!update) { if (!update) {
if (unpublishedUrl == null) { if (unpublishedUrl == null) {
// Second step, add the file to the entry. // Second step, add the file to the entry.
HttpHeaders fileHeaders = new HttpHeaders();
fileHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
LinkedMultiValueMap<String, Object> addFileMap = new LinkedMultiValueMap<>();
FileEnvelope file = getWordDocument(id.toString(), principal, configLoader); FileEnvelope file = getWordDocument(id.toString(), principal, configLoader);
String name = file.getFilename().substring(0, file.getFilename().length() - 5); String name = file.getFilename().substring(0, file.getFilename().length() - 5);
File pdfFile = datasetManager.convertToPDF(file, environment); File pdfFile = datasetManager.convertToPDF(file, environment);
addFileMap.add("filename", name + ".pdf"); String fileName = name + ".pdf";
FileSystemResource fileSystemResource = new FileSystemResource(pdfFile); FileSystemResource fileSystemResource = new FileSystemResource(pdfFile);
addFileMap.add("file", fileSystemResource); HttpEntity<FileSystemResource> addFileMapRequest = new HttpEntity<>(fileSystemResource, null);
HttpEntity<MultiValueMap<String, Object>> addFileMapRequest = new HttpEntity<>(addFileMap, fileHeaders);
String addFileUrl = links.get("files") + "?access_token=" + zenodoToken; String addFileUrl = links.get("bucket") + "/" + fileName + "?access_token=" + zenodoToken;
ResponseEntity<String> addFileResponse = restTemplate.postForEntity(addFileUrl, addFileMapRequest, String.class); restTemplate.put(addFileUrl, addFileMapRequest);
Files.deleteIfExists(file.getFile().toPath()); Files.deleteIfExists(file.getFile().toPath());
// Third post call to Zenodo to publish the entry and return the DOI. // Third post call to Zenodo to publish the entry and return the DOI.
publishUrl = links.get("publish") + "?access_token=" + zenodoToken; publishUrl = links.get("publish") + "?access_token=" + zenodoToken;
} else { } else {