Improved object coupling for various objects on the dataset form

This commit is contained in:
George Kalampokis 2020-03-23 18:09:31 +02:00
parent 9e72be32d4
commit a6bd1f71ca
12 changed files with 424 additions and 87 deletions

View File

@ -0,0 +1,21 @@
package eu.eudat.logic.utilities.helpers;
public class MyStringUtils {
public static int getFirstDifference(String s1, String s2) {
char[] s1ar = s1.toCharArray();
char[] s2ar = s2.toCharArray();
for(int i = 0; i < s1ar.length; i++) {
if (s2ar.length > i) {
if (s1ar[i] != s2ar[i]) {
return i;
}
} else {
return i;
}
}
return -1;
}
}

View File

@ -1,6 +1,7 @@
package eu.eudat.logic.utilities.json;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.ArrayList;
import java.util.Iterator;

View File

@ -149,7 +149,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin
this.rdaProperty = rdaProperty;
}
Field cloneForMultiplicity(String key, Map<String, Object> properties) {
Field cloneForMultiplicity(String key, Map<String, Object> properties, int index) {
Field newField = new Field();
newField.id = key;
newField.ordinal = this.ordinal;
@ -161,6 +161,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin
newField.data = this.data;
newField.validations = this.validations;
newField.rdaProperty = this.rdaProperty;
newField.numbering = "mult" + index + "_" + this.numbering;
return newField;
}
@ -204,8 +205,9 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin
}
this.multiplicityItems = new LinkedList<>();
List<String> compositeKeys = properties.keySet().stream().filter(keys -> keys.startsWith("multiple_" + this.getId())).collect(Collectors.toList());
int index = 1;
for (String key : compositeKeys) {
this.multiplicityItems.add(this.cloneForMultiplicity(key, properties));
this.multiplicityItems.add(this.cloneForMultiplicity(key, properties, index));
}
}

View File

