|
|
|
@ -201,11 +201,11 @@ public class DataManagementPlanManager {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public File getWordDocument(String id, Principal principal, ConfigLoader configLoader) throws IOException {
|
|
|
|
|
public FileEnvelope getWordDocument(String id, Principal principal, ConfigLoader configLoader) throws IOException {
|
|
|
|
|
return this.getWordDocument(id, principal, configLoader, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public File getWordDocument(String id, Principal principal, ConfigLoader configLoader, Boolean versioned) throws IOException {
|
|
|
|
|
public FileEnvelope getWordDocument(String id, Principal principal, ConfigLoader configLoader, Boolean versioned) throws IOException {
|
|
|
|
|
WordBuilder wordBuilder = new WordBuilder();
|
|
|
|
|
VisibilityRuleService visibilityRuleService = this.utilitiesService.getVisibilityRuleService();
|
|
|
|
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
|
|
|
@ -358,12 +358,16 @@ public class DataManagementPlanManager {
|
|
|
|
|
fileName = dmpEntity.getLabel();
|
|
|
|
|
}
|
|
|
|
|
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
|
|
|
|
File exportFile = new File(this.environment.getProperty("temp.temp") + fileName + ".docx");
|
|
|
|
|
FileEnvelope exportEnvelope = new FileEnvelope();
|
|
|
|
|
exportEnvelope.setFilename(fileName + ".docx");
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
File exportFile = new File(this.environment.getProperty("temp.temp") + uuid + ".docx");
|
|
|
|
|
FileOutputStream out = new FileOutputStream(exportFile);
|
|
|
|
|
document.write(out);
|
|
|
|
|
out.close();
|
|
|
|
|
exportEnvelope.setFile(exportFile);
|
|
|
|
|
|
|
|
|
|
return exportFile;
|
|
|
|
|
return exportEnvelope;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*public File getPdfDocument(String id) throws InstantiationException, IllegalAccessException, InterruptedException, IOException {
|
|
|
|
@ -999,9 +1003,10 @@ public class DataManagementPlanManager {
|
|
|
|
|
if (!dmp.isPublic() && dmp.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
|
|
|
|
|
throw new UnauthorisedException();
|
|
|
|
|
List<Dataset> datasets = dmp.getDataset().stream().collect(Collectors.toList());
|
|
|
|
|
String fileName = dmp.getLabel();
|
|
|
|
|
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
|
|
|
|
File xmlFile = new File(this.environment.getProperty("temp.temp") + fileName + ".xml");
|
|
|
|
|
/*String fileName = dmp.getLabel();
|
|
|
|
|
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");*/
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
File xmlFile = new File(this.environment.getProperty("temp.temp") + uuid + ".xml");
|
|
|
|
|
BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true));
|
|
|
|
|
Document xmlDoc = XmlBuilder.getDocument();
|
|
|
|
|
Element dmpElement = xmlDoc.createElement("dmp");
|
|
|
|
@ -1122,7 +1127,7 @@ public class DataManagementPlanManager {
|
|
|
|
|
writer.close();
|
|
|
|
|
FileEnvelope fileEnvelope = new FileEnvelope();
|
|
|
|
|
fileEnvelope.setFile(xmlFile);
|
|
|
|
|
fileEnvelope.setFilename(dmp.getLabel());
|
|
|
|
|
fileEnvelope.setFilename(dmp.getLabel() + ".xml");
|
|
|
|
|
|
|
|
|
|
return fileEnvelope;
|
|
|
|
|
}
|
|
|
|
@ -1138,7 +1143,8 @@ public class DataManagementPlanManager {
|
|
|
|
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
|
|
|
|
String fileName = dmp.getLabel();
|
|
|
|
|
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
|
|
|
|
File file = new File(this.environment.getProperty("temp.temp") + fileName + ".json");
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
File file = new File(this.environment.getProperty("temp.temp") + uuid + ".json");
|
|
|
|
|
OutputStream output = new FileOutputStream(file);
|
|
|
|
|
try {
|
|
|
|
|
// mapper.writeValue(file, rdaExportModel);
|
|
|
|
@ -1153,7 +1159,7 @@ public class DataManagementPlanManager {
|
|
|
|
|
HttpHeaders responseHeaders = new HttpHeaders();
|
|
|
|
|
responseHeaders.setContentLength(file.length());
|
|
|
|
|
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
|
|
responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getName());
|
|
|
|
|
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName + ".json");
|
|
|
|
|
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
|
|
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
|
|
|
|
|
|
|
|
@ -1164,28 +1170,28 @@ public class DataManagementPlanManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResponseEntity<byte[]> getDocument(String id, String contentType, Principal principal, ConfigLoader configLoader) throws InstantiationException, IllegalAccessException, IOException {
|
|
|
|
|
File file;
|
|
|
|
|
FileEnvelope file;
|
|
|
|
|
switch (contentType) {
|
|
|
|
|
case "application/xml":
|
|
|
|
|
file = getXmlDocument(id, principal).getFile();
|
|
|
|
|
file = getXmlDocument(id, principal);
|
|
|
|
|
break;
|
|
|
|
|
case "application/msword":
|
|
|
|
|
file = getWordDocument(id, principal, configLoader);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
file = getXmlDocument(id, principal).getFile();
|
|
|
|
|
file = getXmlDocument(id, principal);
|
|
|
|
|
}
|
|
|
|
|
InputStream resource = new FileInputStream(file);
|
|
|
|
|
InputStream resource = new FileInputStream(file.getFile());
|
|
|
|
|
HttpHeaders responseHeaders = new HttpHeaders();
|
|
|
|
|
responseHeaders.setContentLength(file.length());
|
|
|
|
|
responseHeaders.setContentLength(file.getFile().length());
|
|
|
|
|
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
|
|
responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getName());
|
|
|
|
|
responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getFilename());
|
|
|
|
|
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
|
|
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
|
|
|
|
|
|
|
|
|
byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource);
|
|
|
|
|
resource.close();
|
|
|
|
|
Files.deleteIfExists(file.toPath());
|
|
|
|
|
Files.deleteIfExists(file.getFile().toPath());
|
|
|
|
|
return new ResponseEntity<>(content,
|
|
|
|
|
responseHeaders,
|
|
|
|
|
HttpStatus.OK);
|
|
|
|
@ -1564,15 +1570,15 @@ public class DataManagementPlanManager {
|
|
|
|
|
fileHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
|
|
LinkedMultiValueMap<String, Object> addFileMap = new LinkedMultiValueMap<>();
|
|
|
|
|
|
|
|
|
|
File file = getWordDocument(id.toString(), principal, configLoader);
|
|
|
|
|
addFileMap.add("filename", file.getName());
|
|
|
|
|
FileSystemResource fileSystemResource = new FileSystemResource(file);
|
|
|
|
|
FileEnvelope file = getWordDocument(id.toString(), principal, configLoader);
|
|
|
|
|
addFileMap.add("filename", file.getFilename());
|
|
|
|
|
FileSystemResource fileSystemResource = new FileSystemResource(file.getFile());
|
|
|
|
|
addFileMap.add("file", fileSystemResource);
|
|
|
|
|
HttpEntity<MultiValueMap<String, Object>> addFileMapRequest = new HttpEntity<>(addFileMap, fileHeaders);
|
|
|
|
|
|
|
|
|
|
String addFileUrl = links.get("files") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
|
|
|
|
ResponseEntity<String> addFileResponse = restTemplate.postForEntity(addFileUrl, addFileMapRequest, String.class);
|
|
|
|
|
Files.deleteIfExists(file.toPath());
|
|
|
|
|
Files.deleteIfExists(file.getFile().toPath());
|
|
|
|
|
|
|
|
|
|
// Third post call to Zenodo to publish the entry and return the DOI.
|
|
|
|
|
String publishUrl = links.get("publish") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
|
|
|
|