|
|
|
@ -3,11 +3,13 @@ package eu.eudat.models.rda.mapper;
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import eu.eudat.data.entities.DatasetProfile;
|
|
|
|
|
import eu.eudat.elastic.entities.Tag;
|
|
|
|
|
import eu.eudat.logic.managers.DatasetManager;
|
|
|
|
|
import eu.eudat.logic.services.ApiContext;
|
|
|
|
|
import eu.eudat.logic.utilities.json.JsonSearcher;
|
|
|
|
|
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
|
|
|
|
import eu.eudat.models.rda.Dataset;
|
|
|
|
|
import eu.eudat.models.rda.DatasetId;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
@ -35,7 +37,7 @@ public class DatasetRDAMapper {
|
|
|
|
|
@Transactional
|
|
|
|
|
public Dataset toRDA(eu.eudat.data.entities.Dataset dataset) {
|
|
|
|
|
Dataset rda = new Dataset();
|
|
|
|
|
rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
|
|
|
|
|
// rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
|
|
|
|
|
rda.setTitle(dataset.getLabel());
|
|
|
|
|
rda.setDescription(dataset.getDescription());
|
|
|
|
|
rda.setAdditionalProperty("template", dataset.getProfile().getId());
|
|
|
|
@ -47,9 +49,15 @@ public class DatasetRDAMapper {
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
String datasetDescriptionJson = mapper.writeValueAsString(datasetWizardModel.getDatasetProfileDefinition());
|
|
|
|
|
JsonNode datasetDescriptionObj = mapper.readTree(datasetDescriptionJson);
|
|
|
|
|
List<JsonNode> idNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.dataset_id");
|
|
|
|
|
if (!idNodes.isEmpty()) {
|
|
|
|
|
rda.setDatasetId(DatasetIdRDAMapper.toRDA(idNodes));
|
|
|
|
|
}
|
|
|
|
|
List<JsonNode> typeNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.type");
|
|
|
|
|
if (!typeNodes.isEmpty()) {
|
|
|
|
|
rda.setType(typeNodes.get(0).get("value").asText());
|
|
|
|
|
} else {
|
|
|
|
|
rda.setType(dataset.getLabel());
|
|
|
|
|
}
|
|
|
|
|
List<JsonNode> languageNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.language");
|
|
|
|
|
if (!languageNodes.isEmpty()) {
|
|
|
|
@ -61,10 +69,11 @@ public class DatasetRDAMapper {
|
|
|
|
|
}
|
|
|
|
|
List<JsonNode> qaNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.data_quality_assurance");
|
|
|
|
|
if (!qaNodes.isEmpty()) {
|
|
|
|
|
rda.setDataQualityAssurance(qaNodes.stream().map(qaNode -> qaNode.get("value").asText()).collect(Collectors.toList()));
|
|
|
|
|
/*rda.setDataQualityAssurance(qaNodes.stream().map(qaNode -> qaNode.get("value").asText()).collect(Collectors.toList()));
|
|
|
|
|
for (int i = 0; i < qaNodes.size(); i++) {
|
|
|
|
|
rda.setAdditionalProperty("qaId" + (i + 1), qaNodes.get(i).get("id").asText());
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
rda.setDataQualityAssurance(Collections.singletonList(qaNodes.get(0).get("value").asText()));
|
|
|
|
|
}
|
|
|
|
|
List<JsonNode> preservationNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.preservation_statement");
|
|
|
|
|
if (!preservationNodes.isEmpty()) {
|
|
|
|
@ -72,7 +81,7 @@ public class DatasetRDAMapper {
|
|
|
|
|
}
|
|
|
|
|
List<JsonNode> distributionNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.distribution");
|
|
|
|
|
if (!distributionNodes.isEmpty()) {
|
|
|
|
|
rda.setDistribution(DistributionRDAMapper.toRDAList(distributionNodes));
|
|
|
|
|
rda.setDistribution(Collections.singletonList(DistributionRDAMapper.toRDA(distributionNodes)));
|
|
|
|
|
}
|
|
|
|
|
List<JsonNode> keywordNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.keyword");
|
|
|
|
|
if (!keywordNodes.isEmpty()) {
|
|
|
|
@ -80,10 +89,15 @@ public class DatasetRDAMapper {
|
|
|
|
|
for (int i = 0; i < keywordNodes.size(); i++) {
|
|
|
|
|
rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
List<String> tags = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString()).getTags().stream().map(Tag::getName).collect(Collectors.toList());
|
|
|
|
|
rda.setKeyword(tags);
|
|
|
|
|
}
|
|
|
|
|
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data");
|
|
|
|
|
if (!personalDataNodes.isEmpty()) {
|
|
|
|
|
rda.setPersonalData(personalDataNodes.stream().map(personalDataNode -> Dataset.PersonalData.fromValue(personalDataNode.get("value").asText())).findFirst().get());
|
|
|
|
|
} else {
|
|
|
|
|
rda.setPersonalData(Dataset.PersonalData.UNKNOWN);
|
|
|
|
|
}
|
|
|
|
|
List<JsonNode> securityAndPrivacyNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.security_and_privacy");
|
|
|
|
|
if (!securityAndPrivacyNodes.isEmpty()) {
|
|
|
|
@ -97,6 +111,10 @@ public class DatasetRDAMapper {
|
|
|
|
|
if (!technicalResourceNodes.isEmpty()) {
|
|
|
|
|
rda.setTechnicalResource(TechnicalResourceRDAMapper.toRDAList(technicalResourceNodes));
|
|
|
|
|
}
|
|
|
|
|
List<JsonNode> issuedNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.issued");
|
|
|
|
|
if (!issuedNodes.isEmpty()) {
|
|
|
|
|
rda.setIssued(issuedNodes.get(0).get("value").asText());
|
|
|
|
|
}
|
|
|
|
|
List<JsonNode> foundNodes = Stream.of(typeNodes, languageNodes, metadataNodes, qaNodes, preservationNodes, distributionNodes,
|
|
|
|
|
keywordNodes, personalDataNodes, securityAndPrivacyNodes, sensitiveDataNodes, technicalResourceNodes).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
|
|
templateIdsToValues.entrySet().forEach(entry -> {
|
|
|
|
@ -149,9 +167,17 @@ public class DatasetRDAMapper {
|
|
|
|
|
properties.putAll(MetadataRDAMapper.toProperties(rda.getMetadata()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List <String> qaIds = rda.getAdditionalProperties().entrySet().stream().filter(entry -> entry.getKey().startsWith("qaId")).map(entry -> entry.getValue().toString()).collect(Collectors.toList());
|
|
|
|
|
if (rda.getDatasetId() != null) {
|
|
|
|
|
properties.putAll(DatasetIdRDAMapper.toProperties(rda.getDatasetId(), datasetDescriptionObj));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*List <String> qaIds = rda.getAdditionalProperties().entrySet().stream().filter(entry -> entry.getKey().startsWith("qaId")).map(entry -> entry.getValue().toString()).collect(Collectors.toList());
|
|
|
|
|
for (int i = 0; i < qaIds.size(); i++) {
|
|
|
|
|
properties.put(qaIds.get(i), rda.getDataQualityAssurance().get(i));
|
|
|
|
|
}*/
|
|
|
|
|
List<JsonNode> qaNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.data_quality_assurance");
|
|
|
|
|
if (!qaNodes.isEmpty()) {
|
|
|
|
|
properties.put(qaNodes.get(0).get("id").asText(), rda.getDataQualityAssurance().get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<JsonNode> preservationNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.preservation_statement");
|
|
|
|
@ -159,8 +185,13 @@ public class DatasetRDAMapper {
|
|
|
|
|
properties.put(preservationNodes.get(0).get("id").asText(), rda.getPreservationStatement());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<JsonNode> issuedNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.issued");
|
|
|
|
|
if (!issuedNodes.isEmpty()) {
|
|
|
|
|
properties.put(issuedNodes.get(0).get("id").asText(), rda.getIssued());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rda.getDistribution() != null) {
|
|
|
|
|
properties.putAll(DistributionRDAMapper.toProperties(rda.getDistribution()));
|
|
|
|
|
properties.putAll(DistributionRDAMapper.toProperties(rda.getDistribution().get(0), datasetDescriptionObj));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List <String> keywordIds = rda.getAdditionalProperties().entrySet().stream().filter(entry -> entry.getKey().startsWith("keyword")).map(entry -> entry.getValue().toString()).collect(Collectors.toList());
|
|
|
|
|