@ -163,16 +163,18 @@ public class FieldSet implements Comparable, PropertiesModelBuilder, ViewStyleDe
});
List<String> compositeKeysFather = properties.keySet().stream().filter(keys -> keys.startsWith("multiple_" + this.getId())).collect(Collectors.toList());
List<String> Ids=new ArrayList<>();
int index = 1;
for (String composite : compositeKeysFather) {
String[] split = composite.split("_");
if (!Ids.contains(split[2])) {
Ids.add(split[2]);
this.multiplicityItems.add(this.CloneForMultiplicity2(properties.keySet().stream().filter(keys -> keys.startsWith("multiple_" + this.getId() + "_" + split[2])).collect(Collectors.toList()), properties,split));
this.multiplicityItems.add(this.CloneForMultiplicity2(properties.keySet().stream().filter(keys -> keys.startsWith("multiple_" + this.getId() + "_" + split[2])).collect(Collectors.toList()), properties,split, index));
index++;
}
}
}
private FieldSet CloneForMultiplicity2(List<String> key, Map<String, Object> properties,String[] ids){
private FieldSet CloneForMultiplicity2(List<String> key, Map<String, Object> properties,String[] ids, int index){
FieldSet newFieldSet = new FieldSet();
newFieldSet.id = ids[0]+"_"+ids[1]+"_"+ids[2];
newFieldSet.description = this.description;
@ -181,8 +183,9 @@ public class FieldSet implements Comparable, PropertiesModelBuilder, ViewStyleDe
newFieldSet.title = this.title;
newFieldSet.ordinal = this.ordinal;
newFieldSet.fields = new LinkedList();
for (Field field: this.fields) {
newFieldSet.fields.add(field.cloneForMultiplicity(newFieldSet.id + "_" + field.getId(), properties));
newFieldSet.fields.add(field.cloneForMultiplicity(newFieldSet.id + "_" + field.getId(), properties, index));
}
return newFieldSet;
}

View File

@ -1,21 +1,17 @@
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.managers.DatasetManager;
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.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
@ -41,52 +37,51 @@ public class DatasetRDAMapper {
DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(dataset);
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset));
ObjectMapper mapper = new ObjectMapper();
JsonNode properties = mapper.readTree(dataset.getProperties());
String datasetDescriptionJson = mapper.writeValueAsString(datasetWizardModel.getDatasetProfileDefinition());
JsonNode datasetDescriptionObj = mapper.readTree(datasetDescriptionJson);
List<JsonNode> typeNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.type");
if (!typeNodes.isEmpty()) {
rda.setType(properties.get(typeNodes.get(0).get("id").asText()).asText());
rda.setType(typeNodes.get(0).get("value").asText());
}
List<JsonNode> languageNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.language");
if (!languageNodes.isEmpty()) {
rda.setLanguage(Dataset.Language.fromValue(properties.get(languageNodes.get(0).get("id").asText()).asText()));
rda.setLanguage(Dataset.Language.fromValue(languageNodes.get(0).get("value").asText()));
}
List<JsonNode> metadataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.metadata");
if (!metadataNodes.isEmpty()) {
rda.setMetadata(metadataNodes.stream().map(node -> MetadataRDAMapper.toRDA(node, properties)).collect(Collectors.toList()));
rda.setMetadata(MetadataRDAMapper.toRDAList(metadataNodes));
}
List<JsonNode> qaNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.data_quality_assurance");
if (!qaNodes.isEmpty()) {
rda.setDataQualityAssurance(qaNodes.stream().map(qaNode -> properties.get(qaNode.get("id").asText()).asText()).collect(Collectors.toList()));
rda.setDataQualityAssurance(qaNodes.stream().map(qaNode -> qaNode.get("value").asText()).collect(Collectors.toList()));
}
List<JsonNode> preservationNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.preservation_statement");
if (!preservationNodes.isEmpty()) {
rda.setDataQualityAssurance(preservationNodes.stream().map(preservationNode -> properties.get(preservationNode.get("id").asText()).asText()).collect(Collectors.toList()));
rda.setDataQualityAssurance(preservationNodes.stream().map(preservationNode -> preservationNode.get("value").asText()).collect(Collectors.toList()));
}
List<JsonNode> distributionNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.distribution");
if (!distributionNodes.isEmpty()) {
rda.setDistribution(distributionNodes.stream().map(distributionNode -> DistributionRDAMapper.toRDA(distributionNode, properties)).collect(Collectors.toList()));
rda.setDistribution(DistributionRDAMapper.toRDAList(distributionNodes));
}
List<JsonNode> keywordNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.keyword");
if (!keywordNodes.isEmpty()) {
rda.setKeyword(keywordNodes.stream().map(keywordNode -> properties.get(keywordNode.get("id").asText()).asText()).collect(Collectors.toList()));
rda.setKeyword(keywordNodes.stream().map(keywordNode -> keywordNode.get("value").asText()).collect(Collectors.toList()));
}
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data");
if (!personalDataNodes.isEmpty()) {
rda.setPersonalData(personalDataNodes.stream().map(personalDataNode -> Dataset.PersonalData.fromValue(properties.get(personalDataNode.get("id").asText()).asText())).findFirst().get());
rda.setPersonalData(personalDataNodes.stream().map(personalDataNode -> Dataset.PersonalData.fromValue(personalDataNode.get("value").asText())).findFirst().get());
}
List<JsonNode> securityAndPrivacyNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.security_and_privacy");
if (!securityAndPrivacyNodes.isEmpty()) {
rda.setSecurityAndPrivacy(securityAndPrivacyNodes.stream().map(securityAndPrivacyNode -> SecurityAndPrivacyRDAMapper.toRDA(securityAndPrivacyNode, properties)).collect(Collectors.toList()));
rda.setSecurityAndPrivacy(SecurityAndPrivacyRDAMapper.toRDAList(securityAndPrivacyNodes));
}
List<JsonNode> sensitiveDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.sensitive_data");
if (!sensitiveDataNodes.isEmpty()) {
rda.setSensitiveData(securityAndPrivacyNodes.stream().map(sensitiveDataNode -> Dataset.SensitiveData.fromValue(properties.get(sensitiveDataNode.get("id").asText()).asText())).findFirst().get());
rda.setSensitiveData(securityAndPrivacyNodes.stream().map(sensitiveDataNode -> Dataset.SensitiveData.fromValue(sensitiveDataNode.get("value").asText())).findFirst().get());
}
List<JsonNode> technicalResourceNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.technical_resource");
if (!technicalResourceNodes.isEmpty()) {
rda.setTechnicalResource(technicalResourceNodes.stream().map(technicalResourceNode -> TechnicalResourceRDAMapper.toRDA(technicalResourceNode, properties)).collect(Collectors.toList()));
rda.setTechnicalResource(TechnicalResourceRDAMapper.toRDAList(technicalResourceNodes));
}

View File

