Add rda support for researchers and tags field
This commit is contained in:
parent
c927e41d83
commit
12587ee865
|
@ -1394,7 +1394,7 @@ public class DataManagementPlanManager {
|
||||||
dmp.setStatus((short)0);
|
dmp.setStatus((short)0);
|
||||||
dmp.setGroupId(UUID.randomUUID());
|
dmp.setGroupId(UUID.randomUUID());
|
||||||
if (dmp.getResearchers() != null && !dmp.getResearchers().isEmpty()) {
|
if (dmp.getResearchers() != null && !dmp.getResearchers().isEmpty()) {
|
||||||
dmp.getResearchers().forEach(researcher -> {
|
dmp.getResearchers().stream().filter(Objects::nonNull).forEach(researcher -> {
|
||||||
researcher.setId(UUID.randomUUID());
|
researcher.setId(UUID.randomUUID());
|
||||||
researcher.setCreated(new Date());
|
researcher.setCreated(new Date());
|
||||||
researcher.setModified(new Date());
|
researcher.setModified(new Date());
|
||||||
|
|
|
@ -341,7 +341,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
|
||||||
this.id = entity.getId();
|
this.id = entity.getId();
|
||||||
this.profile = entity.getProfile() != null ? new Tuple<UUID, String>(entity.getProfile().getId(), entity.getProfile().getLabel()) : null;
|
this.profile = entity.getProfile() != null ? new Tuple<UUID, String>(entity.getProfile().getId(), entity.getProfile().getLabel()) : null;
|
||||||
this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
|
this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
|
||||||
this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
|
this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().filter(Objects::nonNull).map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
|
||||||
this.version = entity.getVersion();
|
this.version = entity.getVersion();
|
||||||
this.label = entity.getLabel();
|
this.label = entity.getLabel();
|
||||||
this.grant = new Grant();
|
this.grant = new Grant();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.models.data.dmp;
|
package eu.eudat.models.data.dmp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import eu.eudat.models.DataModel;
|
import eu.eudat.models.DataModel;
|
||||||
import eu.eudat.logic.utilities.helpers.LabelGenerator;
|
import eu.eudat.logic.utilities.helpers.LabelGenerator;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -8,6 +9,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class Researcher implements DataModel<eu.eudat.data.entities.Researcher, Researcher>, LabelGenerator {
|
public class Researcher implements DataModel<eu.eudat.data.entities.Researcher, Researcher>, LabelGenerator {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Researcher.class);
|
private static final Logger logger = LoggerFactory.getLogger(Researcher.class);
|
||||||
private String label;
|
private String label;
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
package eu.eudat.models.rda.mapper;
|
package eu.eudat.models.rda.mapper;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.data.entities.Researcher;
|
import eu.eudat.data.entities.Researcher;
|
||||||
import eu.eudat.data.entities.UserDMP;
|
import eu.eudat.data.entities.UserDMP;
|
||||||
import eu.eudat.models.rda.Contributor;
|
import eu.eudat.models.rda.Contributor;
|
||||||
import eu.eudat.models.rda.ContributorId;
|
import eu.eudat.models.rda.ContributorId;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.io.IOException;
|
||||||
import java.util.HashSet;
|
import java.util.*;
|
||||||
|
|
||||||
public class ContributorRDAMapper {
|
public class ContributorRDAMapper {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ContributorRDAMapper.class);
|
||||||
|
|
||||||
public static Contributor toRDA(UserDMP userDMP) {
|
public static Contributor toRDA(UserDMP userDMP) {
|
||||||
Contributor rda = new Contributor();
|
Contributor rda = new Contributor();
|
||||||
|
@ -28,23 +32,38 @@ public class ContributorRDAMapper {
|
||||||
return rda;
|
return rda;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Contributor toRDA(String value) {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
try {
|
||||||
|
eu.eudat.models.data.dmp.Researcher researcher = mapper.readValue(value, eu.eudat.models.data.dmp.Researcher.class);
|
||||||
|
return toRDA(researcher.toDataModel());
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static Researcher toEntity(Contributor rda) {
|
public static Researcher toEntity(Contributor rda) {
|
||||||
Researcher entity = new Researcher();
|
Researcher entity = new Researcher();
|
||||||
String reference;
|
String reference;
|
||||||
if (rda.getContributorId().getType() == ContributorId.Type.ORCID) {
|
if (rda.getContributorId() != null) {
|
||||||
String id = rda.getContributorId().getIdentifier().replace("http://orcid.org/", "");
|
if (rda.getContributorId().getType() == ContributorId.Type.ORCID) {
|
||||||
reference = "orcid:" + id;
|
String id = rda.getContributorId().getIdentifier().replace("http://orcid.org/", "");
|
||||||
} else {
|
reference = "orcid:" + id;
|
||||||
String idParts[] = rda.getContributorId().getIdentifier().split(":");
|
|
||||||
if (idParts.length == 1) {
|
|
||||||
reference = "dmp:" + rda.getContributorId().getIdentifier();
|
|
||||||
} else {
|
} else {
|
||||||
reference = rda.getContributorId().getIdentifier();
|
String idParts[] = rda.getContributorId().getIdentifier().split(":");
|
||||||
|
if (idParts.length == 1) {
|
||||||
|
reference = "dmp:" + rda.getContributorId().getIdentifier();
|
||||||
|
} else {
|
||||||
|
reference = rda.getContributorId().getIdentifier();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
entity.setReference(reference);
|
||||||
|
entity.setLabel(rda.getName());
|
||||||
|
entity.setPrimaryEmail(rda.getMbox());
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
entity.setReference(reference);
|
|
||||||
entity.setLabel(rda.getName());
|
|
||||||
entity.setPrimaryEmail(rda.getMbox());
|
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import eu.eudat.logic.managers.DatasetManager;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.utilities.json.JsonSearcher;
|
import eu.eudat.logic.utilities.json.JsonSearcher;
|
||||||
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||||
|
import eu.eudat.models.rda.Contributor;
|
||||||
import eu.eudat.models.rda.Dataset;
|
import eu.eudat.models.rda.Dataset;
|
||||||
import eu.eudat.models.rda.Language;
|
import eu.eudat.models.rda.Language;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -36,7 +37,7 @@ public class DatasetRDAMapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Dataset toRDA(eu.eudat.data.entities.Dataset dataset) {
|
public Dataset toRDA(eu.eudat.data.entities.Dataset dataset, List<Contributor> contributors) {
|
||||||
Dataset rda = new Dataset();
|
Dataset rda = new Dataset();
|
||||||
// rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
|
// rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
|
||||||
rda.setTitle(dataset.getLabel());
|
rda.setTitle(dataset.getLabel());
|
||||||
|
@ -91,11 +92,11 @@ public class DatasetRDAMapper {
|
||||||
rda.setKeyword(keywordNodes.stream().map(keywordNode -> {
|
rda.setKeyword(keywordNodes.stream().map(keywordNode -> {
|
||||||
JsonNode value = keywordNode.get("value");
|
JsonNode value = keywordNode.get("value");
|
||||||
if (value.isArray()) {
|
if (value.isArray()) {
|
||||||
return StreamSupport.stream(value.spliterator(), false).map(node -> KeywordRDAMapper.toRDA(node.asText())).collect(Collectors.joining("\", \"")).replaceAll("\"", "\"");
|
return StreamSupport.stream(value.spliterator(), false).map(node -> KeywordRDAMapper.toRDA(node.asText())).collect(Collectors.toList());
|
||||||
} else {
|
} else {
|
||||||
return KeywordRDAMapper.toRDA(keywordNode.get("value").asText());
|
return Collections.singletonList(KeywordRDAMapper.toRDA(keywordNode.get("value").asText()));
|
||||||
}
|
}
|
||||||
}).collect(Collectors.toList()));
|
}).flatMap(Collection::stream).collect(Collectors.toList()));
|
||||||
for (int i = 0; i < keywordNodes.size(); i++) {
|
for (int i = 0; i < keywordNodes.size(); i++) {
|
||||||
rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText());
|
rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText());
|
||||||
}
|
}
|
||||||
|
@ -125,6 +126,17 @@ public class DatasetRDAMapper {
|
||||||
if (!issuedNodes.isEmpty()) {
|
if (!issuedNodes.isEmpty()) {
|
||||||
rda.setIssued(issuedNodes.get(0).get("value").asText());
|
rda.setIssued(issuedNodes.get(0).get("value").asText());
|
||||||
}
|
}
|
||||||
|
List<JsonNode> contributorNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.contributor");
|
||||||
|
if (!contributorNodes.isEmpty()) {
|
||||||
|
contributors.addAll(contributorNodes.stream().map(contributorNode -> {
|
||||||
|
JsonNode value = contributorNode.get("value");
|
||||||
|
if (value.isArray()) {
|
||||||
|
return StreamSupport.stream(value.spliterator(), false).map(node -> ContributorRDAMapper.toRDA(node.asText())).collect(Collectors.toList());
|
||||||
|
} else {
|
||||||
|
return Collections.singletonList(new Contributor());
|
||||||
|
}
|
||||||
|
}).flatMap(Collection::stream).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
List<JsonNode> foundNodes = Stream.of(typeNodes, languageNodes, metadataNodes, qaNodes, preservationNodes, distributionNodes,
|
List<JsonNode> foundNodes = Stream.of(typeNodes, languageNodes, metadataNodes, qaNodes, preservationNodes, distributionNodes,
|
||||||
keywordNodes, personalDataNodes, securityAndPrivacyNodes, sensitiveDataNodes, technicalResourceNodes).flatMap(Collection::stream).collect(Collectors.toList());
|
keywordNodes, personalDataNodes, securityAndPrivacyNodes, sensitiveDataNodes, technicalResourceNodes).flatMap(Collection::stream).collect(Collectors.toList());
|
||||||
templateIdsToValues.entrySet().forEach(entry -> {
|
templateIdsToValues.entrySet().forEach(entry -> {
|
||||||
|
@ -206,8 +218,20 @@ public class DatasetRDAMapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
List <String> keywordIds = rda.getAdditionalProperties().entrySet().stream().filter(entry -> entry.getKey().startsWith("keyword")).map(entry -> entry.getValue().toString()).collect(Collectors.toList());
|
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++) {
|
for (int i = 0; i < keywordIds.size(); i++) {
|
||||||
properties.put(keywordIds.get(i), rda.getKeyword().get(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))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data");
|
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data");
|
||||||
|
@ -239,4 +263,11 @@ public class DatasetRDAMapper {
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Tag toTagEntity(String name) {
|
||||||
|
Tag tag = new Tag();
|
||||||
|
tag.setId("");
|
||||||
|
tag.setName(name);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class DmpRDAMapper {
|
||||||
rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
|
rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
// rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
|
// rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
|
||||||
rda.setDataset(dmp.getDataset().stream().map(dataset -> datasetRDAMapper.toRDA(dataset)).collect(Collectors.toList()));
|
rda.setDataset(dmp.getDataset().stream().map(dataset -> datasetRDAMapper.toRDA(dataset, rda.getContributor())).collect(Collectors.toList()));
|
||||||
rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant())));
|
rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant())));
|
||||||
rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray());
|
rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray());
|
||||||
return rda;
|
return rda;
|
||||||
|
|
Loading…
Reference in New Issue