madmp changes

This commit is contained in:
DESKTOP-4ES9U2E\aldom 2021-12-29 15:24:46 +02:00
parent a9e7ef1798
commit e675ad7c9d
26 changed files with 383 additions and 152 deletions

View File

@ -131,7 +131,7 @@ public class WordBuilder {
this.options.put(ParagraphStyle.COMMENT, (mainDocumentPart, item) -> {
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText(item);
run.setText(" " + item);
run.setItalic(true);
return paragraph;
});
@ -178,7 +178,7 @@ public class WordBuilder {
number.setVal(BigInteger.valueOf(indent));
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
}
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, 1, createListing, visibilityRuleService, page, tempSectionString);
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER4, 1, createListing, visibilityRuleService, page, tempSectionString);
hasValue = createCompositeFields(section.getCompositeFields(), mainDocumentPart, 2, createListing, visibilityRuleService, page, tempSectionString);
if (!hasValue && paragraphPos > -1) {
@ -230,7 +230,11 @@ public class WordBuilder {
try {
if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
this.indent = indent;
XWPFParagraph paragraph = addParagraphContent(this.formatter(field), mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
String format = this.formatter(field);
if(format != null && format.charAt(0) == '['){
format = format.substring(1, format.length() - 1).replaceAll(",", ", ");
}
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
if (paragraph != null) {
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));

View File

@ -4,10 +4,10 @@ public class JavaToJson {
public static String objectStringToJson(String object) {
String result = object.replaceAll("=", "\":\"")
.replaceAll("\\{", "{\"")
//.replaceAll("\\{", "{\"")
.replaceAll(", ", "\", \"")
.replaceAll("}", "\"}" ).
replaceAll("}\", \"\\{", "}, {");
//.replaceAll("}", "\"}" ).
.replaceAll("}\", \"\\{", "}, {");
return result;
}
}

View File

@ -133,12 +133,12 @@ public class Contact 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

@ -100,12 +100,12 @@ public class ContactId 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

@ -168,12 +168,12 @@ public class Contributor implements Serializable
this.role = role;
}
@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

@ -101,12 +101,12 @@ public class ContributorId 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

@ -162,12 +162,12 @@ public class Cost implements Serializable
this.value = value;
}
@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

@ -109,12 +109,12 @@ public class DatasetId 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

@ -101,12 +101,12 @@ public class DmpId 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

@ -101,12 +101,12 @@ public class FunderId 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

@ -133,12 +133,12 @@ public class Funding implements Serializable
this.grantId = grantId;
}
@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

@ -391,12 +391,12 @@ public class Host implements Serializable
this.url = url;
}
@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

@ -100,12 +100,12 @@ public class License implements Serializable
this.startDate = startDate;
}
@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

@ -101,12 +101,12 @@ public class MetadataStandardId 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

@ -199,12 +199,12 @@ public class Project 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

@ -1,10 +1,19 @@
package eu.eudat.models.rda.mapper;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.logic.utilities.json.JavaToJson;
import eu.eudat.models.rda.Cost;
import eu.eudat.models.rda.PidSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CostRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(DatasetRDAMapper.class);
public static Cost toRDA(Map<String, Object> cost) {
Cost rda = new Cost();
@ -19,4 +28,69 @@ public class CostRDAMapper {
return rda;
}
public static List<Cost> toRDAList(List<JsonNode> nodes) throws JsonProcessingException {
Map<String, Cost> rdaMap = new HashMap<>();
for(JsonNode node: nodes){
String rdaProperty = node.get("rdaProperty").asText();
String rdaValue = node.get("value").asText();
if(rdaValue == null || (rdaValue.isEmpty() && !node.get("value").isArray())){
continue;
}
String key = node.get("numbering").asText();
if(!key.contains("mult")){
key = "0";
}
else{
key = "" + key.charAt(4);
}
Cost rda;
if(rdaMap.containsKey(key)){
rda = rdaMap.get(key);
}
else{
rda = new Cost();
rdaMap.put(key, rda);
}
if(rdaProperty.contains("value")){
rda.setValue(Double.valueOf(rdaValue));
}
else if(rdaProperty.contains("currency_code")){
String json = JavaToJson.objectStringToJson(rdaValue);
HashMap<String,String> result =
new ObjectMapper().readValue(json, HashMap.class);
rda.setCurrencyCode(Cost.CurrencyCode.fromValue(result.get("value")));
}
else if(rdaProperty.contains("title")){
Iterator<JsonNode> iter = node.get("value").elements();
StringBuilder title = new StringBuilder();
while(iter.hasNext()){
String next = iter.next().asText();
if(!next.equals("Other")) {
title.append(next).append(", ");
}
}
if(title.length() > 2){
rda.setTitle(title.substring(0, title.length() - 2));
}
else{
String t = rda.getTitle();
if(t == null){ // only other as title
rda.setTitle(rdaValue);
}
else{ // option + other
rda.setTitle(t + ", " + rdaValue);
}
}
}
else if(rdaProperty.contains("description")){
rda.setDescription(rdaValue);
}
}
List<Cost> rdaList = rdaMap.values().stream()
.filter(cost -> cost.getTitle() != null)
.collect(Collectors.toList());
return rdaList;
}
}

