Add RDA Import

This commit is contained in:
George Kalampokis 2020-03-26 18:39:25 +02:00
parent 7a921ec33a
commit b03d45661e
20 changed files with 531 additions and 56 deletions

View File

@ -53,6 +53,9 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import static org.springframework.http.MediaType.APPLICATION_ATOM_XML;
import static org.springframework.http.MediaType.APPLICATION_JSON;
@RestController
@CrossOrigin
@ -224,8 +227,12 @@ public class DMPs extends BaseController {
}
@RequestMapping(method = RequestMethod.POST, value = {"/upload"})
public ResponseEntity<ResponseItem> dmpXmlUpload(@RequestParam("file") MultipartFile[] files, Principal principal) throws Exception {
this.dataManagementPlanManager.createDmpFromXml(this.getApiContext(), files, principal);
public ResponseEntity<ResponseItem> dmpUpload(@RequestParam("file") MultipartFile[] files, Principal principal) throws Exception {
if (files[0].getContentType().equals(APPLICATION_JSON.toString())) {
this.dataManagementPlanManager.createFromRDA(files, principal);
} else if (files[0].getContentType().equals(APPLICATION_ATOM_XML.toString())) {
this.dataManagementPlanManager.createDmpFromXml(this.getApiContext(), files, principal);
}
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List>()
.status(ApiMessageCode.SUCCESS_MESSAGE));
}

View File

@ -131,6 +131,13 @@ public class DataManagementPlanManager {
if (fieldsGroup.equals("listing")) {
itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
.selectAsync(item -> {
if (item.getUsers().stream().noneMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) {
for (UserDMP userDMP: item.getUsers()) {
userDMP.setRole(UserDMP.UserDMPRoles.OWNER.getValue());
databaseRepository.getUserDmpDao().createOrUpdate(userDMP);
break;
}
}
item.setDataset(
item.getDataset().stream()
.filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue())).collect(Collectors.toList()).stream()
@ -1329,6 +1336,34 @@ public class DataManagementPlanManager {
return dataManagementPlans;
}
public List<DMP> createFromRDA(MultipartFile[] files, Principal principal) throws IOException {
if (principal.getId() == null) {
throw new UnauthorisedException("No user is logged in");
}
List<DMP> result = new ArrayList<>();
for (MultipartFile file: files) {
DMP dmp = rdaManager.convertToEntity(new String(file.getBytes(), "UTF-8"));
UserInfo me = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
dmp.setModified(new Date());
dmp.setCreator(me);
dmp.setVersion(0);
dmp.setStatus((short)0);
dmp.setGroupId(UUID.randomUUID());
databaseRepository.getDmpDao().createOrUpdate(dmp);
assignUser(dmp, me);
dmp.getDataset().forEach(dataset -> {
dataset.setStatus(Dataset.Status.SAVED.getValue());
dataset.setCreated(new Date());
dataset.setModified(new Date());
dataset.setDmp(dmp);
databaseRepository.getDatasetDao().createOrUpdate(dataset);
});
result.add(dmp);
}
return result;
}
public DataTableData<DatasetProfileListingModel> getDatasetProfilesUsedByDMP(DatasetProfileTableRequestItem datasetProfileTableRequestItem, Principal principal) {
datasetProfileTableRequestItem.getCriteria().setFilter(DatasetProfileCriteria.DatasetProfileFilter.DMPs.getValue());
datasetProfileTableRequestItem.getCriteria().setUserId(principal.getId());

View File

@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
import java.io.IOException;
import java.text.SimpleDateFormat;
@Component
@ -35,4 +36,12 @@ public class RDAManager {
return result;
}
public DMP convertToEntity(String json) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss Z"));
Dmp rda = mapper.readValue(json, Dmp.class);
return dmpRDAMapper.toEntity(rda);
}
}

View File

@ -38,7 +38,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
"sensitive_data",
"technical_resource",
"title",
"type"
"type",
"additional_properties"
})
public class Dataset implements Serializable
{
@ -182,7 +183,7 @@ public class Dataset implements Serializable
@JsonProperty("type")
@JsonPropertyDescription("If appropriate, type according to: DataCite and/or COAR dictionary. Otherwise use the common name for the type, e.g. raw data, software, survey, etc. https://schema.datacite.org/meta/kernel-4.1/doc/DataCite-MetadataKernel_v4.1.pdf http://vocabularies.coar-repositories.org/pubby/resource_type.html")
private String type;
@JsonIgnore
@JsonProperty("additional_properties")
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
private final static long serialVersionUID = -6931119120629009399L;
@ -524,12 +525,12 @@ public class Dataset implements Serializable
this.type = type;
}
@JsonAnyGetter
@JsonProperty("additional_properties")
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
@JsonProperty("additional_properties")
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