@ -1,39 +1,120 @@
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 java.net.URI;
import java.util.Collections;
import java.util.*;
public class DistributionRDAMapper {
public static Distribution toRDA(JsonNode structure, JsonNode properties) {
public static List<Distribution> toRDAList(List<JsonNode> nodes) {
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);
}
for (PropertyName propertyName : PropertyName.values()) {
if (rdaProperty.contains(propertyName.getName())) {
switch (propertyName) {
case ACCESS_URL:
rda.setAccessUrl(rdaValue);
break;
case AVAILABLE_UTIL:
rda.setAvailableUntil(rdaValue);
break;
case DOWNLOAD_URL:
rda.setDownloadUrl(URI.create(rdaValue));
break;
case DESCRIPTION:
rda.setDescription(rdaValue);
break;
case DATA_ACCESS:
rda.setDataAccess(Distribution.DataAccess.fromValue(rdaValue));
break;
case BYTE_SIZE:
rda.setByteSize(Integer.parseInt(rdaValue));
break;
case LICENSE:
rda.setLicense(Collections.singletonList(LicenseRDAMapper.toRDA(node)));
break;
case FORMAT:
rda.setFormat(Collections.singletonList(rdaValue));
break;
case TITLE:
rda.setTitle(rdaValue);
break;
case HOST:
rda.setHost(HostRDAMapper.toRDA(nodes, node.get("numbering").asText()));
break;
}
}
}
}
return new ArrayList<>(rdaMap.values());
}
public static Distribution toRDA(JsonNode node) {
Distribution rda = new Distribution();
String rdaProperty = structure.get("rdaProperty").asText();
String rdaProperty = node.get("rdaProperty").asText();
String rdaValue = node.get("value").asText();
if (rdaProperty.contains("access_url")) {
rda.setAccessUrl(properties.get(structure.get("id").asText()).asText());
rda.setAccessUrl(rdaValue);
} else if (rdaProperty.contains("available_util")) {
rda.setAvailableUntil(properties.get(structure.get("id").asText()).asText());
rda.setAvailableUntil(rdaValue);
} else if (rdaProperty.contains("byte_size")) {
rda.setByteSize(properties.get(structure.get("id").asText()).asInt());
rda.setByteSize(Integer.parseInt(rdaValue));
} else if (rdaProperty.contains("data_access")) {
rda.setDataAccess(Distribution.DataAccess.fromValue(properties.get(structure.get("id").asText()).asText()));
rda.setDataAccess(Distribution.DataAccess.fromValue(rdaValue));
} else if (rdaProperty.contains("description")) {
rda.setDescription(properties.get(structure.get("id").asText()).asText());
rda.setDescription(rdaValue);
} else if (rdaProperty.contains("download_url")) {
rda.setDownloadUrl(URI.create(properties.get(structure.get("id").asText()).asText()));
rda.setDownloadUrl(URI.create(rdaValue));
} else if (rdaProperty.contains("format")) {
rda.setFormat(Collections.singletonList(properties.get(structure.get("id").asText()).asText()));
rda.setFormat(Collections.singletonList(rdaValue));
} else if (rdaProperty.contains("host")) {
rda.setHost(HostRDAMapper.toRDA(structure, properties));
// rda.setHost(HostRDAMapper.toRDA(node));
} else if (rdaProperty.contains("license")) {
rda.setLicense(Collections.singletonList(LicenseRDAMapper.toRDA(structure, properties)));
rda.setLicense(Collections.singletonList(LicenseRDAMapper.toRDA(node)));
} else if (rdaProperty.contains("title")) {
rda.setTitle(properties.get(structure.get("id").asText()).asText());
rda.setTitle(rdaValue);
}
return rda;
}
private static Distribution getRelative( Map<String, Distribution> rdaMap, String numbering) {
return rdaMap.entrySet().stream().filter(entry -> MyStringUtils.getFirstDifference(entry.getKey(), numbering) > 0)
.max(Comparator.comparingInt(entry -> MyStringUtils.getFirstDifference(entry.getKey(), numbering))).map(Map.Entry::getValue).orElse(new Distribution());
}
private enum PropertyName {
ACCESS_URL("access_url"),
AVAILABLE_UTIL("available_util"),
BYTE_SIZE("byte_size"),
DATA_ACCESS("data_access"),
DESCRIPTION("description"),
DOWNLOAD_URL("download_url"),
FORMAT("format"),
HOST("host"),
LICENSE("license"),
TITLE("title");
private final String name;
PropertyName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
}

View File

@ -1,41 +1,91 @@
package eu.eudat.models.rda.mapper;
import com.fasterxml.jackson.databind.JsonNode;
import eu.eudat.logic.utilities.helpers.MyStringUtils;
import eu.eudat.models.rda.Host;
import eu.eudat.models.rda.PidSystem;
import java.net.URI;
import java.util.Collections;
import java.util.List;
public class HostRDAMapper {
public static Host toRDA(JsonNode structure, JsonNode properties) {
public static Host toRDA(List<JsonNode> nodes, String numbering) {
Host rda = new Host();
String rdaProperty = structure.get("rdaProperties").asText();
if (rdaProperty.contains("availability")) {
rda.setAvailability(properties.get(structure.get("id").asText()).asText());
} else if (rdaProperty.contains("backup_frequency")) {
rda.setBackupFrequency(properties.get(structure.get("id").asText()).asText());
} else if (rdaProperty.contains("backup_type")) {
rda.setBackupType(properties.get(structure.get("id").asText()).asText());
} else if (rdaProperty.contains("certified_with")) {
rda.setCertifiedWith(Host.CertifiedWith.fromValue(properties.get(structure.get("id").asText()).asText()));
} else if (rdaProperty.contains("description")) {
rda.setDescription(properties.get(structure.get("id").asText()).asText());
} else if (rdaProperty.contains("geo_location")) {
rda.setGeoLocation(Host.GeoLocation.fromValue(properties.get(structure.get("id").asText()).asText()));
} else if (rdaProperty.contains("pid_system")) {
rda.setPidSystem(Collections.singletonList(PidSystem.fromValue(properties.get(structure.get("id").asText()).asText())));
} else if (rdaProperty.contains("storage_type")) {
rda.setStorageType(properties.get(structure.get("id").asText()).asText());
} else if (rdaProperty.contains("support_versioning")) {
rda.setSupportVersioning(Host.SupportVersioning.fromValue(properties.get(structure.get("id").asText()).asText()));
} else if (rdaProperty.contains("title")) {
rda.setTitle(properties.get(structure.get("id").asText()).asText());
} else if (rdaProperty.contains("url")) {
rda.setUrl(URI.create(properties.get(structure.get("id").asText()).asText()));
for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperties").asText();
if (rdaProperty.contains("host")) {
int firstDiff = MyStringUtils.getFirstDifference(numbering, node.get("numbering").asText());
if (firstDiff == -1 || firstDiff > 2) {
String rdaValue = node.get("value").asText();
for (PropertyName propertyName: PropertyName.values()) {
if (rdaProperty.contains(propertyName.getName())) {
switch (propertyName) {
case AVAILABILITY:
rda.setAvailability(rdaValue);
break;
case BACKUP_FREQUENCY:
rda.setBackupFrequency(rdaValue);
break;
case BACKUP_TYPE:
rda.setBackupType(rdaValue);
break;
case CERTIFIED_WITH:
rda.setCertifiedWith(Host.CertifiedWith.fromValue(rdaValue));
break;
case DESCRIPTION:
rda.setDescription(rdaValue);
break;
case GEO_LOCATION:
rda.setGeoLocation(Host.GeoLocation.fromValue(rdaValue));
break;
case PID_SYSTEM:
rda.setPidSystem(Collections.singletonList(PidSystem.fromValue(rdaValue)));
break;
case STORAGE_TYPE:
rda.setStorageType(rdaValue);
break;
case SUPPORT_VERSIONING:
rda.setSupportVersioning(Host.SupportVersioning.fromValue(rdaValue));
break;
case TITLE:
rda.setTitle(rdaValue);
break;
case URL:
rda.setUrl(URI.create(rdaValue));
break;
}
}
}
}
}
}
return rda;
}
private enum PropertyName {
AVAILABILITY("availability"),
BACKUP_FREQUENCY("backup_frequency"),
BACKUP_TYPE("backup_type"),
CERTIFIED_WITH("certified_with"),
DESCRIPTION("description"),
GEO_LOCATION("geo_location"),
PID_SYSTEM("pid_system"),
STORAGE_TYPE("storage_type"),
SUPPORT_VERSIONING("support_versioning"),
TITLE("title"),
URL("url");
private final String name;
PropertyName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
}

View File

@ -7,10 +7,10 @@ import java.net.URI;
public class LicenseRDAMapper {
public static License toRDA(JsonNode structure, JsonNode properties) {
public static License toRDA(JsonNode node) {
License rda = new License();
String rdaProperty = structure.get("rdaProperty").asText();
String value = properties.get(structure.get("id").asText()).asText();
String rdaProperty = node.get("rdaProperty").asText();
String value = node.get("value").asText();
if (rdaProperty.contains("license_ref")) {
rda.setLicenseRef(URI.create(value));

View File

@ -2,43 +2,124 @@ package eu.eudat.models.rda.mapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.TextNode;
import eu.eudat.logic.utilities.helpers.MyStringUtils;
import eu.eudat.models.rda.Metadatum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Iterator;
import java.util.*;
public class MetadataRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(MetadataRDAMapper.class);
public static Metadatum toRDA(JsonNode structure, JsonNode properties) {
Metadatum rda = new Metadatum();
JsonNode dataNode = null;
String rdaProperty = structure.get("rdaProperty").asText();
if (rdaProperty.contains("metadata_standard_id")) {
try {
String jsonText = properties.get(structure.get("id").asText()).asText();
if (jsonText != null && !jsonText.isEmpty()) {
dataNode = new ObjectMapper().readTree(jsonText);
for (Iterator<JsonNode> it = dataNode.elements(); it.hasNext(); ) {
JsonNode data = it.next();
if (data.get("uri") != null) {
rda.setMetadataStandardId(MetadataStandardIdRDAMapper.toRDA(data.get("uri").asText()));
}
public static List<Metadatum> toRDAList(List<JsonNode> nodes) {
Map<String, String> rdaMap = new HashMap<>();
List<Metadatum> rdas = new ArrayList<>();
for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperty").asText();
JsonNode rdaValue = node.get("value");
for (PropertyName propertyName: PropertyName.values()) {
if (rdaProperty.contains(propertyName.getName())) {
switch (propertyName) {
case METADATA_STANDARD_ID:
if (rdaValue instanceof ArrayNode) {
try {
ObjectMapper mapper = new ObjectMapper();
for (Iterator<JsonNode> it = rdaValue.elements(); it.hasNext(); ) {
JsonNode data = null;
data = mapper.readTree(it.next().asText());
if (data.get("uri") != null) {
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());
rdaMap.put(data.get("uri").asText(), node.get("numbering").asText());
}
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
} 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()));
rdaMap.put(rdaValue.asText(), node.get("numbering").asText());
}
break;
case DESCRIPTION:
if (!rdaValue.asText().isEmpty()) {
Metadatum rda = getRelative(rdas, rdaMap, node.get("numbering").asText());
if (rda != null) {
rda.setDescription(rdaValue.asText());
} else {
rdas.stream().filter(rda1 -> rda1.getDescription() == null || rda1.getDescription().isEmpty()).forEach(rda1 -> rda1.setDescription(rdaValue.asText()));
}
}
break;
case LANGUAGE:
String language = rdaValue.asText();
Metadatum.Language lang = Metadatum.Language.fromValue(language);
Metadatum rda = getRelative(rdas, rdaMap, node.get("numbering").asText());
if (rda != null) {
rda.setLanguage(lang);
} else {
rdas.forEach(rda1 -> rda1.setLanguage(lang));
}
break;
}
}
}
}
return rdas;
}
public static Metadatum toRDA(JsonNode node) {
Metadatum rda = new Metadatum();
String rdaProperty = node.get("rdaProperty").asText();
JsonNode rdaValue = node.get("value");
if (rdaProperty.contains("metadata_standard_id")) {
if (rdaValue instanceof ArrayNode) {
for (Iterator<JsonNode> it = rdaValue.elements(); it.hasNext(); ) {
JsonNode data = it.next();
if (data.get("uri") != null) {
rda.setMetadataStandardId(MetadataStandardIdRDAMapper.toRDA(data.get("uri").asText()));
}
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
} else if (rdaProperty.contains("description")) {
rda.setDescription(properties.get(structure.get("id").asText()).asText());
rda.setDescription(rdaValue.asText());
} else if (rdaProperty.contains("language")) {
String language = properties.get(structure.get("id").asText()).asText();
String language = rdaValue.asText();
Metadatum.Language lang = Metadatum.Language.fromValue(language);
rda.setLanguage(lang);
}
return rda;
}
private static Metadatum getRelative(List<Metadatum> rdas, Map<String, String> rdaMap, String numbering) {
String target = rdaMap.entrySet().stream().filter(entry -> MyStringUtils.getFirstDifference(entry.getValue(), numbering) > 0)
.max(Comparator.comparingInt(entry -> MyStringUtils.getFirstDifference(entry.getValue(), numbering))).map(Map.Entry::getKey).orElse("");
return rdas.stream().filter(rda -> rda.getMetadataStandardId().getIdentifier().equals(target)).distinct().findFirst().orElse(null);
}
private enum PropertyName {
METADATA_STANDARD_ID("metadata_standard_id"),
DESCRIPTION("description"),
LANGUAGE("language");
private final String name;
PropertyName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
}

View File

@ -1,14 +1,45 @@
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 java.util.*;
public class SecurityAndPrivacyRDAMapper {
public static SecurityAndPrivacy toRDA(JsonNode structure, JsonNode properties) {
public static List<SecurityAndPrivacy> toRDAList(List<JsonNode> nodes) {
Map<String, SecurityAndPrivacy> rdaMap = new HashMap<>();
for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperty").asText();
String rdaValue = node.get("value").asText();
SecurityAndPrivacy rda = getRelative(rdaMap, node.get("numbering").asText());
if (!rdaMap.containsValue(rda)) {
rdaMap.put(node.get("numbering").asText(), rda);
}
for (PropertyName propertyName: PropertyName.values()) {
if (rdaProperty.contains(propertyName.getName())) {
switch (propertyName) {
case TITLE:
rda.setTitle(rdaValue);
break;
case DESCRIPTION:
rda.setDescription(rdaValue);
break;
}
}
}
}
return new ArrayList<>(rdaMap.values());
}
public static SecurityAndPrivacy toRDA(JsonNode node) {
SecurityAndPrivacy rda = new SecurityAndPrivacy();
String rdaProperty = structure.get("rdaProperty").asText();
String value = properties.get(structure.get("id").asText()).asText();
String rdaProperty = node.get("rdaProperty").asText();
String value =node.get("value").asText();
if (rdaProperty.contains("description")) {
rda.setDescription(value);
@ -18,4 +49,24 @@ public class SecurityAndPrivacyRDAMapper {
return rda;
}
private static SecurityAndPrivacy getRelative(Map<String, SecurityAndPrivacy> rdaMap, String numbering) {
return rdaMap.entrySet().stream().filter(entry -> MyStringUtils.getFirstDifference(entry.getKey(), numbering) > 0)
.max(Comparator.comparingInt(entry -> MyStringUtils.getFirstDifference(entry.getKey(), numbering))).map(Map.Entry::getValue).orElse(new SecurityAndPrivacy());
}
private enum PropertyName {
TITLE("title"),
DESCRIPTION("description");
private String name;
PropertyName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
}

View File

@ -1,14 +1,46 @@
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 java.util.*;
public class TechnicalResourceRDAMapper {
public static TechnicalResource toRDA(JsonNode structure, JsonNode properties) {
public static List<TechnicalResource> toRDAList(List<JsonNode> nodes) {
Map<String, TechnicalResource> rdaMap = new HashMap<>();
for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperty").asText();
String rdaValue = node.get("value").asText();
TechnicalResource rda = getRelative(rdaMap, node.get("numbering").asText());
if (!rdaMap.containsValue(rda)) {
rdaMap.put(node.get("numbering").asText(), rda);
}
for (PropertyName propertyName: PropertyName.values()) {
if (rdaProperty.contains(propertyName.getName())) {
switch (propertyName) {
case NAME:
rda.setName(rdaValue);
break;
case DESCRIPTION:
rda.setDescription(rdaValue);
break;
}
}
}
}
return new ArrayList<>(rdaMap.values());
}
public static TechnicalResource toRDA(JsonNode node) {
TechnicalResource rda = new TechnicalResource();
String rdaProperty = structure.get("rdaProperty").asText();
String value = properties.get(structure.get("id").asText()).asText();
String rdaProperty = node.get("rdaProperty").asText();
String value = node.get("value").asText();
if (rdaProperty.contains("description")) {
rda.setDescription(value);
@ -18,4 +50,24 @@ public class TechnicalResourceRDAMapper {
return rda;
}
private static TechnicalResource getRelative(Map<String, TechnicalResource> rdaMap, String numbering) {
return rdaMap.entrySet().stream().filter(entry -> MyStringUtils.getFirstDifference(entry.getKey(), numbering) > 0)
.max(Comparator.comparingInt(entry -> MyStringUtils.getFirstDifference(entry.getKey(), numbering))).map(Map.Entry::getValue).orElse(new TechnicalResource());
}
private enum PropertyName {
NAME("name"),
DESCRIPTION("description");
private String name;
PropertyName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
}