View File

@ -29,19 +29,23 @@ public class DatasetIdRDAMapper {
for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperty").asText();
String rdaValue = node.get("value").asText();
if(rdaValue.isEmpty()){
continue;
}
finalRDAMap(data, rdaProperty, rdaValue);
ObjectMapper mapper = new ObjectMapper();
try {
Map<String, Object> values = mapper.readValue(rdaValue, HashMap.class);
if (!values.isEmpty()) {
values.entrySet().forEach(entry -> finalRDAMap(data, entry.getKey(), (String) entry.getValue()));
} else {
finalRDAMap(data, rdaProperty, rdaValue);
}
} catch (IOException e) {
finalRDAMap(data, rdaProperty, rdaValue);
logger.error(e.getMessage(), e);
}
// ObjectMapper mapper = new ObjectMapper();
// try {
// Map<String, Object> values = mapper.readValue(rdaValue, HashMap.class);
// if (!values.isEmpty()) {
// values.entrySet().forEach(entry -> finalRDAMap(data, entry.getKey(), (String) entry.getValue()));
// } else {
// finalRDAMap(data, rdaProperty, rdaValue);
// }
// } catch (IOException e) {
// finalRDAMap(data, rdaProperty, rdaValue);
// logger.error(e.getMessage(), e);
// }
}

View File

@ -9,10 +9,7 @@ import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.utilities.json.JsonSearcher;
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.rda.Contributor;
import eu.eudat.models.rda.Dataset;
import eu.eudat.models.rda.DatasetId;
import eu.eudat.models.rda.Language;
import eu.eudat.models.rda.*;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -43,7 +40,7 @@ public class DatasetRDAMapper {
}
@Transactional
public Dataset toRDA(eu.eudat.data.entities.Dataset dataset, List<Contributor> contributors) {
public Dataset toRDA(eu.eudat.data.entities.Dataset dataset, List<Contributor> contributors, List<Cost> costs) {
Dataset rda = new Dataset();
// rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
if (dataset.getLabel() == null) {
@ -68,13 +65,13 @@ public class DatasetRDAMapper {
rda.setDatasetId(new DatasetId(dataset.getId().toString(), DatasetId.Type.OTHER));
}
List<JsonNode> typeNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.type");
if (!typeNodes.isEmpty()) {
if (!typeNodes.isEmpty() && !typeNodes.get(0).get("value").asText().isEmpty()) {
rda.setType(typeNodes.get(0).get("value").asText());
} else {
rda.setType("DMP Dataset");
}
List<JsonNode> languageNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.language");
if (!languageNodes.isEmpty()) {
if (!languageNodes.isEmpty() && !languageNodes.get(0).get("value").asText().isEmpty()) {
rda.setLanguage(Language.fromValue(languageNodes.get(0).get("value").asText()));
} else {
rda.setLanguage(LanguageRDAMapper.mapLanguageIsoToRDAIso(dataset.getProfile().getLanguage()));
@ -83,21 +80,33 @@ public class DatasetRDAMapper {
if (!metadataNodes.isEmpty()) {
rda.setMetadata(MetadataRDAMapper.toRDAList(metadataNodes));
}
else{
rda.setMetadata(new ArrayList<>());
}
List<JsonNode> qaNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.data_quality_assurance");
if (!qaNodes.isEmpty()) {
List<String> qaList = qaNodes.stream().map(qaNode -> qaNode.get("value").asText()).filter(qaNode -> !qaNode.isEmpty()).collect(Collectors.toList());
rda.setDataQualityAssurance(qaList);
/*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()));
//rda.setDataQualityAssurance(Collections.singletonList(qaNodes.get(0).get("value").asText()));
}
else{
rda.setDataQualityAssurance(new ArrayList<>());
}
List<JsonNode> preservationNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.preservation_statement");
if (!preservationNodes.isEmpty()) {
if (!preservationNodes.isEmpty() && !preservationNodes.get(0).get("value").asText().isEmpty()) {
rda.setPreservationStatement(preservationNodes.get(0).get("value").asText());
}
List<JsonNode> distributionNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.distribution");
if (!distributionNodes.isEmpty()) {
rda.setDistribution(Collections.singletonList(DistributionRDAMapper.toRDA(distributionNodes)));
rda.setDistribution(DistributionRDAMapper.toRDAList(distributionNodes));
}
else{
rda.setDistribution(new ArrayList<>());
}
List<JsonNode> keywordNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.keyword");
if (!keywordNodes.isEmpty()) {
@ -126,6 +135,9 @@ public class DatasetRDAMapper {
if (!securityAndPrivacyNodes.isEmpty()) {
rda.setSecurityAndPrivacy(SecurityAndPrivacyRDAMapper.toRDAList(securityAndPrivacyNodes));
}
else{
rda.setSecurityAndPrivacy(new ArrayList<>());
}
List<JsonNode> sensitiveDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.sensitive_data");
if (!sensitiveDataNodes.isEmpty()) {
rda.setSensitiveData(sensitiveDataNodes.stream().map(sensitiveDataNode -> Dataset.SensitiveData.fromValue(sensitiveDataNode.get("value").asText())).findFirst().get());
@ -136,8 +148,11 @@ public class DatasetRDAMapper {
if (!technicalResourceNodes.isEmpty()) {
rda.setTechnicalResource(TechnicalResourceRDAMapper.toRDAList(technicalResourceNodes));
}
else{
rda.setTechnicalResource(new ArrayList<>());
}
List<JsonNode> issuedNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.issued");
if (!issuedNodes.isEmpty()) {
if (!issuedNodes.isEmpty() && !issuedNodes.get(0).get("value").asText().isEmpty()) {
rda.setIssued(issuedNodes.get(0).get("value").asText());
}
List<JsonNode> contributorNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.contributor");
@ -147,10 +162,14 @@ public class DatasetRDAMapper {
if (value.isArray()) {
return StreamSupport.stream(value.spliterator(), false).map(node -> ContributorRDAMapper.toRDA(node.asText())).collect(Collectors.toList());
} else {
return Collections.singletonList(new Contributor());
return Collections.singletonList(new Contributor()); // return null kalutera
}
}).flatMap(Collection::stream).collect(Collectors.toList()));
}
List<JsonNode> costNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.cost");
if (!costNodes.isEmpty()) {
costs.addAll(CostRDAMapper.toRDAList(costNodes));
}
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 -> {

View File

@ -1,7 +1,10 @@
package eu.eudat.models.rda.mapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.logic.utilities.helpers.MyStringUtils;
import eu.eudat.logic.utilities.json.JavaToJson;
import eu.eudat.logic.utilities.json.JsonSearcher;
import eu.eudat.models.rda.Distribution;
import org.slf4j.Logger;
@ -14,16 +17,34 @@ import java.util.stream.Collectors;
public class DistributionRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(DistributionRDAMapper.class);
public static List<Distribution> toRDAList(List<JsonNode> nodes) {
public static List<Distribution> toRDAList(List<JsonNode> nodes) throws JsonProcessingException {
Map<String, Distribution> rdaMap = new HashMap<>();
for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperty").asText();
String rdaValue = node.get("value").asText();
Distribution rda = getRelative(rdaMap, node.get("numbering").asText());
if (!rdaMap.containsValue(rda)) {
rdaMap.put(node.get("numbering").asText(), rda);
if(rdaValue == null || (rdaValue.isEmpty() && !node.get("value").isArray())){ // node.get("value").isNull()
continue;
}
String key = node.get("numbering").asText();
if(!key.contains("mult")){
key = "0";
}
else{
key = "" + key.charAt(4);
}
Distribution rda;
if(rdaMap.containsKey(key)){
rda = rdaMap.get(key);
}
else {
rda = new Distribution();
rdaMap.put(key, rda);
}
// Distribution rda = getRelative(rdaMap, node.get("numbering").asText());
// if (!rdaMap.containsValue(rda)) {
// rdaMap.put(node.get("numbering").asText(), rda);
// }
for (ExportPropertyName exportPropertyName : ExportPropertyName.values()) {
if (rdaProperty.contains(exportPropertyName.getName())) {
switch (exportPropertyName) {
@ -40,8 +61,10 @@ public class DistributionRDAMapper {
rda.setAdditionalProperty(ImportPropertyName.DOWNLOAD_URL.getName(), node.get("id").asText());
break;
case DESCRIPTION:
if(!rdaProperty.contains("host")) {
rda.setDescription(rdaValue);
rda.setAdditionalProperty(ImportPropertyName.DESCRIPTION.getName(), node.get("id").asText());
}
break;
case DATA_ACCESS:
rda.setDataAccess(Distribution.DataAccess.fromValue(rdaValue));
@ -56,12 +79,29 @@ public class DistributionRDAMapper {
rda.setLicense(Collections.singletonList(LicenseRDAMapper.toRDA(licenseNodes)));
break;
case FORMAT:
rda.setFormat(Collections.singletonList(rdaValue));
//rda.setFormat(Collections.singletonList(rdaValue));
if(node.get("value").isArray()){
Iterator<JsonNode> iter = node.get("value").elements();
List<String> formats = new ArrayList<>();
while(iter.hasNext()) {
String format = JavaToJson.objectStringToJson(iter.next().asText());
Map<String,String> result =
new ObjectMapper().readValue(format, HashMap.class);
format = result.get("label");
formats.add(format);
}
rda.setFormat(formats);
}
else{
rda.setFormat(new ArrayList<>(Arrays.asList(rdaValue.replace(" ", "").split(","))));
}
rda.setAdditionalProperty(ImportPropertyName.FORMAT.getName(), node.get("id").asText());
break;
case TITLE:
if(!rdaProperty.contains("host")) {
rda.setTitle(rdaValue);
rda.setAdditionalProperty(ImportPropertyName.TITLE.getName(), node.get("id").asText());
}
break;
case HOST:
rda.setHost(HostRDAMapper.toRDA(nodes, node.get("numbering").asText()));
@ -71,7 +111,12 @@ public class DistributionRDAMapper {
}
}
return new ArrayList<>(rdaMap.values());
List<Distribution> rdaList = rdaMap.values().stream()
.filter(distro -> distro.getTitle() != null)
.collect(Collectors.toList());
return rdaList;
//return new ArrayList<>(rdaMap.values());
}
public static Map<String, String> toProperties(List<Distribution> rdas) {

View File

@ -95,7 +95,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().filter(dataset -> dataset.getStatus() != eu.eudat.elastic.entities.Dmp.DMPStatus.DELETED.getValue()).map(dataset -> datasetRDAMapper.toRDA(dataset, rda.getContributor())).collect(Collectors.toList()));
rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getStatus() != eu.eudat.elastic.entities.Dmp.DMPStatus.DELETED.getValue()).map(dataset -> datasetRDAMapper.toRDA(dataset, rda.getContributor(), rda.getCost())).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;

View File

@ -8,10 +8,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
public class HostRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(HostRDAMapper.class);
@ -19,11 +17,14 @@ public class HostRDAMapper {
public static Host toRDA(List<JsonNode> nodes, String numbering) {
Host rda = new Host();
for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperties").asText();
String rdaProperty = node.get("rdaProperty").asText();
if (rdaProperty.contains("host")) {
int firstDiff = MyStringUtils.getFirstDifference(numbering, node.get("numbering").asText());
if (firstDiff == -1 || firstDiff > 2) {
if (firstDiff == -1 || firstDiff >= 2) {
String rdaValue = node.get("value").asText();
if(rdaValue == null || (rdaValue.isEmpty() && !node.get("value").isArray())){
continue;
}
for (ExportPropertyName propertyName: ExportPropertyName.values()) {
if (rdaProperty.contains(propertyName.getName())) {
switch (propertyName) {
@ -51,8 +52,27 @@ public class HostRDAMapper {
rda.setAdditionalProperty(ImportPropertyName.GEO_LOCATION.getName(), node.get("id").asText());
break;
case PID_SYSTEM:
rda.setPidSystem(Collections.singletonList(PidSystem.fromValue(rdaValue)));
try{
Iterator<JsonNode> iter = node.get("value").elements();
List<String> pList = new ArrayList<>();
while(iter.hasNext()) {
pList.add(iter.next().asText());
}
List<PidSystem> pidList;
if(pList.size() == 0){
pidList = Arrays.stream(rdaValue.replaceAll("[\\[\"\\]]","").split(","))
.map(PidSystem::fromValue).collect(Collectors.toList());
}
else{
pidList = pList.stream().map(PidSystem::fromValue).collect(Collectors.toList());
}
rda.setPidSystem(pidList);
rda.setAdditionalProperty(ImportPropertyName.PID_SYSTEM.getName(), node.get("id").asText());
}
catch (IllegalArgumentException e){
rda.setPidSystem(new ArrayList<>());
break;
}
break;
case STORAGE_TYPE:
rda.setStorageType(rdaValue);
@ -67,8 +87,12 @@ public class HostRDAMapper {
rda.setAdditionalProperty(ImportPropertyName.TITLE.getName(), node.get("id").asText());
break;
case URL:
try {
rda.setUrl(URI.create(rdaValue));
rda.setAdditionalProperty(ImportPropertyName.URL.getName(), node.get("id").asText());
} catch (IllegalArgumentException e) {
logger.warn(e.getLocalizedMessage() + ". Skipping url parsing");
}
break;
}
}
@ -77,12 +101,8 @@ public class HostRDAMapper {
}
}
if (rda.getTitle() == null) {
throw new IllegalArgumentException("Host Title is missing");
}
if (rda.getUrl() == null) {
throw new IllegalArgumentException("Host Url is missing");
if(rda.getTitle() == null || rda.getUrl() == null){
return null;
}
return rda;

View File

@ -14,18 +14,20 @@ public class KeywordRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class);
public static List<String> toRDA(String value) {
ObjectMapper mapper = new ObjectMapper();
try {
value = JavaToJson.objectStringToJson(value);
// ObjectMapper mapper = new ObjectMapper();
// try {
// value = JavaToJson.objectStringToJson(value);
// if (!value.isEmpty()) {
// List<Tag> tags = Arrays.asList(mapper.readValue(value, Tag[].class));
// List<String> keywordNames = tags.stream().map(Tag::getName).collect(Collectors.toList());
// return keywordNames;
// }
// } catch (IOException e) {
// logger.error(e.getMessage(), e);
// }
if(!value.isEmpty()) {
List<Tag> tags = Arrays.asList(mapper.readValue(value, Tag[].class));
List<String> keywordNames = tags.stream().map(Tag::getName).collect(Collectors.toList());
return keywordNames;
return new ArrayList<>(Arrays.asList(value.replace(" ", "").split(",")));
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return new ArrayList<>();
}
}

View File

@ -16,12 +16,16 @@ public class LicenseRDAMapper {
for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperty").asText();
String value = node.get("value").asText();
if(value.equals(null)){
continue;
}
for (LicenceProperties licenceProperties: LicenceProperties.values()) {
if (rdaProperty.contains(licenceProperties.getName())) {
switch (licenceProperties) {
case LICENSE_REF:
if(value.contains(":")){ // valid uri
rda.setLicenseRef(URI.create(value));
}
break;
case START_DATE:
rda.setStartDate(value);
@ -39,12 +43,16 @@ public class LicenseRDAMapper {
}*/
}
if (rda.getLicenseRef() == null) {
throw new IllegalArgumentException("Licence Reference is missing");
}
// if (rda.getLicenseRef() == null) {
// throw new IllegalArgumentException("Licence Reference is missing");
// }
//
// if (rda.getStartDate() == null) {
// throw new IllegalArgumentException("License Start Date is missing");
// }
if (rda.getStartDate() == null) {
throw new IllegalArgumentException("License Start Date is missing");
if(rda.getLicenseRef() == null || rda.getStartDate() == null){
return null;
}
return rda;

View File

@ -2,11 +2,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.Distribution;
import eu.eudat.models.rda.SecurityAndPrivacy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.stream.Collectors;
public class SecurityAndPrivacyRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(SecurityAndPrivacyRDAMapper.class);
@ -17,6 +19,9 @@ public class SecurityAndPrivacyRDAMapper {
for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperty").asText();
String rdaValue = node.get("value").asText();
if(rdaValue == null || rdaValue.isEmpty()){
continue;
}
SecurityAndPrivacy rda = getRelative(rdaMap, node.get("numbering").asText());
if (!rdaMap.containsValue(rda)) {
@ -38,7 +43,11 @@ public class SecurityAndPrivacyRDAMapper {
}
}
return new ArrayList<>(rdaMap.values());
List<SecurityAndPrivacy> rdaList = rdaMap.values().stream()
.filter(sap -> sap.getTitle() != null)
.collect(Collectors.toList());
return rdaList;
//return new ArrayList<>(rdaMap.values());
}
public static Map<String, String> toProperties(List<SecurityAndPrivacy> rdas) {

View File

@ -2,11 +2,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 eu.eudat.models.rda.TechnicalResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.stream.Collectors;
public class TechnicalResourceRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(TechnicalResourceRDAMapper.class);
@ -17,6 +19,9 @@ public class TechnicalResourceRDAMapper {
for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperty").asText();
String rdaValue = node.get("value").asText();
if(rdaValue == null || rdaValue.isEmpty()){
continue;
}
TechnicalResource rda = getRelative(rdaMap, node.get("numbering").asText());
if (!rdaMap.containsValue(rda)) {
@ -38,7 +43,11 @@ public class TechnicalResourceRDAMapper {
}
}
return new ArrayList<>(rdaMap.values());
List<TechnicalResource> rdaList = rdaMap.values().stream()
.filter(tr -> tr.getName() != null)
.collect(Collectors.toList());
return rdaList;
//return new ArrayList<>(rdaMap.values());
}
public static Map<String, String> toProperties(List<TechnicalResource> rdas) {

View File

@ -34,12 +34,49 @@ dataset.security_and_privacy.description
dataset.security_and_privacy.title
dataset.sensitive_data
dataset.technical_resource.description
dataset.technical_resource.technical_resource
dataset.technical_resource.technical_resource.description
dataset.technical_resource.technical_resource.name
dataset.technical_resource.name
dataset.title
dataset.type
dataset.issued
dataset.dataset_id
dataset.dataset_id.identifier
dataset.dataset_id.type
dataset.description
dmp.contact
dmp.contact.contact_id.identifier
dmp.contact.contact_id.type
dmp.contact.mbox
dmp.contact.name
dmp.contributor
dmp.contributor.contributor_id.identifier
dmp.contributor.contributor_id.type
dmp.contributor.mbox
dmp.contributor.name
dmp.contributor.role
dmp.cost
dmp.cost.currency_code
dmp.cost.description
dmp.cost.title
dmp.cost.value
dmp.created
dmp.description
dmp.dmp_id
dmp.dmp_id.identifier
dmp.dmp_id.type
dmp.ethical_issues_description
dmp.ethical_issues_exist
dmp.ethical_issues_report
dmp.language
dmp.modified
dmp.project
dmp.project.description
dmp.project.end
dmp.project.funding
dmp.project.funding.funder_id.identifier
dmp.project.funding.funder_id.type
dmp.project.funding.funding_status
dmp.project.funding.grant_id.identifier
dmp.project.funding.grant_id.type
dmp.project.start
dmp.project.title
dmp.title