2020-03-20 17:20:22 +01:00
|
|
|
package eu.eudat.models.rda.mapper;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2020-03-26 17:39:25 +01:00
|
|
|
import eu.eudat.data.entities.DatasetProfile;
|
2020-05-28 17:38:08 +02:00
|
|
|
import eu.eudat.elastic.entities.Tag;
|
2020-03-20 17:20:22 +01:00
|
|
|
import eu.eudat.logic.managers.DatasetManager;
|
2020-03-26 17:39:25 +01:00
|
|
|
import eu.eudat.logic.services.ApiContext;
|
2020-03-20 17:20:22 +01:00
|
|
|
import eu.eudat.logic.utilities.json.JsonSearcher;
|
2020-09-04 16:09:24 +02:00
|
|
|
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
|
2020-03-20 17:20:22 +01:00
|
|
|
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
2021-12-29 14:24:46 +01:00
|
|
|
import eu.eudat.models.rda.*;
|
2020-03-26 17:39:25 +01:00
|
|
|
import org.json.JSONObject;
|
2020-03-20 17:20:22 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import javax.transaction.Transactional;
|
2022-01-12 13:10:00 +01:00
|
|
|
import java.net.URI;
|
2021-11-17 10:12:34 +01:00
|
|
|
import java.time.Instant;
|
|
|
|
import java.time.ZoneId;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.time.format.DateTimeParseException;
|
2020-03-26 17:39:25 +01:00
|
|
|
import java.util.*;
|
2020-03-20 17:20:22 +01:00
|
|
|
import java.util.stream.Collectors;
|
2020-03-26 17:39:25 +01:00
|
|
|
import java.util.stream.Stream;
|
2020-06-08 17:31:34 +02:00
|
|
|
import java.util.stream.StreamSupport;
|
2020-03-20 17:20:22 +01:00
|
|
|
|
|
|
|
@Component
|
|
|
|
public class DatasetRDAMapper {
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DatasetRDAMapper.class);
|
|
|
|
|
|
|
|
private DatasetManager datasetManager;
|
2020-03-26 17:39:25 +01:00
|
|
|
private ApiContext apiContext;
|
2020-03-20 17:20:22 +01:00
|
|
|
|
|
|
|
@Autowired
|
2020-03-26 17:39:25 +01:00
|
|
|
public DatasetRDAMapper(DatasetManager datasetManager, ApiContext apiContext) {
|
2020-03-20 17:20:22 +01:00
|
|
|
this.datasetManager = datasetManager;
|
2020-03-26 17:39:25 +01:00
|
|
|
this.apiContext = apiContext;
|
2020-03-20 17:20:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
2022-01-12 13:10:00 +01:00
|
|
|
public Dataset toRDA(eu.eudat.data.entities.Dataset dataset, eu.eudat.models.rda.Dmp dmp) {
|
2020-03-20 17:20:22 +01:00
|
|
|
Dataset rda = new Dataset();
|
2020-05-28 17:38:08 +02:00
|
|
|
// rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
|
2020-11-13 17:26:09 +01:00
|
|
|
if (dataset.getLabel() == null) {
|
2020-11-13 17:29:16 +01:00
|
|
|
throw new IllegalArgumentException("Dataset Label is missing");
|
2020-11-13 17:26:09 +01:00
|
|
|
}
|
2020-03-20 17:20:22 +01:00
|
|
|
rda.setTitle(dataset.getLabel());
|
|
|
|
rda.setDescription(dataset.getDescription());
|
2020-03-26 17:39:25 +01:00
|
|
|
rda.setAdditionalProperty("template", dataset.getProfile().getId());
|
2020-03-20 17:20:22 +01:00
|
|
|
try {
|
2020-03-26 17:39:25 +01:00
|
|
|
JSONObject jObject = new JSONObject(dataset.getProperties());
|
|
|
|
Map<String, Object> templateIdsToValues = jObject.toMap();
|
2020-03-20 17:20:22 +01:00
|
|
|
DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(dataset);
|
|
|
|
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset));
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
String datasetDescriptionJson = mapper.writeValueAsString(datasetWizardModel.getDatasetProfileDefinition());
|
|
|
|
JsonNode datasetDescriptionObj = mapper.readTree(datasetDescriptionJson);
|
2020-05-28 17:38:08 +02:00
|
|
|
List<JsonNode> idNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.dataset_id");
|
|
|
|
if (!idNodes.isEmpty()) {
|
|
|
|
rda.setDatasetId(DatasetIdRDAMapper.toRDA(idNodes));
|
|
|
|
}
|
2020-09-15 12:21:22 +02:00
|
|
|
if (rda.getDatasetId() == null) {
|
|
|
|
rda.setDatasetId(new DatasetId(dataset.getId().toString(), DatasetId.Type.OTHER));
|
|
|
|
}
|
2020-03-20 17:20:22 +01:00
|
|
|
List<JsonNode> typeNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.type");
|
2021-12-29 14:24:46 +01:00
|
|
|
if (!typeNodes.isEmpty() && !typeNodes.get(0).get("value").asText().isEmpty()) {
|
2020-03-23 17:09:31 +01:00
|
|
|
rda.setType(typeNodes.get(0).get("value").asText());
|
2020-05-28 17:38:08 +02:00
|
|
|
} else {
|
2020-09-15 12:21:22 +02:00
|
|
|
rda.setType("DMP Dataset");
|
2020-03-20 17:20:22 +01:00
|
|
|
}
|
|
|
|
List<JsonNode> languageNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.language");
|
2021-12-29 14:24:46 +01:00
|
|
|
if (!languageNodes.isEmpty() && !languageNodes.get(0).get("value").asText().isEmpty()) {
|
2020-06-03 11:13:31 +02:00
|
|
|
rda.setLanguage(Language.fromValue(languageNodes.get(0).get("value").asText()));
|
|
|
|
} else {
|
|
|
|
rda.setLanguage(LanguageRDAMapper.mapLanguageIsoToRDAIso(dataset.getProfile().getLanguage()));
|
2020-03-20 17:20:22 +01:00
|
|
|
}
|
|
|
|
List<JsonNode> metadataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.metadata");
|
|
|
|
if (!metadataNodes.isEmpty()) {
|
2020-03-23 17:09:31 +01:00
|
|
|
rda.setMetadata(MetadataRDAMapper.toRDAList(metadataNodes));
|
2021-12-17 11:59:10 +01:00
|
|
|
}else{
|
2021-12-29 14:24:46 +01:00
|
|
|
rda.setMetadata(new ArrayList<>());
|
|
|
|
}
|
2020-03-20 17:20:22 +01:00
|
|
|
List<JsonNode> qaNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.data_quality_assurance");
|
|
|
|
if (!qaNodes.isEmpty()) {
|
2020-05-28 17:38:08 +02:00
|
|
|
/*rda.setDataQualityAssurance(qaNodes.stream().map(qaNode -> qaNode.get("value").asText()).collect(Collectors.toList()));
|
2020-03-26 17:39:25 +01:00
|
|
|
for (int i = 0; i < qaNodes.size(); i++) {
|
2020-03-27 09:50:37 +01:00
|
|
|
rda.setAdditionalProperty("qaId" + (i + 1), qaNodes.get(i).get("id").asText());
|
2020-05-28 17:38:08 +02:00
|
|
|
}*/
|
2021-12-17 11:59:10 +01:00
|
|
|
List<String> qaList = qaNodes.stream()
|
|
|
|
.map(qaNode -> qaNode.get("value").asText())
|
2021-12-17 15:21:32 +01:00
|
|
|
.filter(qaNode -> !qaNode.isEmpty())
|
2021-12-17 11:59:10 +01:00
|
|
|
.collect(Collectors.toList());
|
2021-12-16 10:44:34 +01:00
|
|
|
rda.setDataQualityAssurance(qaList);
|
2021-12-17 11:59:10 +01:00
|
|
|
}else{
|
2021-12-29 14:24:46 +01:00
|
|
|
rda.setDataQualityAssurance(new ArrayList<>());
|
2020-03-20 17:20:22 +01:00
|
|
|
}
|
|
|
|
List<JsonNode> preservationNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.preservation_statement");
|
2021-12-29 14:24:46 +01:00
|
|
|
if (!preservationNodes.isEmpty() && !preservationNodes.get(0).get("value").asText().isEmpty()) {
|
2020-03-24 10:26:17 +01:00
|
|
|
rda.setPreservationStatement(preservationNodes.get(0).get("value").asText());
|
2020-03-20 17:20:22 +01:00
|
|
|
}
|
|
|
|
List<JsonNode> distributionNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.distribution");
|
|
|
|
if (!distributionNodes.isEmpty()) {
|
2021-12-29 14:24:46 +01:00
|
|
|
rda.setDistribution(DistributionRDAMapper.toRDAList(distributionNodes));
|
2021-12-17 11:59:10 +01:00
|
|
|
}else{
|
2021-12-29 14:24:46 +01:00
|
|
|
rda.setDistribution(new ArrayList<>());
|
2020-03-20 17:20:22 +01:00
|
|
|
}
|
|
|
|
List<JsonNode> keywordNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.keyword");
|
|
|
|
if (!keywordNodes.isEmpty()) {
|
2020-06-08 17:31:34 +02:00
|
|
|
rda.setKeyword(keywordNodes.stream().map(keywordNode -> {
|
|
|
|
JsonNode value = keywordNode.get("value");
|
|
|
|
if (value.isArray()) {
|
2020-09-15 12:21:22 +02:00
|
|
|
return StreamSupport.stream(value.spliterator(), false).map(node -> KeywordRDAMapper.toRDA(node.asText())).flatMap(Collection::stream).collect(Collectors.toList());
|
2020-06-08 17:31:34 +02:00
|
|
|
} else {
|
2020-09-15 12:21:22 +02:00
|
|
|
return KeywordRDAMapper.toRDA(keywordNode.get("value").asText());
|
2020-06-08 17:31:34 +02:00
|
|
|
}
|
2020-06-09 15:25:50 +02:00
|
|
|
}).flatMap(Collection::stream).collect(Collectors.toList()));
|
2020-03-26 17:39:25 +01:00
|
|
|
for (int i = 0; i < keywordNodes.size(); i++) {
|
|
|
|
rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText());
|
|
|
|
}
|
2021-07-06 11:58:38 +02:00
|
|
|
} else if (apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().exists()) {
|
2020-05-28 17:38:08 +02:00
|
|
|
List<String> tags = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString()).getTags().stream().map(Tag::getName).collect(Collectors.toList());
|
|
|
|
rda.setKeyword(tags);
|
2020-03-20 17:20:22 +01:00
|
|
|
}
|
|
|
|
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data");
|
|
|
|
if (!personalDataNodes.isEmpty()) {
|
2022-01-12 13:10:00 +01:00
|
|
|
try{
|
|
|
|
rda.setPersonalData(personalDataNodes.stream().map(personalDataNode -> Dataset.PersonalData.fromValue(personalDataNode.get("value").asText())).findFirst().get());
|
|
|
|
}catch(IllegalArgumentException e){
|
|
|
|
rda.setPersonalData(Dataset.PersonalData.UNKNOWN);
|
|
|
|
}
|
2020-05-28 17:38:08 +02:00
|
|
|
} else {
|
|
|
|
rda.setPersonalData(Dataset.PersonalData.UNKNOWN);
|
2020-03-20 17:20:22 +01:00
|
|
|
}
|
|
|
|
List<JsonNode> securityAndPrivacyNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.security_and_privacy");
|
|
|
|
if (!securityAndPrivacyNodes.isEmpty()) {
|
2020-03-23 17:09:31 +01:00
|
|
|
rda.setSecurityAndPrivacy(SecurityAndPrivacyRDAMapper.toRDAList(securityAndPrivacyNodes));
|
2021-12-17 11:59:10 +01:00
|
|
|
}else{
|
2021-12-29 14:24:46 +01:00
|
|
|
rda.setSecurityAndPrivacy(new ArrayList<>());
|
|
|
|
}
|
2020-03-20 17:20:22 +01:00
|
|
|
List<JsonNode> sensitiveDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.sensitive_data");
|
|
|
|
if (!sensitiveDataNodes.isEmpty()) {
|
2022-01-12 13:10:00 +01:00
|
|
|
try{
|
|
|
|
rda.setSensitiveData(sensitiveDataNodes.stream().map(sensitiveDataNode -> Dataset.SensitiveData.fromValue(sensitiveDataNode.get("value").asText())).findFirst().get());
|
|
|
|
}catch(IllegalArgumentException e){
|
|
|
|
rda.setSensitiveData(Dataset.SensitiveData.UNKNOWN);
|
|
|
|
}
|
2020-09-15 12:21:22 +02:00
|
|
|
} else {
|
|
|
|
rda.setSensitiveData(Dataset.SensitiveData.UNKNOWN);
|
2020-03-20 17:20:22 +01:00
|
|
|
}
|
|
|
|
List<JsonNode> technicalResourceNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.technical_resource");
|
|
|
|
if (!technicalResourceNodes.isEmpty()) {
|
2020-03-23 17:09:31 +01:00
|
|
|
rda.setTechnicalResource(TechnicalResourceRDAMapper.toRDAList(technicalResourceNodes));
|
2021-12-17 11:59:10 +01:00
|
|
|
}else{
|
2021-12-29 14:24:46 +01:00
|
|
|
rda.setTechnicalResource(new ArrayList<>());
|
|
|
|
}
|
2020-05-28 17:38:08 +02:00
|
|
|
List<JsonNode> issuedNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.issued");
|
2021-12-29 14:24:46 +01:00
|
|
|
if (!issuedNodes.isEmpty() && !issuedNodes.get(0).get("value").asText().isEmpty()) {
|
2020-05-28 17:38:08 +02:00
|
|
|
rda.setIssued(issuedNodes.get(0).get("value").asText());
|
|
|
|
}
|
2020-06-09 15:25:50 +02:00
|
|
|
List<JsonNode> contributorNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.contributor");
|
|
|
|
if (!contributorNodes.isEmpty()) {
|
2022-01-12 13:10:00 +01:00
|
|
|
dmp.getContributor().addAll(contributorNodes.stream().map(contributorNode -> {
|
2020-06-09 15:25:50 +02:00
|
|
|
JsonNode value = contributorNode.get("value");
|
|
|
|
if (value.isArray()) {
|
|
|
|
return StreamSupport.stream(value.spliterator(), false).map(node -> ContributorRDAMapper.toRDA(node.asText())).collect(Collectors.toList());
|
|
|
|
} else {
|
2021-12-29 14:24:46 +01:00
|
|
|
return Collections.singletonList(new Contributor()); // return null kalutera
|
2020-06-09 15:25:50 +02:00
|
|
|
}
|
|
|
|
}).flatMap(Collection::stream).collect(Collectors.toList()));
|
|
|
|
}
|
2021-12-29 14:24:46 +01:00
|
|
|
List<JsonNode> costNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.cost");
|
|
|
|
if (!costNodes.isEmpty()) {
|
2022-01-12 13:10:00 +01:00
|
|
|
dmp.getCost().addAll(CostRDAMapper.toRDAList(costNodes));
|
|
|
|
}
|
|
|
|
List<JsonNode> ethicsNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.ethical_issues");
|
|
|
|
if (!ethicsNodes.isEmpty()) {
|
|
|
|
for(JsonNode node: ethicsNodes){
|
|
|
|
String rdaProperty = node.get("rdaProperty").asText();
|
|
|
|
String rdaValue = node.get("value").asText();
|
|
|
|
if(rdaValue == null || rdaValue.isEmpty()){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(rdaProperty.contains("exist")){
|
|
|
|
try {
|
|
|
|
Dmp.EthicalIssuesExist exists = dmp.getEthicalIssuesExist();
|
|
|
|
if(exists == null
|
|
|
|
|| ((exists == Dmp.EthicalIssuesExist.NO || exists == Dmp.EthicalIssuesExist.UNKNOWN) && rdaValue.equals("yes"))
|
|
|
|
|| (exists == Dmp.EthicalIssuesExist.YES && !(rdaValue.equals("no") || rdaValue.equals("unknown")))
|
|
|
|
|| (exists == Dmp.EthicalIssuesExist.UNKNOWN && rdaValue.equals("no"))){
|
|
|
|
dmp.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(rdaValue));
|
|
|
|
}
|
|
|
|
}catch(IllegalArgumentException e){
|
|
|
|
logger.warn(e.getLocalizedMessage() + ". Setting ethical_issues_exist to unknown");
|
|
|
|
dmp.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(rdaProperty.contains("description")){
|
|
|
|
if(dmp.getEthicalIssuesDescription() == null){
|
|
|
|
dmp.setEthicalIssuesDescription(rdaValue);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
dmp.setEthicalIssuesDescription(dmp.getEthicalIssuesDescription() + ", " + rdaValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(rdaProperty.contains("report")){
|
|
|
|
try {
|
|
|
|
dmp.setEthicalIssuesReport(URI.create(rdaValue));
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
logger.warn(e.getLocalizedMessage() + ". Skipping url parsing");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-29 14:24:46 +01:00
|
|
|
}
|
2020-03-26 17:39:25 +01:00
|
|
|
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 -> {
|
|
|
|
boolean isFound = foundNodes.stream().anyMatch(node -> node.get("id").asText().equals(entry.getKey()));
|
|
|
|
if (!isFound && entry.getValue() != null && !entry.getValue().toString().isEmpty()) {
|
2021-11-17 10:12:34 +01:00
|
|
|
try {
|
|
|
|
Instant time = Instant.parse(entry.getValue().toString());
|
|
|
|
rda.setAdditionalProperty(entry.getKey(), DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(time));
|
|
|
|
} catch (DateTimeParseException e) {
|
|
|
|
rda.setAdditionalProperty(entry.getKey(), entry.getValue());
|
|
|
|
}
|
2020-03-26 17:39:25 +01:00
|
|
|
}
|
|
|
|
});
|
2020-03-20 17:20:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return rda;
|
|
|
|
}
|
2020-03-26 17:39:25 +01:00
|
|
|
|
|
|
|
|
2020-05-29 12:39:18 +02:00
|
|
|
public eu.eudat.data.entities.Dataset toEntity(Dataset rda, DatasetProfile defaultProfile) {
|
2020-03-26 17:39:25 +01:00
|
|
|
eu.eudat.data.entities.Dataset entity = new eu.eudat.data.entities.Dataset();
|
|
|
|
entity.setLabel(rda.getTitle());
|
|
|
|
entity.setDescription(rda.getDescription());
|
|
|
|
try {
|
|
|
|
DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(rda.getAdditionalProperties().get("template").toString()));
|
|
|
|
entity.setProfile(profile);
|
|
|
|
}catch(Exception e) {
|
|
|
|
logger.warn(e.getMessage(), e);
|
2020-05-29 12:39:18 +02:00
|
|
|
entity.setProfile(defaultProfile);
|
2020-03-26 17:39:25 +01:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
Map<String, Object> properties = new HashMap<>();
|
|
|
|
DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
|
2020-09-04 16:09:24 +02:00
|
|
|
datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()));
|
2020-03-26 17:39:25 +01:00
|
|
|
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, entity));
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
String datasetDescriptionJson = mapper.writeValueAsString(datasetWizardModel.getDatasetProfileDefinition());
|
|
|
|
JsonNode datasetDescriptionObj = mapper.readTree(datasetDescriptionJson);
|
|
|
|
|
|
|
|
List<JsonNode> typeNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.type");
|
|
|
|
if (!typeNodes.isEmpty()) {
|
|
|
|
properties.put(typeNodes.get(0).get("id").asText(), rda.getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
List<JsonNode> languageNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.language");
|
2020-05-29 13:42:21 +02:00
|
|
|
if (!languageNodes.isEmpty() && rda.getLanguage() != null) {
|
2020-03-26 17:39:25 +01:00
|
|
|
properties.put(languageNodes.get(0).get("id").asText(), rda.getLanguage().value());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rda.getMetadata() != null) {
|
|
|
|
properties.putAll(MetadataRDAMapper.toProperties(rda.getMetadata()));
|
|
|
|
}
|
|
|
|
|
2020-05-28 17:38:08 +02:00
|
|
|
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());
|
2020-03-26 17:39:25 +01:00
|
|
|
for (int i = 0; i < qaIds.size(); i++) {
|
|
|
|
properties.put(qaIds.get(i), rda.getDataQualityAssurance().get(i));
|
2020-05-28 17:38:08 +02:00
|
|
|
}*/
|
|
|
|
List<JsonNode> qaNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.data_quality_assurance");
|
2020-05-29 12:39:18 +02:00
|
|
|
if (!qaNodes.isEmpty() && rda.getDataQualityAssurance() != null && !rda.getDataQualityAssurance().isEmpty()) {
|
2020-05-28 17:38:08 +02:00
|
|
|
properties.put(qaNodes.get(0).get("id").asText(), rda.getDataQualityAssurance().get(0));
|
2020-03-26 17:39:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
List<JsonNode> preservationNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.preservation_statement");
|
|
|
|
if (!preservationNodes.isEmpty()) {
|
|
|
|
properties.put(preservationNodes.get(0).get("id").asText(), rda.getPreservationStatement());
|
|
|
|
}
|
|
|
|
|
2020-05-28 17:38:08 +02:00
|
|
|
List<JsonNode> issuedNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.issued");
|
|
|
|
if (!issuedNodes.isEmpty()) {
|
|
|
|
properties.put(issuedNodes.get(0).get("id").asText(), rda.getIssued());
|
|
|
|
}
|
|
|
|
|
2020-03-26 17:39:25 +01:00
|
|
|
if (rda.getDistribution() != null) {
|
2020-05-28 17:38:08 +02:00
|
|
|
properties.putAll(DistributionRDAMapper.toProperties(rda.getDistribution().get(0), datasetDescriptionObj));
|
2020-03-26 17:39:25 +01:00
|
|
|
}
|
|
|
|
|
2020-06-25 12:30:47 +02:00
|
|
|
if (rda.getKeyword() != null) {
|
|
|
|
List<String> keywordIds = rda.getAdditionalProperties().entrySet().stream().filter(entry -> entry.getKey().startsWith("keyword")).map(entry -> entry.getValue().toString()).collect(Collectors.toList());
|
|
|
|
boolean takeAll = false;
|
|
|
|
if (keywordIds.size() < rda.getKeyword().size()) {
|
|
|
|
takeAll = true;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < keywordIds.size(); i++) {
|
|
|
|
if (takeAll) {
|
|
|
|
List<String> tags = new ArrayList<>();
|
|
|
|
for (String keyword : rda.getKeyword()) {
|
|
|
|
tags.add(mapper.writeValueAsString(toTagEntity(keyword)));
|
|
|
|
}
|
|
|
|
properties.put(keywordIds.get(i), tags);
|
|
|
|
} else {
|
|
|
|
properties.put(keywordIds.get(i), mapper.writeValueAsString(toTagEntity(rda.getKeyword().get(i))));
|
2020-06-09 15:25:50 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-26 17:39:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data");
|
|
|
|
if (!personalDataNodes.isEmpty()) {
|
|
|
|
properties.put(personalDataNodes.get(0).get("id").asText(), rda.getPersonalData().value());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rda.getSecurityAndPrivacy() != null) {
|
|
|
|
properties.putAll(SecurityAndPrivacyRDAMapper.toProperties(rda.getSecurityAndPrivacy()));
|
|
|
|
}
|
|
|
|
|
|
|
|
List<JsonNode> sensitiveDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.sensitive_data");
|
|
|
|
if (!sensitiveDataNodes.isEmpty()) {
|
|
|
|
properties.put(sensitiveDataNodes.get(0).get("id").asText(), rda.getSensitiveData().value());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rda.getTechnicalResource() != null) {
|
|
|
|
properties.putAll(TechnicalResourceRDAMapper.toProperties(rda.getTechnicalResource()));
|
|
|
|
}
|
|
|
|
|
|
|
|
rda.getAdditionalProperties().entrySet().stream()
|
2020-03-27 09:50:37 +01:00
|
|
|
.filter(entry -> !entry.getKey().equals("template") && !entry.getKey().startsWith("qaId") && !entry.getKey().startsWith("keyword"))
|
2020-03-26 17:39:25 +01:00
|
|
|
.forEach(entry -> properties.put(entry.getKey(), entry.getValue()));
|
|
|
|
entity.setProperties(new ObjectMapper().writeValueAsString(properties));
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return entity;
|
|
|
|
}
|
2020-06-09 15:25:50 +02:00
|
|
|
|
|
|
|
private static Tag toTagEntity(String name) {
|
|
|
|
Tag tag = new Tag();
|
|
|
|
tag.setId("");
|
|
|
|
tag.setName(name);
|
|
|
|
return tag;
|
|
|
|
}
|
2020-03-20 17:20:22 +01:00
|
|
|
}
|