View File

@ -34,7 +34,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
"format",
"host",
"license",
"title"
"title",
"additional_properties"
})
public class Distribution implements Serializable
{
@ -131,7 +132,7 @@ public class Distribution implements Serializable
@JsonProperty("title")
@JsonPropertyDescription("Title is a property in both Dataset and Distribution, in compliance with W3C DCAT. In some cases these might be identical, but in most cases the Dataset represents a more abstract concept, while the distribution can point to a specific file.")
private String title;
@JsonIgnore
@JsonProperty("additional_properties")
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
private final static long serialVersionUID = -6018365280419917902L;
@ -359,12 +360,12 @@ public class Distribution implements Serializable
this.title = title;
}
@JsonAnyGetter
@JsonProperty("additional_properties")
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
@JsonProperty("additional_properties")
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

View File

@ -39,7 +39,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
"language",
"modified",
"project",
"title"
"title",
"additional_properties"
})
public class Dmp implements Serializable
{
@ -173,7 +174,7 @@ public class Dmp implements Serializable
@JsonProperty("title")
@JsonPropertyDescription("Title of a DMP")
private String title;
@JsonIgnore
@JsonProperty("additional_properties")
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
private final static long serialVersionUID = 4599713332472772292L;
@ -499,12 +500,12 @@ public class Dmp implements Serializable
this.title = title;
}
@JsonAnyGetter
@JsonProperty("additional_properties")
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
@JsonProperty("additional_properties")
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

View File

@ -25,7 +25,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
@JsonPropertyOrder({
"description",
"language",
"metadata_standard_id"
"metadata_standard_id",
"additional_properties"
})
public class Metadatum implements Serializable
{
@ -58,7 +59,7 @@ public class Metadatum implements Serializable
*/
@JsonProperty("metadata_standard_id")
private MetadataStandardId metadataStandardId;
@JsonIgnore
@JsonProperty("additional_properties")
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
private final static long serialVersionUID = 6511312853153406190L;
@ -132,12 +133,12 @@ public class Metadatum implements Serializable
this.metadataStandardId = metadataStandardId;
}
@JsonAnyGetter
@JsonProperty("additional_properties")
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
@JsonProperty("additional_properties")
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

View File

@ -22,7 +22,8 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"description",
"title"
"title",
"additional_properties"
})
public class SecurityAndPrivacy implements Serializable
{
@ -46,7 +47,7 @@ public class SecurityAndPrivacy implements Serializable
@JsonProperty("title")
@JsonPropertyDescription("Title")
private String title;
@JsonIgnore
@JsonProperty("additional_properties")
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
private final static long serialVersionUID = 7863747935827682977L;
@ -96,12 +97,12 @@ public class SecurityAndPrivacy implements Serializable
this.title = title;
}
@JsonAnyGetter
@JsonProperty("additional_properties")
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
@JsonProperty("additional_properties")
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

View File

@ -22,7 +22,8 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"description",
"name"
"name",
"additional_properties"
})
public class TechnicalResource implements Serializable
{
@ -46,7 +47,7 @@ public class TechnicalResource implements Serializable
@JsonProperty("name")
@JsonPropertyDescription("Name of the technical resource")
private String name;
@JsonIgnore
@JsonProperty("additional_properties")
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
private final static long serialVersionUID = -7451757227129483110L;
@ -96,12 +97,12 @@ public class TechnicalResource implements Serializable
this.name = name;
}
@JsonAnyGetter
@JsonProperty("additional_properties")
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
@JsonProperty("additional_properties")
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

View File

@ -12,4 +12,8 @@ public class ContactIdRDAMapper {
rda.setType(ContactId.Type.OTHER);
return rda;
}
public static UUID toEntity(ContactId rda) {
return UUID.fromString(rda.getIdentifier());
}
}

