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.setGroupId(UUID.randomUUID());
|
||||
if (dmp.getResearchers() != null && !dmp.getResearchers().isEmpty()) {
|
||||
dmp.getResearchers().forEach(researcher -> {
|
||||
dmp.getResearchers().stream().filter(Objects::nonNull).forEach(researcher -> {
|
||||
researcher.setId(UUID.randomUUID());
|
||||
researcher.setCreated(new Date());
|
||||
researcher.setModified(new Date());
|
||||
|
|
|
@ -341,7 +341,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
|
|||
this.id = entity.getId();
|
||||
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.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.label = entity.getLabel();
|
||||
this.grant = new Grant();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.models.data.dmp;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import eu.eudat.models.DataModel;
|
||||
import eu.eudat.logic.utilities.helpers.LabelGenerator;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -8,6 +9,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Researcher implements DataModel<eu.eudat.data.entities.Researcher, Researcher>, LabelGenerator {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Researcher.class);
|
||||
private String label;
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
package eu.eudat.models.rda.mapper;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.data.entities.Researcher;
|
||||
import eu.eudat.data.entities.UserDMP;
|
||||
import eu.eudat.models.rda.Contributor;
|
||||
import eu.eudat.models.rda.ContributorId;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class ContributorRDAMapper {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContributorRDAMapper.class);
|
||||
|
||||
public static Contributor toRDA(UserDMP userDMP) {
|
||||
Contributor rda = new Contributor();
|
||||
|
@ -28,9 +32,21 @@ public class ContributorRDAMapper {
|
|||
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) {
|
||||
Researcher entity = new Researcher();
|
||||
String reference;
|
||||
if (rda.getContributorId() != null) {
|
||||
if (rda.getContributorId().getType() == ContributorId.Type.ORCID) {
|
||||
String id = rda.getContributorId().getIdentifier().replace("http://orcid.org/", "");
|
||||
reference = "orcid:" + id;
|
||||
|
@ -45,6 +61,9 @@ public class ContributorRDAMapper {
|
|||
entity.setReference(reference);
|
||||
entity.setLabel(rda.getName());
|
||||
entity.setPrimaryEmail(rda.getMbox());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ 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.Contributor;
|
||||
import eu.eudat.models.rda.Dataset;
|
||||
import eu.eudat.models.rda.Language;
|
||||
import org.json.JSONObject;
|
||||
|
@ -36,7 +37,7 @@ public class DatasetRDAMapper {
|
|||
}
|
||||
|
||||
@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();
|
||||
// rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
|
||||
rda.setTitle(dataset.getLabel());
|
||||
|
@ -91,11 +92,11 @@ public class DatasetRDAMapper {
|
|||
rda.setKeyword(keywordNodes.stream().map(keywordNode -> {
|
||||
JsonNode value = keywordNode.get("value");
|
||||
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 {
|
||||
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++) {
|
||||
rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText());
|
||||
}
|
||||
|
@ -125,6 +126,17 @@ public class DatasetRDAMapper {
|
|||
if (!issuedNodes.isEmpty()) {
|
||||
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,
|
||||
keywordNodes, personalDataNodes, securityAndPrivacyNodes, sensitiveDataNodes, technicalResourceNodes).flatMap(Collection::stream).collect(Collectors.toList());
|
||||
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());
|
||||
boolean takeAll = false;
|
||||
if (keywordIds.size() < rda.getKeyword().size()) {
|
||||
takeAll = true;
|
||||
}
|
||||
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");
|
||||
|
@ -239,4 +263,11 @@ public class DatasetRDAMapper {
|
|||
|
||||
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.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.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray());
|
||||
return rda;
|
||||
|
|
Loading…
Reference in New Issue