Add extraProperties for xml export/import and restore pdf export for zenodo deposit

This commit is contained in:
George Kalampokis 2021-07-06 16:33:46 +03:00
parent d5cd90814a
commit 1c22ed2321
2 changed files with 72 additions and 4 deletions

View File

@ -1292,6 +1292,22 @@ public class DataManagementPlanManager {
dmpName.setTextContent(dmp.getLabel());
dmpElement.appendChild(dmpName);
if (dmp.getExtraProperties() != null && !dmp.getExtraProperties().isEmpty()) {
Map<String, Object> extraProperties = new ObjectMapper().readValue(dmp.getExtraProperties(), HashMap.class);
Element language = xmlDoc.createElement("language");
language.setTextContent(extraProperties.get("language") != null ? extraProperties.get("language").toString() : null);
dmpElement.appendChild(language);
Element visibility = xmlDoc.createElement("visibility");
visibility.setTextContent(extraProperties.get("visible") != null ? extraProperties.get("visible").toString() : null);
dmpElement.appendChild(visibility);
Element publicDate = xmlDoc.createElement("publicDate");
publicDate.setTextContent(extraProperties.get("publicDate") != null ? extraProperties.get("publicDate").toString() : null);
dmpElement.appendChild(publicDate);
Element costs = xmlDoc.createElement("costs");
costs.setTextContent(extraProperties.get("costs") != null ? extraProperties.get("costs").toString() : null);
dmpElement.appendChild(costs);
}
DMPProfile dmpProfile = dmp.getProfile();
Element dmpProfileElement = xmlDoc.createElement("dmpProfile");
Element dmpProfileName = xmlDoc.createElement("dmpProfileName");
@ -1580,6 +1596,21 @@ public class DataManagementPlanManager {
dm.setAssociatedUsers(associatedUsers); // Sets associatedUsers property.
dm.setDynamicFields(dynamicFields); // Sets dynamicFields property.
dm.setDefinition(dmpProfile);
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> extraPropertiesMap = new HashMap<>();
if (dataManagementPlans.get(0).getLanguage() != null) {
extraPropertiesMap.put("language", dataManagementPlans.get(0).getLanguage());
}
if (dataManagementPlans.get(0).getVisibility() != null) {
extraPropertiesMap.put("visible", dataManagementPlans.get(0).getVisibility());
}
if (dataManagementPlans.get(0).getPublicDate() != null) {
extraPropertiesMap.put("publicDate", dataManagementPlans.get(0).getPublicDate());
}
if (dataManagementPlans.get(0).getCosts() != null) {
extraPropertiesMap.put("costs", mapper.readValue(dataManagementPlans.get(0).getCosts(), ArrayList.class));
}
dm.setExtraProperties(extraPropertiesMap);
//createOrUpdate(apiContext, dm, principal);
DMP dmp = this.createOrUpdate(dm, principal);
@ -2081,13 +2112,13 @@ public class DataManagementPlanManager {
if (unpublishedUrl == null) {
// Second step, add the file to the entry.
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);
String fileName = name + ".pdf";*/
FileSystemResource fileSystemResource = new FileSystemResource(file.getFile());
String fileName = name + ".pdf";
FileSystemResource fileSystemResource = new FileSystemResource(pdfFile);
HttpEntity<FileSystemResource> addFileMapRequest = new HttpEntity<>(fileSystemResource, null);
String addFileUrl = links.get("bucket") + "/" + file.getFilename() + "?access_token=" + zenodoToken;
String addFileUrl = links.get("bucket") + "/" + fileName + "?access_token=" + zenodoToken;
restTemplate.put(addFileUrl, addFileMapRequest);
Files.deleteIfExists(file.getFile().toPath());

View File

@ -19,6 +19,10 @@ public class DmpImportModel {
private List<UserInfoImportModels> associatedUsersImportModels;
private List<DynamicFieldWithValueImportModels> dynamicFieldsImportModels;
private List<DatasetImportModels> datasetImportModels;
private String language;
private Boolean visibility;
private String publicDate;
private String costs;
@XmlElement(name = "description")
public String getDescriptionImport() {
@ -113,4 +117,37 @@ public class DmpImportModel {
@XmlElement(name = "dataset")
public List<DatasetImportModels> getDatasetImportModels() { return datasetImportModels; }
public void setDatasetImportModels(List<DatasetImportModels> datasetImportModels) { this.datasetImportModels = datasetImportModels; }
@XmlElement(name = "language")
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
@XmlElement(name = "visibility")
public Boolean getVisibility() {
return visibility;
}
public void setVisibility(Boolean visibility) {
this.visibility = visibility;
}
@XmlElement(name = "publicDate")
public String getPublicDate() {
return publicDate;
}
public void setPublicDate(String publicDate) {
this.publicDate = publicDate;
}
@XmlElement(name = "costs")
public String getCosts() {
return costs;
}
public void setCosts(String costs) {
this.costs = costs;
}
}