Update Zenodo's file API
This commit is contained in:
parent
fa86258197
commit
e1368e270a
|
@ -1901,23 +1901,17 @@ public class DataManagementPlanManager {
|
|||
if (!update) {
|
||||
if (unpublishedUrl == null) {
|
||||
// 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);
|
||||
String name = file.getFilename().substring(0, file.getFilename().length() - 5);
|
||||
File pdfFile = datasetManager.convertToPDF(file, environment);
|
||||
addFileMap.add("filename", name + ".pdf");
|
||||
String fileName = name + ".pdf";
|
||||
FileSystemResource fileSystemResource = new FileSystemResource(pdfFile);
|
||||
addFileMap.add("file", fileSystemResource);
|
||||
HttpEntity<MultiValueMap<String, Object>> addFileMapRequest = new HttpEntity<>(addFileMap, fileHeaders);
|
||||
HttpEntity<FileSystemResource> addFileMapRequest = new HttpEntity<>(fileSystemResource, null);
|
||||
|
||||
String addFileUrl = links.get("files") + "?access_token=" + zenodoToken;
|
||||
ResponseEntity<String> addFileResponse = restTemplate.postForEntity(addFileUrl, addFileMapRequest, String.class);
|
||||
String addFileUrl = links.get("bucket") + "/" + fileName + "?access_token=" + zenodoToken;
|
||||
restTemplate.put(addFileUrl, addFileMapRequest);
|
||||
Files.deleteIfExists(file.getFile().toPath());
|
||||
|
||||
|
||||
// Third post call to Zenodo to publish the entry and return the DOI.
|
||||
publishUrl = links.get("publish") + "?access_token=" + zenodoToken;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue