Allow zenodo deposits to keep more than one files when creating a new version (ref #221)

This commit is contained in:
George Kalampokis 2020-02-24 09:59:03 +02:00
parent d522bd7c2f
commit 0d59cce33c
2 changed files with 13 additions and 5 deletions

View File

@ -4,7 +4,6 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.eudat</groupId>
<artifactId>data</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

View File

@ -192,6 +192,10 @@ public class DataManagementPlanManager {
}
public File 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 {
WordBuilder wordBuilder = new WordBuilder();
VisibilityRuleService visibilityRuleService = this.utilitiesService.getVisibilityRuleService();
DatasetWizardModel dataset = new DatasetWizardModel();
@ -337,7 +341,12 @@ public class DataManagementPlanManager {
document.removeBodyElement(0);
}
String fileName = dmpEntity.getLabel();
String fileName = "";
if (versioned) {
fileName = dmpEntity.getLabel() + "_v" + dmpEntity.getVersion();
} else {
fileName = dmpEntity.getLabel();
}
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
File exportFile = new File(fileName + ".docx");
FileOutputStream out = new FileOutputStream(exportFile);
@ -1297,7 +1306,7 @@ public class DataManagementPlanManager {
//Third, get the new deposit
String latestDraftUrl = links.get("latest_draft") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
createResponse = restTemplate.getForObject(latestDraftUrl, Map.class);
String fileListUrl = links.get("latest_draft") + "/files" + "?access_token=" + this.environment.getProperty("zenodo.access_token");
/* String fileListUrl = links.get("latest_draft") + "/files" + "?access_token=" + this.environment.getProperty("zenodo.access_token");
try {
//And finally remove pre-existing files from it
ResponseEntity<Map[]> fileListResponse = restTemplate.getForEntity(fileListUrl, Map[].class);
@ -1309,7 +1318,7 @@ public class DataManagementPlanManager {
//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;
}
}*/
}
@ -1318,7 +1327,7 @@ public class DataManagementPlanManager {
fileHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
LinkedMultiValueMap<String, Object> addFileMap = new LinkedMultiValueMap<>();
File file = getWordDocument(id.toString(), principal, configLoader);
File file = getWordDocument(id.toString(), principal, configLoader, true);
addFileMap.add("filename", file.getName());
FileSystemResource fileSystemResource = new FileSystemResource(file);
addFileMap.add("file", fileSystemResource);