From 3765d7cc9f4980debbbce32a21d39c2de61c14a9 Mon Sep 17 00:00:00 2001 From: gkolokythas Date: Wed, 11 Dec 2019 12:48:13 +0200 Subject: [PATCH] Refactors RDA export for DMP. --- .../main/java/eu/eudat/controllers/DMPs.java | 2 +- .../eudat/logic/managers/DatasetManager.java | 2 +- .../rda/DatasetMetadataIdRDAExportModel.java | 31 -- .../rda/DatasetMetadataRDAExportModel.java | 9 +- .../data/rda/DatasetRDAExportModel.java | 410 ++++++++++++------ ...tasetSecurityAndPrivacyRDAExportModel.java | 18 +- ...atasetTechnicalResourceRDAExportModel.java | 15 +- .../models/data/rda/DmpRDAExportModel.java | 9 +- .../eudat/models/data/rda/RDAExportModel.java | 5 +- .../eu/eudat/models/data/rda/RdaField.java | 36 ++ .../user/components/datasetprofile/Field.java | 12 + .../src/main/resources/RDACommonStandards.txt | 1 + 12 files changed, 358 insertions(+), 192 deletions(-) delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataIdRDAExportModel.java create mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RdaField.java diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java index 5208e5d43..beca226a5 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java @@ -110,7 +110,7 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.GET, value = {"rda/{id}"}) public @ResponseBody ResponseEntity getRDAJsonDocument(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IOException { - return this.dataManagementPlanManager.getRDAJsonDocument(id, principal); + return this.dataManagementPlanManager.getRDAJsonDocument(id, datasetManager, principal); } @RequestMapping(method = RequestMethod.GET, value = {"/overview/{id}"}) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index 5b04ef777..3a1d2e8f8 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -172,7 +172,7 @@ public class DatasetManager { return dataTable; } - public DatasetWizardModel getSingle(String id) throws InstantiationException, IllegalAccessException, IOException { + public DatasetWizardModel getSingle(String id) { DatasetWizardModel dataset = new DatasetWizardModel(); eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); eu.eudat.elastic.entities.Dataset datasetElastic; diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataIdRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataIdRDAExportModel.java deleted file mode 100644 index f6b3130ba..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataIdRDAExportModel.java +++ /dev/null @@ -1,31 +0,0 @@ -package eu.eudat.models.data.rda; - -public class DatasetMetadataIdRDAExportModel { - private String metadata_id; - private String metadata_id_type; - - public String getMetadata_id() { - return metadata_id; - } - public void setMetadata_id(String metadata_id) { - this.metadata_id = metadata_id; - } - - public String getMetadata_id_type() { - return metadata_id_type; - } - public void setMetadata_id_type(String metadata_id_type) { - 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; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataRDAExportModel.java index dc5814375..2b5da6abd 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataRDAExportModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataRDAExportModel.java @@ -1,5 +1,7 @@ package eu.eudat.models.data.rda; +import com.fasterxml.jackson.annotation.JsonIgnore; + public class DatasetMetadataRDAExportModel { private String description; // Not mandatory. private String language; @@ -29,7 +31,7 @@ public class DatasetMetadataRDAExportModel { public DatasetMetadataRDAExportModel fromDataModel(String key, Object value) { DatasetMetadataRDAExportModel metadataRDAExportModel = new DatasetMetadataRDAExportModel(); if (key.contains("metadata_standard_id")) - metadataRDAExportModel.setMetadata_standard_id(new IdRDAExportModel(value.toString(), value.toString())); + metadataRDAExportModel.setMetadata_standard_id(new IdRDAExportModel(value.toString(), "other")); else if (key.contains("language")) metadataRDAExportModel.setLanguage(value.toString()); else if (key.contains("description")) @@ -37,4 +39,9 @@ public class DatasetMetadataRDAExportModel { return metadataRDAExportModel; } + + @JsonIgnore + public boolean isValid() { + return description != null || language != null || metadata_standard_id != null; + } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java index 0c94ad88a..71705b859 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java @@ -1,12 +1,13 @@ package eu.eudat.models.data.rda; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.jayway.jsonpath.JsonPath; import eu.eudat.data.entities.Dataset; +import eu.eudat.logic.managers.DatasetManager; import eu.eudat.logic.utilities.builders.XmlBuilder; -import org.apache.commons.collections4.MultiValuedMap; -import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; -import org.apache.poi.ss.formula.functions.T; +import org.json.JSONArray; import org.json.JSONObject; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -16,12 +17,14 @@ import javax.xml.xpath.*; import java.text.DateFormat; import java.util.*; +import static java.util.stream.Collectors.groupingBy; + public class DatasetRDAExportModel { private static final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - private MultiValuedMap rdaToValueMap; + private Map multiplicityIdToFieldSetId = new HashMap<>(); - private String data_quality_assurance; + private List data_quality_assurance; private IdRDAExportModel dataset_id; private String description; private List distribution; @@ -37,10 +40,10 @@ public class DatasetRDAExportModel { private String title; private String type; // Type according to: http://vocabularies.coar-repositories.org/pubby/resource_type.html - public String getData_quality_assurance() { + public List getData_quality_assurance() { return data_quality_assurance; } - public void setData_quality_assurance(String data_quality_assurance) { + public void setData_quality_assurance(List data_quality_assurance) { this.data_quality_assurance = data_quality_assurance; } @@ -143,28 +146,280 @@ public class DatasetRDAExportModel { } - public DatasetRDAExportModel fromDataModel(Dataset dataset) { - this.rdaToValueMap = getRdaValueMap(dataset); - List distributions = getDatasetDistribution(); - List datasetMetadata = getDatasetMetadata(); - List securityAndPrivacy = getSecurityAndPrivacy(); - List technicalResources = getTechnicalResource(); + public DatasetRDAExportModel fromDataModel(Dataset dataset, DatasetManager datasetManager) { + // Map of template Ids to rda values. + JSONObject jObject = new JSONObject(dataset.getProperties()); + Map templateIdsToValues = jObject.toMap(); - DatasetRDAExportModel datasetRDAExportModel = mapper.convertValue(this.rdaToValueMap, DatasetRDAExportModel.class); + /*--------- Building dataset rda export model ---------*/ + DatasetRDAExportModel datasetRDAExportModel = new DatasetRDAExportModel(); datasetRDAExportModel.setDataset_id(new IdRDAExportModel(dataset.getId().toString(), "other")); - datasetRDAExportModel.setDescription(dataset.getDescription()); + if (dataset.getDescription() != null) datasetRDAExportModel.setDescription(dataset.getDescription().replace("\n", " ")); datasetRDAExportModel.setIssued(DateFormat.getDateInstance(DateFormat.SHORT).format(dataset.getCreated())); - datasetRDAExportModel.setLanguage("en"); // mock data; + datasetRDAExportModel.setLanguage("en"); // mock data datasetRDAExportModel.setTitle(dataset.getLabel()); - datasetRDAExportModel.setDistribution(distributions); - datasetRDAExportModel.setMetadata(datasetMetadata); - datasetRDAExportModel.setSecurity_and_privacy(securityAndPrivacy); - datasetRDAExportModel.setTechnical_resource(technicalResources); + + // Transform the answered dataset description to json so we can parse it and fill the rda model. + JSONObject datasetDescriptionJson = null; + try { + String jsonResult = mapper.writeValueAsString(datasetManager.getSingle(dataset.getId().toString()).getDatasetProfileDefinition()); + datasetDescriptionJson = new JSONObject(jsonResult); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + setMultiplicityIdToFieldSetId(datasetDescriptionJson); + + /*--------- Building personal data. ---------*/ + String personalData = buildSingleProperties("dataset.personal_data", datasetDescriptionJson, templateIdsToValues); + if (personalData != null) { + datasetRDAExportModel.setPersonal_data(personalData); + } else { + datasetRDAExportModel.setPersonal_data("unknown"); + } + + /*--------- Building preservation statement. ---------*/ + datasetRDAExportModel.setPreservation_statement(buildSingleProperties("dataset.preservation_statement", datasetDescriptionJson, templateIdsToValues)); + + /*--------- Building sensitive data. ---------*/ + String sensitiveData = buildSingleProperties("dataset.sensitive_data", datasetDescriptionJson, templateIdsToValues); + if (personalData != null) { + datasetRDAExportModel.setSensitive_data(sensitiveData); + } else { + datasetRDAExportModel.setSensitive_data("unknown"); + } + + /*--------- Building type. ---------*/ + datasetRDAExportModel.setType(buildSingleProperties("dataset.type", datasetDescriptionJson, templateIdsToValues)); + + /*--------- Building data_quality_assurance. ---------*/ + datasetRDAExportModel.setData_quality_assurance(buildDataQualityAssurance(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); + + /*--------- Building keywords. ---------*/ + datasetRDAExportModel.setKeyword(buildKeywords(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); + + /*--------- Building metadata items. ---------*/ + datasetRDAExportModel.setMetadata(buildMetadata(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); + + /*--------- Building security and privacy items. ---------*/ + datasetRDAExportModel.setSecurity_and_privacy(buildSecurityAndPrivacy(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); + + /*--------- Building technical_resource. ---------*/ + datasetRDAExportModel.setTechnical_resource(buildTechnicalResource(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); return datasetRDAExportModel; } - private List xmlNodeListFromExpression(String xml, String expression) { + private String buildSingleProperties(String rdaKey, JSONObject datasetDescriptionJson, Map templateIdsToValues) { + String expression = "$..fields[*][?(@.rdaProperty == \"" + rdaKey + "\" )].id"; + List list = jsonValueListFromExpression(datasetDescriptionJson, expression); + if (!list.isEmpty()) { + return templateIdsToValues.get(list.get(0)).toString(); + } else { + return null; + } + } + + private List buildDataQualityAssurance(JSONObject datasetDescriptionJson, Map templateIdsToValues, String datasetProfileDefinition) { + List dataQualityFields = getRDAFieldsFromJson(datasetDescriptionJson, new String[]{"dataset.data_quality_assurance"}, datasetProfileDefinition); + for (RdaField rdaField : dataQualityFields) { + rdaField.setRdaValue(templateIdsToValues.get(rdaField.getFieldId()).toString()); + } + List dataQualityAssuranceList = new LinkedList<>(); + for (RdaField rdaField : dataQualityFields) { + dataQualityAssuranceList.add(rdaField.getRdaValue()); + } + + return dataQualityAssuranceList; + } + + private List buildKeywords(JSONObject datasetDescriptionJson, Map templateIdsToValues, String datasetProfileDefinition) { + List keywordFields = getRDAFieldsFromJson(datasetDescriptionJson, new String[]{"dataset.keyword"}, datasetProfileDefinition); + for (RdaField rdaField : keywordFields) { + rdaField.setRdaValue(templateIdsToValues.get(rdaField.getFieldId()).toString()); + } + List keywordsList = new LinkedList<>(); + for (RdaField rdaField : keywordFields) { + keywordsList.add(rdaField.getRdaValue()); + } + + return keywordsList; + } + + private List buildMetadata(JSONObject datasetDescriptionJson, Map templateIdsToValues, String datasetProfileDefinition) { + List metadataFields = getRDAFieldsFromJson(datasetDescriptionJson, + new String[]{"dataset.metadata.metadata_standard_id.type", "dataset.metadata.metadata_standard_id.identifier", "dataset.metadata.description", "dataset.metadata.language", "dataset.metadata.metadata_standard_id"}, + datasetProfileDefinition); + + // Adding rdaValue and FieldSetIds on metadataFields. + for (RdaField rdaField : metadataFields) { + rdaField.setRdaValue(templateIdsToValues.get(rdaField.getFieldId()).toString()); + } + // Group metadataFields based on their field set id. + Map> groupedMetadataFields = metadataFields.stream().collect(groupingBy(RdaField::getFieldSetId)); + + // Creating the metadata. + List metadataRDAExportModelList = new LinkedList<>(); + for (String fieldSetId : groupedMetadataFields.keySet()) { + DatasetMetadataRDAExportModel metadataRda = new DatasetMetadataRDAExportModel(); + for (RdaField rdaField : groupedMetadataFields.get(fieldSetId)) { + if (rdaField.getRdaProperty().equals("dataset.metadata.metadata_standard_id.identifier")) { + if (metadataRda.getMetadata_standard_id() != null) { + metadataRda.getMetadata_standard_id().setIdentifier(rdaField.getRdaValue()); + } else { + metadataRda.setMetadata_standard_id(new IdRDAExportModel(rdaField.getRdaValue(), "other")); + } + } + if (rdaField.getRdaProperty().equals("dataset.metadata.metadata_standard_id.type")) { + if (metadataRda.getMetadata_standard_id() != null) { + metadataRda.getMetadata_standard_id().setType(rdaField.getRdaValue()); + } else { + metadataRda.setMetadata_standard_id(new IdRDAExportModel("", rdaField.getRdaValue())); + } + } + if (rdaField.getRdaProperty().equals("dataset.metadata.description")) { + metadataRda.setDescription(rdaField.getRdaValue()); + } + if (rdaField.getRdaProperty().equals("dataset.metadata.language")) { + metadataRda.setLanguage(rdaField.getRdaValue()); + } + if (rdaField.getRdaProperty().equals("dataset.metadata.metadata_standard_id")) { + JSONArray jsonArray = new JSONArray(rdaField.getRdaValue()); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + Map jsonObjectMap = jsonObject.toMap(); + DatasetMetadataRDAExportModel metadataRda1 = new DatasetMetadataRDAExportModel(); + metadataRda1.setMetadata_standard_id(new IdRDAExportModel(jsonObjectMap.get("label").toString(), jsonObjectMap.get("source").toString())); + metadataRDAExportModelList.add(metadataRda1); + } + } + } + if (metadataRda.isValid()) { + metadataRDAExportModelList.add(metadataRda); + } + } + + return new LinkedList<>(metadataRDAExportModelList); + } + + private List buildSecurityAndPrivacy(JSONObject datasetDescriptionJson, Map templateIdsToValues, String datasetProfileDefinition) { + List secAndPrFields = getRDAFieldsFromJson( + datasetDescriptionJson, + new String[]{"dataset.security_and_privacy.description", "dataset.security_and_privacy.title", "dataset.security_and_privacy"}, + datasetProfileDefinition); + for (RdaField rdaField : secAndPrFields) { + rdaField.setRdaValue(templateIdsToValues.get(rdaField.getFieldId()).toString()); + } + Map> groupedSecurityAndPrivacyFields = secAndPrFields.stream().collect(groupingBy(RdaField::getFieldSetId)); + + List securityAndPrivacyRDAExportModelList = new LinkedList<>(); + for (String fieldSetId : groupedSecurityAndPrivacyFields.keySet()) { + DatasetSecurityAndPrivacyRDAExportModel securityAndPrivacyModel = new DatasetSecurityAndPrivacyRDAExportModel(); + for (RdaField rdaField : groupedSecurityAndPrivacyFields.get(fieldSetId)) { + if (rdaField.getRdaProperty().equals("dataset.security_and_privacy.description")) { + securityAndPrivacyModel.setDescription(rdaField.getRdaValue()); + } + if (rdaField.getRdaProperty().equals("dataset.security_and_privacy.title")) { + securityAndPrivacyModel.setTitle(rdaField.getRdaValue()); + } + if (rdaField.getRdaProperty().equals("dataset.security_and_privacy")) { + JSONArray jsonArray = new JSONArray(rdaField.getRdaValue()); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + Map jsonObjectMap = jsonObject.toMap(); + DatasetSecurityAndPrivacyRDAExportModel secAndPrivacy = new DatasetSecurityAndPrivacyRDAExportModel(jsonObjectMap.get("label").toString(), jsonObjectMap.get("source").toString()); + securityAndPrivacyRDAExportModelList.add(secAndPrivacy); + } + } + } + securityAndPrivacyRDAExportModelList.add(securityAndPrivacyModel); + } + + return securityAndPrivacyRDAExportModelList; + } + + private List buildTechnicalResource(JSONObject datasetDescriptionJson, Map templateIdsToValues, String datasetProfileDefinition) { + List dataQualityFields = getRDAFieldsFromJson(datasetDescriptionJson, + new String[]{"dataset.technical_resource.technical_resource", "dataset.technical_resource.technical_resource.description", "dataset.technical_resource.technical_resource.name"}, + datasetProfileDefinition); + for (RdaField rdaField : dataQualityFields) { + rdaField.setRdaValue(templateIdsToValues.get(rdaField.getFieldId()).toString()); + } + List technicalResourceList = new LinkedList<>(); + Map> groupedDataQualityFields = dataQualityFields.stream().collect(groupingBy(RdaField::getFieldSetId)); + for (String fieldSetId : groupedDataQualityFields.keySet()) { + DatasetTechnicalResourceRDAExportModel technicalResourceModel = new DatasetTechnicalResourceRDAExportModel(); + for (RdaField rdaField : groupedDataQualityFields.get(fieldSetId)) { + if (rdaField.getRdaProperty().equals("dataset.technical_resource.technical_resource.description")) { + technicalResourceModel.setDescription(rdaField.getRdaValue()); + } + if (rdaField.getRdaProperty().equals("dataset.technical_resource.technical_resource.name")) { + technicalResourceModel.setName(rdaField.getRdaValue()); + } + if (rdaField.getRdaProperty().equals("dataset.security_and_privacy")) { + JSONArray jsonArray = new JSONArray(rdaField.getRdaValue()); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + Map jsonObjectMap = jsonObject.toMap(); + DatasetTechnicalResourceRDAExportModel technicalResource = new DatasetTechnicalResourceRDAExportModel(jsonObjectMap.get("label").toString(), jsonObjectMap.get("label").toString()); + technicalResourceList.add(technicalResource); + } + } + } + technicalResourceList.add(technicalResourceModel); + } + + return technicalResourceList; + } + + private void setMultiplicityIdToFieldSetId(JSONObject json) { + String multiplicityItemsFieldSetIdExp = "$..multiplicityItems[*].id"; + List multiplicityItemsFieldSetIdList = jsonValueListFromExpression(json, multiplicityItemsFieldSetIdExp); + for (String fieldSetId : multiplicityItemsFieldSetIdList) { + String fieldsFromFieldSetIdExp = "$..multiplicityItems[*][?(@.id == \""+ fieldSetId +"\")].fields[*].id"; + List fieldsIdList = jsonValueListFromExpression(json, fieldsFromFieldSetIdExp); + for (String fieldId : fieldsIdList) { + this.multiplicityIdToFieldSetId.put(fieldId, fieldSetId); + } + } + } + + private List getRDAFieldsFromJson(JSONObject json, String[] rdaKey, String datasetProfileDefinition) { + List rdaFields = new LinkedList<>(); + for (String key : rdaKey) { + String fieldIdExpression = "$..fields[*][?(@.rdaProperty == \"" + key + "\" )].id"; + List listFromExpression = jsonValueListFromExpression(json, fieldIdExpression); + for (String fieldId : listFromExpression) { + RdaField rdaField = new RdaField(); + rdaField.setRdaProperty(key); + rdaField.setFieldId(fieldId); + if (fieldId.startsWith("multiple_")) { + rdaField.setFieldSetId(this.multiplicityIdToFieldSetId.get(fieldId)); + } else { + rdaField.setFieldSetId(getFieldSetIdForFieldFromXML(datasetProfileDefinition, fieldId)); + } + rdaFields.add(rdaField); + } + } + return rdaFields; + } + + private List jsonValueListFromExpression(JSONObject json, String expression) { + net.minidev.json.JSONArray jsonArray = JsonPath.parse(json.toString()).read(expression); + List valueList = new LinkedList<>(); + for (Object o : jsonArray) { + valueList.add(o.toString()); + } + return valueList; + } + + private String getFieldSetIdForFieldFromXML(String datasetProfileDefinition, String fieldId) { + String fieldSetIdExpression = "//field[@id ='" + fieldId + "']/ancestor::fieldSet/@id"; + List listFromExpression = xmlValueListFromExpression(datasetProfileDefinition, fieldSetIdExpression); + if (listFromExpression.size() == 1) return listFromExpression.get(0); + return null; + } + + private List xmlValueListFromExpression(String xml, String expression) { List valuesList = new LinkedList<>(); Document document = XmlBuilder.fromXml(xml); XPathFactory xpathFactory = XPathFactory.newInstance(); @@ -182,117 +437,4 @@ public class DatasetRDAExportModel { return valuesList; } - - private Map combineListsIntoOrderedMap (List keys, List values) { - if (keys.size() != values.size()) - throw new IllegalArgumentException ("Cannot combine lists with dissimilar sizes"); - Map map = new LinkedHashMap<>(); - for (int i=0; i getRdaValueMap(Dataset dataset) { - // Parsing dataset template definition to create a map of which question of the template corresponds to the RDA common standard. Map: TemplateId -> rdaProperty - List rdaPropertiesThatExistOnDatasetTemplate = xmlNodeListFromExpression(dataset.getProfile().getDefinition(), "//rdaCommonStandard/text()"); - List rdaProperties = new LinkedList<>(); - for (String item : rdaPropertiesThatExistOnDatasetTemplate) { - item = item.replace("dataset.", ""); - rdaProperties.add(item); - } - List datasetTemplateIdsWithRdaProperties = xmlNodeListFromExpression(dataset.getProfile().getDefinition(), "//rdaCommonStandard/text()/ancestor::field/@id"); - Map templateIdsToRDAProperties = combineListsIntoOrderedMap(datasetTemplateIdsWithRdaProperties, rdaProperties); - - // Parsing dataset answers from json to map. Map: TemplateId -> datasetValue - JSONObject jObject = new JSONObject(dataset.getProperties()); - Map templateIdsToValues = jObject.toMap(); - - // Map: rdaProperty -> datasetValue - MultiValuedMap rdaToValueMap = new ArrayListValuedHashMap<>(); - for (String templateId : templateIdsToRDAProperties.keySet()) { - if (templateIdsToValues.containsKey(templateId)) { - rdaToValueMap.put(templateIdsToRDAProperties.get(templateId), templateIdsToValues.get(templateId).toString()); - } - } - return rdaToValueMap; - } - - private List getDatasetDistribution() { - // Creates and fills a map to include distribution keys and values. - MultiValuedMap distributionJsonMap = new ArrayListValuedHashMap<>(); - for (String key : this.rdaToValueMap.keySet()) { - if (key.startsWith("distribution.")) { - distributionJsonMap.putAll(key.replace("distribution.", ""), this.rdaToValueMap.get(key)); - } - } - // Removes distribution keys from rdaToValueMap. - for (String distributionKey : distributionJsonMap.keySet()) this.rdaToValueMap.remove(distributionKey); - List distributionModels = new LinkedList<>(); - for (String key : distributionJsonMap.keySet()) { - for (String value : distributionJsonMap.get(key)) { - distributionModels.add(new DatasetDistributionRDAExportModel().fromDataModel(key, value)); - } - } - return distributionModels; - } - - private List getDatasetMetadata() { - // Creates and fills a map to include metadata keys and values. - MultiValuedMap metadataJsonMap = new ArrayListValuedHashMap<>(); - for (String key : this.rdaToValueMap.keySet()) { - if (key.startsWith("metadata.")) { - metadataJsonMap.putAll(key.replace("metadata.", ""), this.rdaToValueMap.get(key)); - } - } - // Removes metadata keys from rdaToValueMap. - for (String metadataKey : metadataJsonMap.keySet()) this.rdaToValueMap.remove(metadataKey); - List datasetMetadataRDAExportModels = new LinkedList<>(); - for (String key : metadataJsonMap.keySet()) { - for (String value : metadataJsonMap.get(key)) { - datasetMetadataRDAExportModels.add(new DatasetMetadataRDAExportModel().fromDataModel(key, value)); - } - } - return datasetMetadataRDAExportModels; - } - - private List getSecurityAndPrivacy() { - // Creates and fills a map to include SecurityAndPrivacy keys and values. - MultiValuedMap securityAndPrivacyJsonMap = new ArrayListValuedHashMap<>(); - for (String key : this.rdaToValueMap.keySet()) { - if (key.startsWith("security_and_privacy.")) { - securityAndPrivacyJsonMap.putAll(key.replace("security_and_privacy.", ""), this.rdaToValueMap.get(key)); - } - } - // Removes SecurityAndPrivacy keys from rdaToValueMap. - for (String securityAndPrivacy : securityAndPrivacyJsonMap.keySet()) this.rdaToValueMap.remove(securityAndPrivacy); - List securityAndPrivacyList= new LinkedList<>(); - for (String key : securityAndPrivacyJsonMap.keySet()) { - for (String value : securityAndPrivacyJsonMap.get(key)) { - securityAndPrivacyList.add(new DatasetSecurityAndPrivacyRDAExportModel().fromDataModel(key, value)); - } - } - return securityAndPrivacyList; - } - - private List getTechnicalResource() { - // Creates and fills a map to include Technical_Resource keys and values. - MultiValuedMap technicalResourceJsonMap = new ArrayListValuedHashMap<>(); - for (String key : this.rdaToValueMap.keySet()) { - if (key.startsWith("technical_resource.")) { - technicalResourceJsonMap.putAll(key.replace("technical_resource.", ""), this.rdaToValueMap.get(key)); - } - } - // Removes Technical_Resource keys from rdaToValueMap. - for (String techResource : technicalResourceJsonMap.keySet()) this.rdaToValueMap.remove(techResource); - List datasetTechnicalResourceRDAExportModel= new LinkedList<>(); - for (String key : technicalResourceJsonMap.keySet()) { - for (String value : technicalResourceJsonMap.get(key)) { - datasetTechnicalResourceRDAExportModel.add(new DatasetTechnicalResourceRDAExportModel().fromDataModel(key, value)); - } - } - return datasetTechnicalResourceRDAExportModel; - } - - } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetSecurityAndPrivacyRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetSecurityAndPrivacyRDAExportModel.java index 77115e086..a2d2a5581 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetSecurityAndPrivacyRDAExportModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetSecurityAndPrivacyRDAExportModel.java @@ -4,6 +4,15 @@ public class DatasetSecurityAndPrivacyRDAExportModel { private String description; private String title; + public DatasetSecurityAndPrivacyRDAExportModel() { + + } + + public DatasetSecurityAndPrivacyRDAExportModel(String description, String title) { + this.description = description; + this.title = title; + } + public String getDescription() { return description; } @@ -17,13 +26,4 @@ public class DatasetSecurityAndPrivacyRDAExportModel { public void setTitle(String title) { this.title = title; } - - public DatasetSecurityAndPrivacyRDAExportModel fromDataModel(String key, Object value) { - DatasetSecurityAndPrivacyRDAExportModel securityAndPrivacy = new DatasetSecurityAndPrivacyRDAExportModel(); - if (key.contains("description")) - securityAndPrivacy.setDescription(value.toString()); - else if (key.contains("title")) - securityAndPrivacy.setTitle(value.toString()); - return securityAndPrivacy; - } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetTechnicalResourceRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetTechnicalResourceRDAExportModel.java index 96ad0c3fb..6c47ea98e 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetTechnicalResourceRDAExportModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetTechnicalResourceRDAExportModel.java @@ -18,12 +18,11 @@ public class DatasetTechnicalResourceRDAExportModel { this.name = name; } - public DatasetTechnicalResourceRDAExportModel fromDataModel(String key, Object value) { - DatasetTechnicalResourceRDAExportModel technicalResource = new DatasetTechnicalResourceRDAExportModel(); - if (key.contains("description")) - technicalResource.setDescription(value.toString()); - else if (key.contains("name")) - technicalResource.setName(value.toString()); - return technicalResource; + public DatasetTechnicalResourceRDAExportModel(String description, String name) { + this.description = description; + this.name = name; } -} + + public DatasetTechnicalResourceRDAExportModel() { + } +} \ No newline at end of file diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java index 7c2b02eaf..53fda76d0 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java @@ -4,6 +4,7 @@ import eu.eudat.data.entities.DMP; import eu.eudat.data.entities.Dataset; import eu.eudat.data.entities.UserDMP; import eu.eudat.data.entities.UserInfo; +import eu.eudat.logic.managers.DatasetManager; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -126,7 +127,7 @@ public class DmpRDAExportModel { this.title = title; } - public DmpRDAExportModel fromDataModel(DMP entity) { + public DmpRDAExportModel fromDataModel(DMP entity, DatasetManager datasetManager) { DmpRDAExportModel dmpRda = new DmpRDAExportModel(); dmpRda.contact = new ContactRDAExportModel().fromDataModel(entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); if (entity.getUsers().stream().anyMatch(x -> x.getRole().equals(UserDMP.UserDMPRoles.USER.getValue()))) { @@ -141,9 +142,9 @@ public class DmpRDAExportModel { dmpRda.dataset = new LinkedList<>(); for (Dataset dataset : entity.getDataset()) { if (dataset.getStatus() != Dataset.Status.DELETED.getValue() && dataset.getStatus() != Dataset.Status.CANCELED.getValue()) - dmpRda.dataset.add(new DatasetRDAExportModel().fromDataModel(dataset)); + dmpRda.dataset.add(new DatasetRDAExportModel().fromDataModel(dataset, datasetManager)); } - dmpRda.description = entity.getDescription(); + dmpRda.description = entity.getDescription().replace("\n", " "); if (entity.getDoi() != null) { dmpRda.dmp_id = new IdRDAExportModel(entity.getDoi(), "zenodo"); } @@ -151,9 +152,7 @@ public class DmpRDAExportModel { dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other"); } // Mock up data on "language" and "ethical_issues_*" for now. - // dmpRda.ethical_issues_description = null; dmpRda.ethical_issues_exist = "unknown"; - // dmpRda.ethical_issues_report = null; dmpRda.language = "en"; dmpRda.modified = formatter.format(new Date()); dmpRda.project = new ProjectRDAExportModel().fromDataModel(entity.getGrant()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java index eae34fa60..ad3d3c16b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java @@ -2,6 +2,7 @@ package eu.eudat.models.data.rda; import eu.eudat.data.entities.DMP; import eu.eudat.data.entities.Dataset; +import eu.eudat.logic.managers.DatasetManager; import java.util.LinkedList; import java.util.List; @@ -16,8 +17,8 @@ public class RDAExportModel { this.dmp = dmp; } - public RDAExportModel fromDataModel(DMP dmp) { - this.dmp = new DmpRDAExportModel().fromDataModel(dmp); + public RDAExportModel fromDataModel(DMP dmp, DatasetManager datasetManager) { + this.dmp = new DmpRDAExportModel().fromDataModel(dmp, datasetManager); return this; } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RdaField.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RdaField.java new file mode 100644 index 000000000..31acd5c51 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RdaField.java @@ -0,0 +1,36 @@ +package eu.eudat.models.data.rda; + +public class RdaField { + private String rdaProperty; + private String rdaValue; + private String fieldId; + private String fieldSetId; + + public String getRdaProperty() { + return rdaProperty; + } + public void setRdaProperty(String rdaProperty) { + this.rdaProperty = rdaProperty; + } + + public String getRdaValue() { + return rdaValue; + } + public void setRdaValue(String rdaValue) { + this.rdaValue = rdaValue; + } + + public String getFieldId() { + return fieldId; + } + public void setFieldId(String fieldId) { + this.fieldId = fieldId; + } + + public String getFieldSetId() { + return fieldSetId; + } + public void setFieldSetId(String fieldSetId) { + this.fieldSetId = fieldSetId; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java index f01ecf678..ea4301ef6 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java @@ -28,6 +28,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin private List multiplicityItems; private List validations; private Visibility visible; + private String rdaProperty; public List getMultiplicityItems() { return multiplicityItems; @@ -137,6 +138,14 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin this.numbering = numbering; } + public String getRdaProperty() { + return rdaProperty; + } + + public void setRdaProperty(String rdaProperty) { + this.rdaProperty = rdaProperty; + } + public Field cloneForMultiplicity(String key, Map properties) { Field newField = new Field(); newField.id = key; @@ -148,6 +157,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin newField.defaultValue = this.defaultValue; newField.data = this.data; newField.validations = this.validations; + newField.rdaProperty = this.rdaProperty; return newField; } @@ -160,6 +170,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin field.setDefaultValue(this.defaultValue); field.setVisible(this.visible); field.setValidations(this.validations); + field.setRdaCommonStandard(this.rdaProperty); return field; } @@ -173,6 +184,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin this.defaultValue = item.getDefaultValue(); this.visible = item.getVisible(); this.validations = item.getValidations(); + this.rdaProperty = item.getRdaCommonStandard(); } @Override diff --git a/dmp-backend/web/src/main/resources/RDACommonStandards.txt b/dmp-backend/web/src/main/resources/RDACommonStandards.txt index 8c543d6aa..697e195b2 100644 --- a/dmp-backend/web/src/main/resources/RDACommonStandards.txt +++ b/dmp-backend/web/src/main/resources/RDACommonStandards.txt @@ -22,6 +22,7 @@ dataset.distribution.license.start_date dataset.distribution.title dataset.keyword dataset.language +dataset.metadata.description dataset.metadata.language dataset.metadata.metadata_standard_id dataset.metadata.metadata_standard_id.identifier