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;
|
this.metadata_id_type = metadata_id_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatasetMetadataIdRDAExportModel(String metadata_id, String metadata_id_type) {
|
|
||||||
this.metadata_id = metadata_id;
|
public DatasetMetadataIdRDAExportModel fromDataModel(String key, Object value) {
|
||||||
this.metadata_id_type = metadata_id_type;
|
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;
|
this.metadata_id = metadata_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatasetMetadataRDAExportModel fromDataModel() {
|
public DatasetMetadataRDAExportModel fromDataModel(String key, Object value) {
|
||||||
return this;
|
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 com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.data.entities.Dataset;
|
import eu.eudat.data.entities.Dataset;
|
||||||
import eu.eudat.logic.utilities.builders.XmlBuilder;
|
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.json.JSONObject;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
@ -14,7 +16,7 @@ import java.util.*;
|
||||||
|
|
||||||
public class DatasetRDAExportModel {
|
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 DatasetIdRDAExportModel dataset_id;
|
||||||
private String description;
|
private String description;
|
||||||
|
@ -23,7 +25,7 @@ public class DatasetRDAExportModel {
|
||||||
private String title;
|
private String title;
|
||||||
private String sensitive_data;
|
private String sensitive_data;
|
||||||
private String data_quality_assurance;
|
private String data_quality_assurance;
|
||||||
private DatasetMetadataRDAExportModel metadata;
|
private List<DatasetMetadataRDAExportModel> metadata;
|
||||||
|
|
||||||
public DatasetIdRDAExportModel getDataset_id() {
|
public DatasetIdRDAExportModel getDataset_id() {
|
||||||
return dataset_id;
|
return dataset_id;
|
||||||
|
@ -74,10 +76,10 @@ public class DatasetRDAExportModel {
|
||||||
this.data_quality_assurance = data_quality_assurance;
|
this.data_quality_assurance = data_quality_assurance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatasetMetadataRDAExportModel getMetadata() {
|
public List<DatasetMetadataRDAExportModel> getMetadata() {
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
public void setMetadata(DatasetMetadataRDAExportModel metadata) {
|
public void setMetadata(List<DatasetMetadataRDAExportModel> metadata) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,17 +100,36 @@ public class DatasetRDAExportModel {
|
||||||
Map<String, Object> templateIdsToValues = jObject.toMap();
|
Map<String, Object> templateIdsToValues = jObject.toMap();
|
||||||
|
|
||||||
// Map: rdaProperty -> datasetValue
|
// Map: rdaProperty -> datasetValue
|
||||||
Map<String, Object> rdaToValue = new HashMap<>();
|
MultiValuedMap<String, String> rdaToValueMap = new ArrayListValuedHashMap<>();
|
||||||
for (String templateId : templateIdsToRDAProperties.keySet()) {
|
for (String templateId : templateIdsToRDAProperties.keySet()) {
|
||||||
if (templateIdsToValues.containsKey(templateId))
|
if (templateIdsToValues.containsKey(templateId)) {
|
||||||
rdaToValue.put(templateIdsToRDAProperties.get(templateId), templateIdsToValues.get(templateId));
|
rdaToValueMap.put(templateIdsToRDAProperties.get(templateId), templateIdsToValues.get(templateId).toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DatasetRDAExportModel datasetRDAExportModel = mapper.convertValue(rdaToValue, DatasetRDAExportModel.class);
|
// Creates and fills a map to include metadata keys and values.
|
||||||
datasetRDAExportModel.title = dataset.getLabel();
|
MultiValuedMap<String, String> metadataJsonMap = new ArrayListValuedHashMap<>();
|
||||||
datasetRDAExportModel.issued = dataset.getCreated();
|
for (String key : rdaToValueMap.keySet()) {
|
||||||
datasetRDAExportModel.language = "en"; // mock data;
|
if (key.startsWith("metadata.")) {
|
||||||
datasetRDAExportModel.dataset_id = new DatasetIdRDAExportModel(dataset.getId().toString(), "argos_internal");
|
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;
|
return datasetRDAExportModel;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public class RDAExportModel {
|
||||||
this.dmp = new DmpRDAExportModel().fromDataModel(dmp);
|
this.dmp = new DmpRDAExportModel().fromDataModel(dmp);
|
||||||
this.datasets = new LinkedList<>();
|
this.datasets = new LinkedList<>();
|
||||||
for (Dataset dataset : dmp.getDataset()) {
|
for (Dataset dataset : dmp.getDataset()) {
|
||||||
|
if (dataset.getStatus() != Dataset.Status.DELETED.getValue() && dataset.getStatus() != Dataset.Status.CANCELED.getValue())
|
||||||
this.datasets.add(new DatasetRDAExportModel().fromDataModel(dataset));
|
this.datasets.add(new DatasetRDAExportModel().fromDataModel(dataset));
|
||||||
}
|
}
|
||||||
return this;
|
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
|
ethical_issues_exist
|
||||||
cost
|
cost
|
||||||
cost.title
|
cost.title
|
||||||
|
@ -44,3 +36,4 @@ dataset.metadata.metadata_id.metadata_id
|
||||||
dataset.metadata.metadata_id.metadata_id_type
|
dataset.metadata.metadata_id.metadata_id_type
|
||||||
dataset.security_and_privacy
|
dataset.security_and_privacy
|
||||||
dataset.security_and_privacy.title
|
dataset.security_and_privacy.title
|
||||||
|
dataset.security_and_privacy.description
|
Loading…
Reference in New Issue