View File

@ -13,4 +13,12 @@ public class ContactRDAMapper {
rda.setContactId(ContactIdRDAMapper.toRDA(creator.getId()));
return rda;
}
public static UserInfo toEntity(Contact rda) {
UserInfo entity = new UserInfo();
entity.setId(ContactIdRDAMapper.toEntity(rda.getContactId()));
entity.setName(rda.getName());
entity.setEmail(rda.getMbox());
return entity;
}
}

View File

@ -2,28 +2,34 @@ 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.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 org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Component
public class DatasetRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(DatasetRDAMapper.class);
private DatasetManager datasetManager;
private ApiContext apiContext;
@Autowired
public DatasetRDAMapper(DatasetManager datasetManager) {
public DatasetRDAMapper(DatasetManager datasetManager, ApiContext apiContext) {
this.datasetManager = datasetManager;
this.apiContext = apiContext;
}
@Transactional
@ -32,9 +38,10 @@ public class DatasetRDAMapper {
rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
rda.setTitle(dataset.getLabel());
rda.setDescription(dataset.getDescription());
// rda.setAdditionalProperty("template", dataset.getProfile().getId());
rda.setAdditionalProperty("template", dataset.getProfile().getId());
try {
JSONObject jObject = new JSONObject(dataset.getProperties());
Map<String, Object> templateIdsToValues = jObject.toMap();
DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(dataset);
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset));
ObjectMapper mapper = new ObjectMapper();
@ -55,6 +62,9 @@ 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()));
for (int i = 0; i < qaNodes.size(); i++) {
rda.setAdditionalProperty("qa" + (i + 1), qaNodes.get(i).get("id").asText());
}
}
List<JsonNode> preservationNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.preservation_statement");
if (!preservationNodes.isEmpty()) {
@ -67,6 +77,9 @@ public class DatasetRDAMapper {
List<JsonNode> keywordNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.keyword");
if (!keywordNodes.isEmpty()) {
rda.setKeyword(keywordNodes.stream().map(keywordNode -> keywordNode.get("value").asText()).collect(Collectors.toList()));
for (int i = 0; i < keywordNodes.size(); i++) {
rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText());
}
}
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data");
if (!personalDataNodes.isEmpty()) {
@ -84,6 +97,14 @@ public class DatasetRDAMapper {
if (!technicalResourceNodes.isEmpty()) {
rda.setTechnicalResource(TechnicalResourceRDAMapper.toRDAList(technicalResourceNodes));
}
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()) {
rda.setAdditionalProperty(entry.getKey(), entry.getValue());
}
});
} catch (Exception e) {
@ -93,4 +114,87 @@ public class DatasetRDAMapper {
return rda;
}
public eu.eudat.data.entities.Dataset toEntity(Dataset rda) {
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);
}
try {
Map<String, Object> properties = new HashMap<>();
DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
datasetWizardModel.setProfile(entity.getProfile().getId());
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");
if (!languageNodes.isEmpty()) {
properties.put(languageNodes.get(0).get("id").asText(), rda.getLanguage().value());
}
if (rda.getMetadata() != null) {
properties.putAll(MetadataRDAMapper.toProperties(rda.getMetadata()));
}
List <String> qaIds = rda.getAdditionalProperties().entrySet().stream().filter(entry -> entry.getKey().startsWith("qa")).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> preservationNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.preservation_statement");
if (!preservationNodes.isEmpty()) {
properties.put(preservationNodes.get(0).get("id").asText(), rda.getPreservationStatement());
}
if (rda.getDistribution() != null) {
properties.putAll(DistributionRDAMapper.toProperties(rda.getDistribution()));
}
List <String> keywordIds = rda.getAdditionalProperties().entrySet().stream().filter(entry -> entry.getKey().startsWith("keyword")).map(entry -> entry.getValue().toString()).collect(Collectors.toList());
for (int i = 0; i < keywordIds.size(); i++) {
properties.put(keywordIds.get(i), rda.getKeyword().get(i));
}
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()
.filter(entry -> !entry.getKey().equals("template") && !entry.getKey().startsWith("qa") && !entry.getKey().startsWith("keyword"))
.forEach(entry -> properties.put(entry.getKey(), entry.getValue()));
entity.setProperties(new ObjectMapper().writeValueAsString(properties));
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return entity;
}
}

