Refactors RDA export to accept more than one metadata values and fixes bug on exporting deleted and canceled Datasets.
This commit is contained in:
parent
9b23f467a7
commit
1438f6bdca
|
@ -18,8 +18,14 @@ public class DatasetMetadataIdRDAExportModel {
|
|||
this.metadata_id_type = metadata_id_type;
|
||||
}
|
||||
|
||||
public DatasetMetadataIdRDAExportModel(String metadata_id, String metadata_id_type) {
|
||||
this.metadata_id = metadata_id;
|
||||
this.metadata_id_type = metadata_id_type;
|
||||
|
||||
public DatasetMetadataIdRDAExportModel fromDataModel(String key, Object value) {
|
||||
DatasetMetadataIdRDAExportModel metadataIdRDAExportModel = new DatasetMetadataIdRDAExportModel();
|
||||
if (key.contains(".metadata_id"))
|
||||
metadataIdRDAExportModel.setMetadata_id(value.toString());
|
||||
else if (key.contains(".metadata_id_type"))
|
||||
metadataIdRDAExportModel.setMetadata_id_type(value.toString());
|
||||
|
||||
return metadataIdRDAExportModel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,15 @@ public class DatasetMetadataRDAExportModel {
|
|||
this.metadata_id = metadata_id;
|
||||
}
|
||||
|
||||
public DatasetMetadataRDAExportModel fromDataModel() {
|
||||
return this;
|
||||
public DatasetMetadataRDAExportModel fromDataModel(String key, Object value) {
|
||||
DatasetMetadataRDAExportModel metadataRDAExportModel = new DatasetMetadataRDAExportModel();
|
||||
if (key.contains("metadata_id"))
|
||||
metadataRDAExportModel.setMetadata_id(new DatasetMetadataIdRDAExportModel().fromDataModel(key, value));
|
||||
else if (key.contains("language"))
|
||||
metadataRDAExportModel.setLanguage(value.toString());
|
||||
else if (key.contains("description"))
|
||||
metadataRDAExportModel.setDescription(value.toString());
|
||||
|
||||
return metadataRDAExportModel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.data.entities.Dataset;
|
||||
import eu.eudat.logic.utilities.builders.XmlBuilder;
|
||||
import org.apache.commons.collections4.MultiValuedMap;
|
||||
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
|
||||
import org.json.JSONObject;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -14,7 +16,7 @@ import java.util.*;
|
|||
|
||||
public class DatasetRDAExportModel {
|
||||
|
||||
private static final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);;
|
||||
private static final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
private DatasetIdRDAExportModel dataset_id;
|
||||
private String description;
|
||||
|
@ -23,7 +25,7 @@ public class DatasetRDAExportModel {
|
|||
private String title;
|
||||
private String sensitive_data;
|
||||
private String data_quality_assurance;
|
||||
private DatasetMetadataRDAExportModel metadata;
|
||||
private List<DatasetMetadataRDAExportModel> metadata;
|
||||
|
||||
public DatasetIdRDAExportModel getDataset_id() {
|
||||
return dataset_id;
|
||||
|
@ -74,10 +76,10 @@ public class DatasetRDAExportModel {
|
|||
this.data_quality_assurance = data_quality_assurance;
|
||||
}
|
||||
|
||||
public DatasetMetadataRDAExportModel getMetadata() {
|
||||
public List<DatasetMetadataRDAExportModel> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
public void setMetadata(DatasetMetadataRDAExportModel metadata) {
|
||||
public void setMetadata(List<DatasetMetadataRDAExportModel> metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
|
@ -98,17 +100,36 @@ public class DatasetRDAExportModel {
|
|||
Map<String, Object> templateIdsToValues = jObject.toMap();
|
||||
|
||||
// Map: rdaProperty -> datasetValue
|
||||
Map<String, Object> rdaToValue = new HashMap<>();
|
||||
MultiValuedMap<String, String> rdaToValueMap = new ArrayListValuedHashMap<>();
|
||||
for (String templateId : templateIdsToRDAProperties.keySet()) {
|
||||
if (templateIdsToValues.containsKey(templateId))
|
||||
rdaToValue.put(templateIdsToRDAProperties.get(templateId), templateIdsToValues.get(templateId));
|
||||
if (templateIdsToValues.containsKey(templateId)) {
|
||||
rdaToValueMap.put(templateIdsToRDAProperties.get(templateId), templateIdsToValues.get(templateId).toString());
|
||||
}
|
||||
}
|
||||
|
||||
DatasetRDAExportModel datasetRDAExportModel = mapper.convertValue(rdaToValue, DatasetRDAExportModel.class);
|
||||
datasetRDAExportModel.title = dataset.getLabel();
|
||||
datasetRDAExportModel.issued = dataset.getCreated();
|
||||
datasetRDAExportModel.language = "en"; // mock data;
|
||||
datasetRDAExportModel.dataset_id = new DatasetIdRDAExportModel(dataset.getId().toString(), "argos_internal");
|
||||
// Creates and fills a map to include metadata keys and values.
|
||||
MultiValuedMap<String, String> metadataJsonMap = new ArrayListValuedHashMap<>();
|
||||
for (String key : rdaToValueMap.keySet()) {
|
||||
if (key.startsWith("metadata.")) {
|
||||
metadataJsonMap.putAll(key.replace("metadata.", ""), rdaToValueMap.get(key));
|
||||
}
|
||||
}
|
||||
// Removes metadata keys from rdaToValueMap.
|
||||
for (String metadataKey : metadataJsonMap.keySet()) rdaToValueMap.remove(metadataKey);
|
||||
|
||||
DatasetRDAExportModel datasetRDAExportModel = mapper.convertValue(rdaToValueMap, DatasetRDAExportModel.class);
|
||||
datasetRDAExportModel.setTitle(dataset.getLabel());
|
||||
datasetRDAExportModel.setIssued(dataset.getCreated());
|
||||
datasetRDAExportModel.setLanguage("en"); // mock data;
|
||||
datasetRDAExportModel.setDataset_id(new DatasetIdRDAExportModel(dataset.getId().toString(), "argos_internal"));
|
||||
|
||||
List<DatasetMetadataRDAExportModel> datasetMetadataRDAExportModels = new LinkedList<>();
|
||||
for (String key : metadataJsonMap.keySet()) {
|
||||
for (String value : metadataJsonMap.get(key)) {
|
||||
datasetMetadataRDAExportModels.add(new DatasetMetadataRDAExportModel().fromDataModel(key,value));
|
||||
}
|
||||
}
|
||||
datasetRDAExportModel.setMetadata(datasetMetadataRDAExportModels);
|
||||
|
||||
return datasetRDAExportModel;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ public class RDAExportModel {
|
|||
this.dmp = new DmpRDAExportModel().fromDataModel(dmp);
|
||||
this.datasets = new LinkedList<>();
|
||||
for (Dataset dataset : dmp.getDataset()) {
|
||||
this.datasets.add(new DatasetRDAExportModel().fromDataModel(dataset));
|
||||
if (dataset.getStatus() != Dataset.Status.DELETED.getValue() && dataset.getStatus() != Dataset.Status.CANCELED.getValue())
|
||||
this.datasets.add(new DatasetRDAExportModel().fromDataModel(dataset));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
dmp
|
||||
dmp_id
|
||||
dmp_id.dmp_id
|
||||
dmp_id.dmp_id_type
|
||||
title
|
||||
created
|
||||
modified
|
||||
language
|
||||
ethical_issues_exist
|
||||
cost
|
||||
cost.title
|
||||
|
@ -43,4 +35,5 @@ dataset.metadata.metadata_id
|
|||
dataset.metadata.metadata_id.metadata_id
|
||||
dataset.metadata.metadata_id.metadata_id_type
|
||||
dataset.security_and_privacy
|
||||
dataset.security_and_privacy.title
|
||||
dataset.security_and_privacy.title
|
||||
dataset.security_and_privacy.description
|
Loading…
Reference in New Issue