View File

@ -1,13 +1,17 @@
package eu.eudat.models.rda.mapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.lowagie.text.ExceptionConverter;
import eu.eudat.logic.utilities.helpers.MyStringUtils;
import eu.eudat.models.rda.Distribution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URI;
import java.util.*;
public class DistributionRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(DistributionRDAMapper.class);
public static List<Distribution> toRDAList(List<JsonNode> nodes) {
Map<String, Distribution> rdaMap = new HashMap<>();
@ -19,35 +23,43 @@ public class DistributionRDAMapper {
if (!rdaMap.containsValue(rda)) {
rdaMap.put(node.get("numbering").asText(), rda);
}
for (PropertyName propertyName : PropertyName.values()) {
if (rdaProperty.contains(propertyName.getName())) {
switch (propertyName) {
for (ExportPropertyName exportPropertyName : ExportPropertyName.values()) {
if (rdaProperty.contains(exportPropertyName.getName())) {
switch (exportPropertyName) {
case ACCESS_URL:
rda.setAccessUrl(rdaValue);
rda.setAdditionalProperty(ImportPropertyName.ACCESS_URL.getName(), node.get("id").asText());
break;
case AVAILABLE_UTIL:
rda.setAvailableUntil(rdaValue);
rda.setAdditionalProperty(ImportPropertyName.AVAILABLE_UTIL.getName(), node.get("id").asText());
break;
case DOWNLOAD_URL:
rda.setDownloadUrl(URI.create(rdaValue));
rda.setAdditionalProperty(ImportPropertyName.DOWNLOAD_URL.getName(), node.get("id").asText());
break;
case DESCRIPTION:
rda.setDescription(rdaValue);
rda.setAdditionalProperty(ImportPropertyName.DESCRIPTION.getName(), node.get("id").asText());
break;
case DATA_ACCESS:
rda.setDataAccess(Distribution.DataAccess.fromValue(rdaValue));
rda.setAdditionalProperty(ImportPropertyName.DATA_ACCESS.getName(), node.get("id").asText());
break;
case BYTE_SIZE:
rda.setByteSize(Integer.parseInt(rdaValue));
rda.setAdditionalProperty(ImportPropertyName.BYTE_SIZE.getName(), node.get("id").asText());
break;
case LICENSE:
rda.setLicense(Collections.singletonList(LicenseRDAMapper.toRDA(node)));
break;
case FORMAT:
rda.setFormat(Collections.singletonList(rdaValue));
rda.setAdditionalProperty(ImportPropertyName.FORMAT.getName(), node.get("id").asText());
break;
case TITLE:
rda.setTitle(rdaValue);
rda.setAdditionalProperty(ImportPropertyName.TITLE.getName(), node.get("id").asText());
break;
case HOST:
rda.setHost(HostRDAMapper.toRDA(nodes, node.get("numbering").asText()));
@ -60,6 +72,49 @@ public class DistributionRDAMapper {
return new ArrayList<>(rdaMap.values());
}
public static Map<String, String> toProperties(List<Distribution> rdas) {
Map<String, String> properties = new HashMap<>();
rdas.forEach(rda -> {
rda.getAdditionalProperties().entrySet().forEach(entry -> {
try {
ImportPropertyName importPropertyName = ImportPropertyName.fromString(entry.getKey());
switch (importPropertyName) {
case ACCESS_URL:
properties.put(entry.getValue().toString(), rda.getAccessUrl());
break;
case TITLE:
properties.put(entry.getValue().toString(), rda.getTitle());
break;
case DESCRIPTION:
properties.put(entry.getValue().toString(), rda.getDescription());
break;
case FORMAT:
properties.put(entry.getValue().toString(), rda.getFormat().get(0));
break;
case BYTE_SIZE:
properties.put(entry.getValue().toString(), rda.getByteSize().toString());
break;
case DATA_ACCESS:
properties.put(entry.getValue().toString(), rda.getDataAccess().value());
break;
case DOWNLOAD_URL:
properties.put(entry.getValue().toString(), rda.getDownloadUrl().toString());
break;
case AVAILABLE_UTIL:
properties.put(entry.getValue().toString(), rda.getAvailableUntil());
break;
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
});
});
return properties;
}
public static Distribution toRDA(JsonNode node) {
Distribution rda = new Distribution();
String rdaProperty = node.get("rdaProperty").asText();
@ -95,7 +150,7 @@ public class DistributionRDAMapper {
.max(Comparator.comparingInt(entry -> MyStringUtils.getFirstDifference(entry.getKey(), numbering))).map(Map.Entry::getValue).orElse(new Distribution());
}
private enum PropertyName {
private enum ExportPropertyName {
ACCESS_URL("access_url"),
AVAILABLE_UTIL("available_util"),
BYTE_SIZE("byte_size"),
@ -109,7 +164,7 @@ public class DistributionRDAMapper {
private final String name;
PropertyName(String name) {
ExportPropertyName(String name) {
this.name = name;
}
@ -117,4 +172,36 @@ public class DistributionRDAMapper {
return name;
}
}
private enum ImportPropertyName {
ACCESS_URL("accessurlId"),
AVAILABLE_UTIL("availableUtilId"),
BYTE_SIZE("byteSizeId"),
DATA_ACCESS("dataAccessId"),
DESCRIPTION("descriptionId"),
DOWNLOAD_URL("downloadUrlId"),
FORMAT("formatId"),
/*HOST("host"),
LICENSE("license"),*/
TITLE("titleId");
private final String name;
ImportPropertyName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static ImportPropertyName fromString(String name) throws Exception {
for (ImportPropertyName importPropertyName: ImportPropertyName.values()) {
if (importPropertyName.getName().equals(name)) {
return importPropertyName;
}
}
throw new Exception("No name available");
}
}
}

View File

@ -1,24 +1,26 @@
package eu.eudat.models.rda.mapper;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.entities.*;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.rda.Dmp;
import eu.eudat.models.rda.DmpId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
import java.util.Collections;
import java.util.*;
import java.util.stream.Collectors;
@Component
public class DmpRDAMapper {
private DatasetRDAMapper datasetRDAMapper;
private ApiContext apiContext;
@Autowired
public DmpRDAMapper(DatasetRDAMapper datasetRDAMapper) {
public DmpRDAMapper(DatasetRDAMapper datasetRDAMapper, ApiContext apiContext) {
this.datasetRDAMapper = datasetRDAMapper;
this.apiContext = apiContext;
}
@Transactional
@ -44,8 +46,28 @@ public class DmpRDAMapper {
rda.setContributor(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
rda.setDataset(dmp.getDataset().stream().map(dataset -> datasetRDAMapper.toRDA(dataset)).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;
}
public DMP toEntity(Dmp rda) {
DMP entity = new DMP();
entity.setLabel(rda.getTitle());
if (rda.getDmpId().getType() == DmpId.Type.DOI) {
entity.setDoi(rda.getDmpId().getIdentifier());
}
entity.setCreated(rda.getCreated());
entity.setModified(rda.getModified());
entity.setDescription(rda.getDescription());
entity.setDataset(rda.getDataset().stream().map(rda1 -> datasetRDAMapper.toEntity(rda1)).collect(Collectors.toSet()));
Map<String, Object> result = ProjectRDAMapper.toEntity(rda.getProject().get(0), apiContext);
entity.setProject((Project) result.get("project"));
result.entrySet().stream().filter(entry -> entry.getKey().startsWith("grant")).forEach(entry -> entity.setGrant((Grant) entry.getValue()));
entity.setAssociatedDmps(((List<String>) rda.getAdditionalProperties().get("templates")).stream().map(this::getProfile).collect(Collectors.toSet()));
return entity;
}
private DatasetProfile getProfile(String id) {
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
}
}

View File

@ -1,7 +1,8 @@
package eu.eudat.models.rda.mapper;
import eu.eudat.data.entities.Funder;
import eu.eudat.data.dao.criteria.GrantCriteria;
import eu.eudat.data.entities.Grant;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.rda.Funding;
public class FundingRDAMapper {
@ -22,4 +23,10 @@ public class FundingRDAMapper {
rda.setGrantId(GrantIdRDAMapper.toRDA(shortReference));
return rda;
}
public static Grant toEntity(Funding rda, ApiContext apiContext) {
GrantCriteria criteria = new GrantCriteria();
criteria.setReference(rda.getGrantId().getIdentifier());
return apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getWithCriteria(criteria).getSingle();
}
}

View File

@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
public class MetadataRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(MetadataRDAMapper.class);
@ -36,6 +37,7 @@ public class MetadataRDAMapper {
rdas.add(new Metadatum());
rdas.get(rdas.size() - 1).setMetadataStandardId(MetadataStandardIdRDAMapper.toRDA(data.get("uri").asText()));
rdas.get(rdas.size() - 1).setDescription(data.get("label").asText());
rdas.get(rdas.size() - 1).setAdditionalProperty("fieldId", node.get("id").asText());
rdaMap.put(data.get("uri").asText(), node.get("numbering").asText());
}
}
@ -45,6 +47,7 @@ public class MetadataRDAMapper {
} else if (rdaValue instanceof TextNode && rdaProperty.contains("identifier") && !rdaValue.asText().isEmpty()) {
rdas.add(new Metadatum());
rdas.get(rdas.size() - 1).setMetadataStandardId(MetadataStandardIdRDAMapper.toRDA(rdaValue.asText()));
rdas.get(rdas.size() - 1).setAdditionalProperty("identifierId", node.get("id").asText());
rdaMap.put(rdaValue.asText(), node.get("numbering").asText());
}
break;
@ -53,6 +56,7 @@ public class MetadataRDAMapper {
Metadatum rda = getRelative(rdas, rdaMap, node.get("numbering").asText());
if (rda != null) {
rda.setDescription(rdaValue.asText());
rda.setAdditionalProperty("descriptionId", node.get("id").asText());
} else {
rdas.stream().filter(rda1 -> rda1.getDescription() == null || rda1.getDescription().isEmpty()).forEach(rda1 -> rda1.setDescription(rdaValue.asText()));
}
@ -64,6 +68,7 @@ public class MetadataRDAMapper {
Metadatum rda = getRelative(rdas, rdaMap, node.get("numbering").asText());
if (rda != null) {
rda.setLanguage(lang);
rda.setAdditionalProperty("languageId", node.get("id").asText());
} else {
rdas.forEach(rda1 -> rda1.setLanguage(lang));
}
@ -77,6 +82,40 @@ public class MetadataRDAMapper {
return rdas;
}
public static Map<String, String> toProperties(List<Metadatum> rdas) {
Map<String, String> properties = new HashMap<>();
List<Object> standardIds = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
rdas.forEach(rda -> {
rda.getAdditionalProperties().entrySet().forEach(entry -> {
try {
switch (entry.getKey()) {
case "fieldId":
Map<String, String> metadata = toMap(rda);
standardIds.add(metadata);
properties.put(entry.getValue().toString(), mapper.writeValueAsString(standardIds));
break;
case "identifierId":
properties.put(entry.getValue().toString(), rda.getMetadataStandardId().getIdentifier());
break;
case "descriptionId":
properties.put(entry.getValue().toString(), rda.getDescription());
break;
case "languageId":
if (rda.getLanguage() != null) {
properties.put(entry.getValue().toString(), rda.getLanguage().value());
}
break;
}
}catch (Exception e) {
logger.error(e.getMessage(), e);
}
});
});
return properties;
}
public static Metadatum toRDA(JsonNode node) {
Metadatum rda = new Metadatum();
String rdaProperty = node.get("rdaProperty").asText();
@ -122,4 +161,31 @@ public class MetadataRDAMapper {
return name;
}
}
private static Map<String, String> toMap(Metadatum rda) {
Map<String, String> result = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> metadata = mapper.convertValue(rda, Map.class);
Map<String, String> metadataStandardId = mapper.convertValue(metadata.get("metadata_standard_id"), Map.class);
String url = metadataStandardId.remove("identifier");
metadataStandardId.remove("type");
metadataStandardId.put("uri", url);
metadata.remove("additional_properties");
metadata.remove("metadata_standard_id");
Map<String, String> newMetadata = metadata.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().toString()));
String label = newMetadata.remove("description");
newMetadata.put("label", label);
result.putAll(newMetadata);
result.putAll(metadataStandardId);
return result;
}
}

View File

@ -2,9 +2,10 @@ package eu.eudat.models.rda.mapper;
import eu.eudat.data.entities.Funder;
import eu.eudat.data.entities.Grant;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.rda.Project;
import java.util.Collections;
import java.util.*;
public class ProjectRDAMapper {
@ -22,4 +23,23 @@ public class ProjectRDAMapper {
return rda;
}
public static Map<String, Object> toEntity(Project rda, ApiContext apiContext) {
Map<String, Object> entities = new HashMap<>();
entities.put("project", new eu.eudat.data.entities.Project());
((eu.eudat.data.entities.Project) entities.get("project")).setLabel(rda.getTitle());
((eu.eudat.data.entities.Project) entities.get("project")).setDescription(rda.getDescription());
((eu.eudat.data.entities.Project) entities.get("project")).setId(UUID.randomUUID());
((eu.eudat.data.entities.Project) entities.get("project")).setStatus((short)1);
((eu.eudat.data.entities.Project) entities.get("project")).setCreated(new Date());
((eu.eudat.data.entities.Project) entities.get("project")).setModified(new Date());
((eu.eudat.data.entities.Project) entities.get("project")).setType(0);
apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().createOrUpdate(((eu.eudat.data.entities.Project) entities.get("project")));
for (int i = 0; i < rda.getFunding().size(); i++) {
entities.put("grant" + (i + 1), FundingRDAMapper.toEntity(rda.getFunding().get(i), apiContext));
}
return entities;
}
}

View File

@ -3,10 +3,13 @@ package eu.eudat.models.rda.mapper;
import com.fasterxml.jackson.databind.JsonNode;
import eu.eudat.logic.utilities.helpers.MyStringUtils;
import eu.eudat.models.rda.SecurityAndPrivacy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
public class SecurityAndPrivacyRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(SecurityAndPrivacyRDAMapper.class);
public static List<SecurityAndPrivacy> toRDAList(List<JsonNode> nodes) {
Map<String, SecurityAndPrivacy> rdaMap = new HashMap<>();
@ -19,14 +22,16 @@ public class SecurityAndPrivacyRDAMapper {
if (!rdaMap.containsValue(rda)) {
rdaMap.put(node.get("numbering").asText(), rda);
}
for (PropertyName propertyName: PropertyName.values()) {
if (rdaProperty.contains(propertyName.getName())) {
switch (propertyName) {
for (ExportPropertyName exportPropertyName : ExportPropertyName.values()) {
if (rdaProperty.contains(exportPropertyName.getName())) {
switch (exportPropertyName) {
case TITLE:
rda.setTitle(rdaValue);
rda.getAdditionalProperties().put(ImportPropertyName.TITLE.getName(), node.get("id").asText());
break;
case DESCRIPTION:
rda.setDescription(rdaValue);
rda.getAdditionalProperties().put(ImportPropertyName.DESCRIPTION.getName(), node.get("id").asText());
break;
}
}
@ -36,6 +41,27 @@ public class SecurityAndPrivacyRDAMapper {
return new ArrayList<>(rdaMap.values());
}
public static Map<String, String> toProperties(List<SecurityAndPrivacy> rdas) {
Map<String, String> properties = new HashMap<>();
rdas.forEach(rda -> rda.getAdditionalProperties().entrySet().forEach(entry -> {
try {
ImportPropertyName importPropertyName = ImportPropertyName.fromString(entry.getKey());
switch(importPropertyName) {
case TITLE:
properties.put(entry.getValue().toString(), rda.getTitle());
break;
case DESCRIPTION:
properties.put(entry.getValue().toString(), rda.getDescription());
break;
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}));
return properties;
}
public static SecurityAndPrivacy toRDA(JsonNode node) {
SecurityAndPrivacy rda = new SecurityAndPrivacy();
String rdaProperty = node.get("rdaProperty").asText();
@ -55,13 +81,13 @@ public class SecurityAndPrivacyRDAMapper {
.max(Comparator.comparingInt(entry -> MyStringUtils.getFirstDifference(entry.getKey(), numbering))).map(Map.Entry::getValue).orElse(new SecurityAndPrivacy());
}
private enum PropertyName {
private enum ExportPropertyName {
TITLE("title"),
DESCRIPTION("description");
private String name;
PropertyName(String name) {
ExportPropertyName(String name) {
this.name = name;
}
@ -69,4 +95,28 @@ public class SecurityAndPrivacyRDAMapper {
return name;
}
}
private enum ImportPropertyName {
TITLE("titleId"),
DESCRIPTION("descriptionId");
private String name;
ImportPropertyName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static ImportPropertyName fromString(String name) throws Exception {
for (ImportPropertyName importPropertyName: ImportPropertyName.values()) {
if (importPropertyName.getName().equals(name)) {
return importPropertyName;
}
}
throw new Exception("Property not available");
}
}
}

View File

@ -2,12 +2,14 @@ package eu.eudat.models.rda.mapper;
import com.fasterxml.jackson.databind.JsonNode;
import eu.eudat.logic.utilities.helpers.MyStringUtils;
import eu.eudat.models.rda.SecurityAndPrivacy;
import eu.eudat.models.rda.TechnicalResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
public class TechnicalResourceRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(TechnicalResourceRDAMapper.class);
public static List<TechnicalResource> toRDAList(List<JsonNode> nodes) {
Map<String, TechnicalResource> rdaMap = new HashMap<>();
@ -20,14 +22,16 @@ public class TechnicalResourceRDAMapper {
if (!rdaMap.containsValue(rda)) {
rdaMap.put(node.get("numbering").asText(), rda);
}
for (PropertyName propertyName: PropertyName.values()) {
if (rdaProperty.contains(propertyName.getName())) {
switch (propertyName) {
for (ExportPropertyName exportPropertyName : ExportPropertyName.values()) {
if (rdaProperty.contains(exportPropertyName.getName())) {
switch (exportPropertyName) {
case NAME:
rda.setName(rdaValue);
rda.setAdditionalProperty(ImportPropertyName.NAME.getName(), node.get("id").asText());
break;
case DESCRIPTION:
rda.setDescription(rdaValue);
rda.setAdditionalProperty(ImportPropertyName.DESCRIPTION.getName(), node.get("id").asText());
break;
}
}
@ -37,6 +41,28 @@ public class TechnicalResourceRDAMapper {
return new ArrayList<>(rdaMap.values());
}
public static Map<String, String> toProperties(List<TechnicalResource> rdas) {
Map<String, String> properties = new HashMap<>();
rdas.forEach(rda -> rda.getAdditionalProperties().entrySet().forEach(entry -> {
try {
ImportPropertyName importPropertyName = ImportPropertyName.fromString(entry.getKey());
switch(importPropertyName) {
case DESCRIPTION:
properties.put(entry.getValue().toString(), rda.getDescription());
break;
case NAME:
properties.put(entry.getValue().toString(), rda.getName());
break;
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}));
return properties;
}
public static TechnicalResource toRDA(JsonNode node) {
TechnicalResource rda = new TechnicalResource();
String rdaProperty = node.get("rdaProperty").asText();
@ -56,13 +82,13 @@ public class TechnicalResourceRDAMapper {
.max(Comparator.comparingInt(entry -> MyStringUtils.getFirstDifference(entry.getKey(), numbering))).map(Map.Entry::getValue).orElse(new TechnicalResource());
}
private enum PropertyName {
private enum ExportPropertyName {
NAME("name"),
DESCRIPTION("description");
private String name;
PropertyName(String name) {
ExportPropertyName(String name) {
this.name = name;
}
@ -70,4 +96,28 @@ public class TechnicalResourceRDAMapper {
return name;
}
}
private enum ImportPropertyName {
NAME("nameId"),
DESCRIPTION("descriptionId");
private String name;
ImportPropertyName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static ImportPropertyName fromString(String name) throws Exception {
for (ImportPropertyName importPropertyName: ImportPropertyName.values()) {
if (importPropertyName.getName().equals(name)) {
return importPropertyName;
}
}
throw new Exception("Property name not available");
}
}
}

View File

@ -7,7 +7,7 @@
<button class="col-auto attach-file" (click)="fileInput.click()" type="button">
<mat-icon color="primary">attach_file</mat-icon>
</button>
<input class="hidden" #fileInput type="file" (change)="uploadFile($event)" accept="text/xml">
<input class="hidden" #fileInput type="file" (change)="uploadFile($event)" accept="text/xml, application/json">
</div>
</div>
<div class="row">