Merge branch 'Development' of code-repo.d4science.org:MaDgiK-CITE/argos into Development

This commit is contained in:
Konstantinos Triantafyllou 2022-01-14 17:50:45 +02:00
commit 99cecbc4fb
18 changed files with 388 additions and 99 deletions

View File

@ -291,6 +291,8 @@ public class DatasetProfileManager {
modelDefinition.setGroupId(oldDatasetProfile.getGroupId()); modelDefinition.setGroupId(oldDatasetProfile.getGroupId());
modelDefinition.setLanguage(oldDatasetProfile.getLanguage()); modelDefinition.setLanguage(oldDatasetProfile.getLanguage());
apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition); apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
eu.eudat.data.entities.DatasetProfile datasetProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
this.storeDatasetProfileUsers(datasetProfile, profile);
return modelDefinition; return modelDefinition;
} else { } else {
throw new DatasetProfileNewVersionException("Version to update not the latest."); throw new DatasetProfileNewVersionException("Version to update not the latest.");

View File

@ -52,7 +52,7 @@ public class PrefillingManager {
PrefillingGet prefillingGet = prefillingConfig.getPrefillingGet(); PrefillingGet prefillingGet = prefillingConfig.getPrefillingGet();
Map<String, Object> prefillingEntity = getSingle(prefillingGet.getUrl(), prefillId); Map<String, Object> prefillingEntity = getSingle(prefillingGet.getUrl(), prefillId);
DatasetProfile datasetProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(profileId); DatasetProfile datasetProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(profileId);
return DatasetWizardModel.fromPrefilledEntity(prefillingEntity, prefillingGet.getMappings(), datasetProfile, datasetManager); return DatasetWizardModel.fromPrefilledEntity(prefillingEntity, prefillingGet, datasetProfile, datasetManager);
} }
private Map<String, Object> getSingle(String url, String id) { private Map<String, Object> getSingle(String url, String id) {

View File

@ -0,0 +1,38 @@
package eu.eudat.logic.proxy.config.entities;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "mapping")
public class DefaultPrefillingMapping implements PrefillingMapping{
private String source;
private String target;
private String maDmpTarget;
public String getSource() {
return source;
}
@XmlAttribute(name = "source")
public void setSource(String source) {
this.source = source;
}
public String getTarget() {
return target;
}
@XmlAttribute(name = "target")
public void setTarget(String target) {
this.target = target;
}
public String getMaDmpTarget() {
return maDmpTarget;
}
@XmlAttribute(name = "maDmpTarget")
public void setMaDmpTarget(String maDmpTarget) {
this.maDmpTarget = maDmpTarget;
}
}

View File

@ -0,0 +1,38 @@
package eu.eudat.logic.proxy.config.entities;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "fixedMapping")
public class PrefillingFixedMapping implements PrefillingMapping{
private String target;
private String maDmpTarget;
private String value;
public String getTarget() {
return target;
}
@XmlAttribute(name = "target")
public void setTarget(String target) {
this.target = target;
}
public String getMaDmpTarget() {
return maDmpTarget;
}
@XmlAttribute(name = "maDmpTarget")
public void setMaDmpTarget(String maDmpTarget) {
this.maDmpTarget = maDmpTarget;
}
public String getValue() {
return value;
}
@XmlAttribute(name = "value")
public void setValue(String value) {
this.value = value;
}
}

View File

@ -1,15 +1,13 @@
package eu.eudat.logic.proxy.config.entities; package eu.eudat.logic.proxy.config.entities;
import eu.eudat.logic.proxy.config.FetchStrategy;
import eu.eudat.logic.proxy.config.UrlConfiguration;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import java.util.List; import java.util.List;
public class PrefillingGet{ public class PrefillingGet{
private String url; private String url;
private List<PrefillingMapping> mappings; private List<DefaultPrefillingMapping> mappings;
private List<PrefillingFixedMapping> fixedMappings;
public String getUrl() { public String getUrl() {
return url; return url;
@ -20,13 +18,23 @@ public class PrefillingGet{
this.url = url; this.url = url;
} }
public List<PrefillingMapping> getMappings() { public List<DefaultPrefillingMapping> getMappings() {
return mappings; return mappings;
} }
@XmlElement(name = "mapping") @XmlElement(name = "mapping")
@XmlElementWrapper @XmlElementWrapper
public void setMappings(List<PrefillingMapping> mappings) { public void setMappings(List<DefaultPrefillingMapping> mappings) {
this.mappings = mappings; this.mappings = mappings;
} }
public List<PrefillingFixedMapping> getFixedMappings() {
return fixedMappings;
}
@XmlElement(name = "fixedMapping")
@XmlElementWrapper
public void setFixedMappings(List<PrefillingFixedMapping> fixedMappings) {
this.fixedMappings = fixedMappings;
}
} }

View File

@ -1,38 +1,13 @@
package eu.eudat.logic.proxy.config.entities; package eu.eudat.logic.proxy.config.entities;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "mapping") public interface PrefillingMapping {
public class PrefillingMapping { String getTarget();
private String source;
private String target;
private String maDmpTarget;
public String getSource() { void setTarget(String target);
return source;
}
@XmlAttribute(name = "source") String getMaDmpTarget();
public void setSource(String source) {
this.source = source;
}
public String getTarget() { void setMaDmpTarget(String maDmpTarget);
return target;
}
@XmlAttribute(name = "target")
public void setTarget(String target) {
this.target = target;
}
public String getMaDmpTarget() {
return maDmpTarget;
}
@XmlAttribute(name = "maDmpTarget")
public void setMaDmpTarget(String maDmpTarget) {
this.maDmpTarget = maDmpTarget;
}
} }

View File

@ -131,7 +131,7 @@ public class WordBuilder {
this.options.put(ParagraphStyle.COMMENT, (mainDocumentPart, item) -> { this.options.put(ParagraphStyle.COMMENT, (mainDocumentPart, item) -> {
XWPFParagraph paragraph = mainDocumentPart.createParagraph(); XWPFParagraph paragraph = mainDocumentPart.createParagraph();
XWPFRun run = paragraph.createRun(); XWPFRun run = paragraph.createRun();
run.setText(item); run.setText(" " + item);
run.setItalic(true); run.setItalic(true);
return paragraph; return paragraph;
}); });
@ -178,7 +178,7 @@ public class WordBuilder {
number.setVal(BigInteger.valueOf(indent)); number.setVal(BigInteger.valueOf(indent));
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph); 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); hasValue = createCompositeFields(section.getCompositeFields(), mainDocumentPart, 2, createListing, visibilityRuleService, page, tempSectionString);
if (!hasValue && paragraphPos > -1) { if (!hasValue && paragraphPos > -1) {
@ -193,17 +193,25 @@ public class WordBuilder {
boolean hasValue = false; boolean hasValue = false;
for (FieldSet compositeField: compositeFields) { for (FieldSet compositeField: compositeFields) {
if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) { if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) {
char c = 'a';
int paragraphPos = -1; int paragraphPos = -1;
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) { if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
XWPFParagraph paragraph = addParagraphContent(page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId); XWPFParagraph paragraph = addParagraphContent(page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent)); number.setVal(BigInteger.valueOf(indent));
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph); paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
if(compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()){
addParagraphContent(c + ".\n", mainDocumentPart, ParagraphStyle.HEADER6, numId);
}
} }
hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService); hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService);
if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) { if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) {
List<FieldSet> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList()); List<FieldSet> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList());
for (FieldSet multiplicityFieldset : list) { for (FieldSet multiplicityFieldset : list) {
if(!createListing){
c++;
addParagraphContent(c + ".\n", mainDocumentPart, ParagraphStyle.HEADER6, numId);
}
hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService); hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService);
} }
} }
@ -224,13 +232,31 @@ public class WordBuilder {
if (createListing) this.addListing(mainDocumentPart, indent, false, false); if (createListing) this.addListing(mainDocumentPart, indent, false, false);
boolean hasValue = false; boolean hasValue = false;
List<Field> tempFields = fields.stream().sorted(Comparator.comparingInt(Field::getOrdinal)).collect(Collectors.toList()); List<Field> tempFields = fields.stream().sorted(Comparator.comparingInt(Field::getOrdinal)).collect(Collectors.toList());
List<Field> formats = tempFields.stream().filter(f -> {
try {
String fTemp = this.formatter(f);
return fTemp != null && !fTemp.isEmpty();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return false;
}).collect(Collectors.toList());
for (Field field: tempFields) { for (Field field: tempFields) {
if (visibilityRuleService.isElementVisible(field.getId())) { if (visibilityRuleService.isElementVisible(field.getId())) {
if (!createListing) { if (!createListing) {
try { try {
if (field.getValue() != null && !field.getValue().toString().isEmpty()) { if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
this.indent = indent; 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){
if(format.charAt(0) == '['){
format = format.substring(1, format.length() - 1).replaceAll(",", ", ");
}
if(formats.size() > 1){
format = "\t• " + format;
}
}
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
if (paragraph != null) { if (paragraph != null) {
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent)); number.setVal(BigInteger.valueOf(indent));

View File

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

View File

@ -1,10 +1,14 @@
package eu.eudat.models.data.datasetwizard; package eu.eudat.models.data.datasetwizard;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.entities.*; import eu.eudat.data.entities.*;
import eu.eudat.elastic.entities.Tag; import eu.eudat.elastic.entities.Tag;
import eu.eudat.logic.managers.DatasetManager; import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.proxy.config.entities.PrefillingFixedMapping;
import eu.eudat.logic.proxy.config.entities.PrefillingGet;
import eu.eudat.logic.proxy.config.entities.DefaultPrefillingMapping;
import eu.eudat.logic.proxy.config.entities.PrefillingMapping; import eu.eudat.logic.proxy.config.entities.PrefillingMapping;
import eu.eudat.logic.utilities.json.JsonSearcher; import eu.eudat.logic.utilities.json.JsonSearcher;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
@ -20,7 +24,6 @@ import net.minidev.json.JSONValue;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -305,7 +308,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
return entity; return entity;
} }
public static DatasetWizardModel fromPrefilledEntity(Map<String, Object> prefilledEntity, List<PrefillingMapping> mappings, public static DatasetWizardModel fromPrefilledEntity(Map<String, Object> prefilledEntity, PrefillingGet prefillingGet,
DatasetProfile profile, DatasetManager datasetManager) throws Exception { DatasetProfile profile, DatasetManager datasetManager) throws Exception {
DatasetWizardModel datasetWizardModel = new DatasetWizardModel(); DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(profile)); datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(profile));
@ -314,7 +317,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
Map<String, Object> properties = new HashMap<>(); Map<String, Object> properties = new HashMap<>();
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
JsonNode parentNode = objectMapper.readTree(objectMapper.writeValueAsString(datasetManager.getPagedProfile(datasetWizardModel, dataset))); JsonNode parentNode = objectMapper.readTree(objectMapper.writeValueAsString(datasetManager.getPagedProfile(datasetWizardModel, dataset)));
for (PrefillingMapping prefillingMapping: mappings) { for (DefaultPrefillingMapping prefillingMapping: prefillingGet.getMappings()) {
List<String> sourceKeys = Arrays.asList(prefillingMapping.getSource().split("\\.")); List<String> sourceKeys = Arrays.asList(prefillingMapping.getSource().split("\\."));
Object sourceValue = null; Object sourceValue = null;
for (String sourceKey: sourceKeys) { for (String sourceKey: sourceKeys) {
@ -324,26 +327,35 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
sourceValue = ((Map)sourceValue).get(sourceKey); sourceValue = ((Map)sourceValue).get(sourceKey);
} }
} }
setValue(prefillingMapping, objectMapper.writeValueAsString(sourceValue), datasetWizardModel, parentNode, properties);
}
for (PrefillingFixedMapping fixedMapping: prefillingGet.getFixedMappings()) {
setValue(fixedMapping, fixedMapping.getValue(), datasetWizardModel, parentNode, properties);
}
dataset.setProperties(objectMapper.writeValueAsString(properties));
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset));
return datasetWizardModel;
}
private static void setValue(PrefillingMapping prefillingMapping, String value, DatasetWizardModel datasetWizardModel, JsonNode parentNode, Map<String, Object> properties) throws InvocationTargetException, IllegalAccessException, JsonProcessingException {
if (prefillingMapping.getTarget() != null) { if (prefillingMapping.getTarget() != null) {
try { try {
String methodName = "set" + prefillingMapping.getTarget().substring(0, 1).toUpperCase(Locale.ROOT) + prefillingMapping.getTarget().substring(1); String methodName = "set" + prefillingMapping.getTarget().substring(0, 1).toUpperCase(Locale.ROOT) + prefillingMapping.getTarget().substring(1);
Method setterMethod = DatasetWizardModel.class.getMethod(methodName, String.class); Method setterMethod = Arrays.stream(DatasetWizardModel.class.getDeclaredMethods())
setterMethod.invoke(datasetWizardModel, sourceValue); .filter(method -> method.getName().equals(methodName)).collect(Collectors.toList()).get(0);
}catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { Class<?>[] params = setterMethod.getParameterTypes();
e.printStackTrace(); setterMethod.invoke(datasetWizardModel, new ObjectMapper().readValue(value, params[0]));
}catch (InvocationTargetException | IllegalAccessException | JsonProcessingException e) {
throw e;
} }
} else { } else {
List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", prefillingMapping.getMaDmpTarget()); List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", prefillingMapping.getMaDmpTarget());
for (JsonNode node: nodes) { for (JsonNode node: nodes) {
String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText(); String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText();
properties.put(id, sourceValue); properties.put(id, value);
} }
} }
} }
dataset.setProperties(objectMapper.writeValueAsString(properties));
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset));
return datasetWizardModel;
}
@Override @Override
public String getHint() { public String getHint() {

View File

@ -1,10 +1,19 @@
package eu.eudat.models.rda.mapper; 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.Cost;
import eu.eudat.models.rda.PidSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CostRDAMapper { public class CostRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(DatasetRDAMapper.class);
public static Cost toRDA(Map<String, Object> cost) { public static Cost toRDA(Map<String, Object> cost) {
Cost rda = new Cost(); Cost rda = new Cost();
@ -19,4 +28,69 @@ public class CostRDAMapper {
return rda; 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

@ -9,10 +9,7 @@ import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.utilities.json.JsonSearcher; import eu.eudat.logic.utilities.json.JsonSearcher;
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel; import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel; import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.rda.Contributor; import eu.eudat.models.rda.*;
import eu.eudat.models.rda.Dataset;
import eu.eudat.models.rda.DatasetId;
import eu.eudat.models.rda.Language;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -20,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.net.URI;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -43,7 +41,7 @@ public class DatasetRDAMapper {
} }
@Transactional @Transactional
public Dataset toRDA(eu.eudat.data.entities.Dataset dataset, List<Contributor> contributors) { public Dataset toRDA(eu.eudat.data.entities.Dataset dataset, eu.eudat.models.rda.Dmp dmp) {
Dataset rda = new Dataset(); Dataset rda = new Dataset();
// rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId())); // rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
if (dataset.getLabel() == null) { if (dataset.getLabel() == null) {
@ -128,7 +126,11 @@ public class DatasetRDAMapper {
} }
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data"); List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data");
if (!personalDataNodes.isEmpty()) { if (!personalDataNodes.isEmpty()) {
try{
rda.setPersonalData(personalDataNodes.stream().map(personalDataNode -> Dataset.PersonalData.fromValue(personalDataNode.get("value").asText())).findFirst().get()); rda.setPersonalData(personalDataNodes.stream().map(personalDataNode -> Dataset.PersonalData.fromValue(personalDataNode.get("value").asText())).findFirst().get());
}catch(IllegalArgumentException e){
rda.setPersonalData(Dataset.PersonalData.UNKNOWN);
}
} else { } else {
rda.setPersonalData(Dataset.PersonalData.UNKNOWN); rda.setPersonalData(Dataset.PersonalData.UNKNOWN);
} }
@ -140,7 +142,11 @@ public class DatasetRDAMapper {
} }
List<JsonNode> sensitiveDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.sensitive_data"); List<JsonNode> sensitiveDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.sensitive_data");
if (!sensitiveDataNodes.isEmpty()) { if (!sensitiveDataNodes.isEmpty()) {
try{
rda.setSensitiveData(sensitiveDataNodes.stream().map(sensitiveDataNode -> Dataset.SensitiveData.fromValue(sensitiveDataNode.get("value").asText())).findFirst().get()); rda.setSensitiveData(sensitiveDataNodes.stream().map(sensitiveDataNode -> Dataset.SensitiveData.fromValue(sensitiveDataNode.get("value").asText())).findFirst().get());
}catch(IllegalArgumentException e){
rda.setSensitiveData(Dataset.SensitiveData.UNKNOWN);
}
} else { } else {
rda.setSensitiveData(Dataset.SensitiveData.UNKNOWN); rda.setSensitiveData(Dataset.SensitiveData.UNKNOWN);
} }
@ -156,15 +162,58 @@ public class DatasetRDAMapper {
} }
List<JsonNode> contributorNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.contributor"); List<JsonNode> contributorNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.contributor");
if (!contributorNodes.isEmpty()) { if (!contributorNodes.isEmpty()) {
contributors.addAll(contributorNodes.stream().map(contributorNode -> { dmp.getContributor().addAll(contributorNodes.stream().map(contributorNode -> {
JsonNode value = contributorNode.get("value"); JsonNode value = contributorNode.get("value");
if (value.isArray()) { if (value.isArray()) {
return StreamSupport.stream(value.spliterator(), false).map(node -> ContributorRDAMapper.toRDA(node.asText())).collect(Collectors.toList()); return StreamSupport.stream(value.spliterator(), false).map(node -> ContributorRDAMapper.toRDA(node.asText())).collect(Collectors.toList());
} else { } else {
return Collections.singletonList(new Contributor()); return Collections.singletonList(new Contributor()); // return null kalutera
} }
}).flatMap(Collection::stream).collect(Collectors.toList())); }).flatMap(Collection::stream).collect(Collectors.toList()));
} }
List<JsonNode> costNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.cost");
if (!costNodes.isEmpty()) {
dmp.getCost().addAll(CostRDAMapper.toRDAList(costNodes));
}
List<JsonNode> ethicsNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.ethical_issues");
if (!ethicsNodes.isEmpty()) {
for(JsonNode node: ethicsNodes){
String rdaProperty = node.get("rdaProperty").asText();
String rdaValue = node.get("value").asText();
if(rdaValue == null || rdaValue.isEmpty()){
continue;
}
if(rdaProperty.contains("exist")){
try {
Dmp.EthicalIssuesExist exists = dmp.getEthicalIssuesExist();
if(exists == null
|| ((exists == Dmp.EthicalIssuesExist.NO || exists == Dmp.EthicalIssuesExist.UNKNOWN) && rdaValue.equals("yes"))
|| (exists == Dmp.EthicalIssuesExist.YES && !(rdaValue.equals("no") || rdaValue.equals("unknown")))
|| (exists == Dmp.EthicalIssuesExist.UNKNOWN && rdaValue.equals("no"))){
dmp.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(rdaValue));
}
}catch(IllegalArgumentException e){
logger.warn(e.getLocalizedMessage() + ". Setting ethical_issues_exist to unknown");
dmp.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN);
}
}
else if(rdaProperty.contains("description")){
if(dmp.getEthicalIssuesDescription() == null){
dmp.setEthicalIssuesDescription(rdaValue);
}
else{
dmp.setEthicalIssuesDescription(dmp.getEthicalIssuesDescription() + ", " + rdaValue);
}
}
else if(rdaProperty.contains("report")){
try {
dmp.setEthicalIssuesReport(URI.create(rdaValue));
} catch (IllegalArgumentException e) {
logger.warn(e.getLocalizedMessage() + ". Skipping url parsing");
}
}
}
}
List<JsonNode> foundNodes = Stream.of(typeNodes, languageNodes, metadataNodes, qaNodes, preservationNodes, distributionNodes, List<JsonNode> foundNodes = Stream.of(typeNodes, languageNodes, metadataNodes, qaNodes, preservationNodes, distributionNodes,
keywordNodes, personalDataNodes, securityAndPrivacyNodes, sensitiveDataNodes, technicalResourceNodes).flatMap(Collection::stream).collect(Collectors.toList()); keywordNodes, personalDataNodes, securityAndPrivacyNodes, sensitiveDataNodes, technicalResourceNodes).flatMap(Collection::stream).collect(Collectors.toList());
templateIdsToValues.entrySet().forEach(entry -> { templateIdsToValues.entrySet().forEach(entry -> {

View File

@ -1,7 +1,11 @@
package eu.eudat.models.rda.mapper; package eu.eudat.models.rda.mapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.logic.utilities.helpers.MyStringUtils; import eu.eudat.logic.utilities.helpers.MyStringUtils;
import eu.eudat.logic.utilities.json.JavaToJson;
import eu.eudat.logic.utilities.json.JsonSearcher; import eu.eudat.logic.utilities.json.JsonSearcher;
import eu.eudat.models.rda.Distribution; import eu.eudat.models.rda.Distribution;
import eu.eudat.models.rda.License; import eu.eudat.models.rda.License;
@ -21,7 +25,8 @@ public class DistributionRDAMapper {
for (JsonNode node: nodes) { for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperty").asText(); String rdaProperty = node.get("rdaProperty").asText();
String rdaValue = node.get("value").asText(); String rdaValue = node.get("value").asText();
if(rdaValue == null || rdaValue.isEmpty()){ //if(rdaValue == null || rdaValue.isEmpty()){
if(rdaValue == null || (rdaValue.isEmpty() && !node.get("value").isArray())){
continue; continue;
} }
String key = node.get("numbering").asText(); String key = node.get("numbering").asText();
@ -39,10 +44,10 @@ public class DistributionRDAMapper {
rda = new Distribution(); rda = new Distribution();
rdaMap.put(key, rda); rdaMap.put(key, rda);
} }
/* Distribution rda = getRelative(rdaMap, node.get("numbering").asText()); /* Distribution rda = getRelative(rdaMap, node.get("numbering").asText());
if (!rdaMap.containsValue(rda)) { if (!rdaMap.containsValue(rda)) {
rdaMap.put(node.get("numbering").asText(), rda); rdaMap.put(node.get("numbering").asText(), rda);
}*/ } */
for (ExportPropertyName exportPropertyName : ExportPropertyName.values()) { for (ExportPropertyName exportPropertyName : ExportPropertyName.values()) {
if (rdaProperty.contains(exportPropertyName.getName())) { if (rdaProperty.contains(exportPropertyName.getName())) {
switch (exportPropertyName) { switch (exportPropertyName) {
@ -78,7 +83,25 @@ public class DistributionRDAMapper {
rda.setLicense(license != null? Collections.singletonList(license): new ArrayList<>()); rda.setLicense(license != null? Collections.singletonList(license): new ArrayList<>());
break; break;
case FORMAT: case FORMAT:
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());
try {
Map<String, String> result = new ObjectMapper().readValue(format, HashMap.class);
format = result.get("label");
formats.add(format);
}
catch(JsonProcessingException e){
logger.warn(e.getMessage());
}
}
rda.setFormat(formats);
}
else{
rda.setFormat(new ArrayList<>(Arrays.asList(rdaValue.replace(" ", "").split(",")))); rda.setFormat(new ArrayList<>(Arrays.asList(rdaValue.replace(" ", "").split(","))));
}
rda.setAdditionalProperty(ImportPropertyName.FORMAT.getName(), node.get("id").asText()); rda.setAdditionalProperty(ImportPropertyName.FORMAT.getName(), node.get("id").asText());
break; break;
case TITLE: case TITLE:

View File

@ -68,7 +68,7 @@ public class DmpRDAMapper {
if (!extraProperties.isEmpty()) { if (!extraProperties.isEmpty()) {
if (extraProperties.get("ethicalIssues") != null) { if (extraProperties.get("ethicalIssues") != null) {
rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(extraProperties.get("ethicalIsses").toString())); rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(extraProperties.get("ethicalIssues").toString()));
} else { } else {
rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN); rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN);
} }
@ -95,7 +95,7 @@ public class DmpRDAMapper {
rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList())); rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
} }
// rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList())); // rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
rda.setDataset(dmp.getDataset().stream().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)).collect(Collectors.toList()));
rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant()))); rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant())));
rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray()); rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray());
return rda; return rda;

View File

@ -22,7 +22,7 @@ public class HostRDAMapper {
String rdaProperty = node.get("rdaProperty").asText(); String rdaProperty = node.get("rdaProperty").asText();
if (rdaProperty.contains("host")) { if (rdaProperty.contains("host")) {
int firstDiff = MyStringUtils.getFirstDifference(numbering, node.get("numbering").asText()); 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(); String rdaValue = node.get("value").asText();
if(rdaValue == null || (rdaValue.isEmpty() && !node.get("value").isArray())){ if(rdaValue == null || (rdaValue.isEmpty() && !node.get("value").isArray())){
continue; continue;
@ -67,7 +67,14 @@ public class HostRDAMapper {
while(iter.hasNext()) { while(iter.hasNext()) {
pList.add(iter.next().asText()); pList.add(iter.next().asText());
} }
List<PidSystem> pidList = pList.stream().map(PidSystem::fromValue).collect(Collectors.toList()); 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.setPidSystem(pidList);
rda.setAdditionalProperty(ImportPropertyName.PID_SYSTEM.getName(), node.get("id").asText()); rda.setAdditionalProperty(ImportPropertyName.PID_SYSTEM.getName(), node.get("id").asText());
} }

View File

@ -15,22 +15,18 @@ public class KeywordRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class); private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class);
public static List<String> toRDA(String value) { public static List<String> toRDA(String value) {
ObjectMapper mapper = new ObjectMapper();
value = JavaToJson.objectStringToJson(value);
if (!value.isEmpty()) { if (!value.isEmpty()) {
try { try {
List<Tag> tags = Arrays.asList(mapper.readValue(value, Tag[].class)); ObjectMapper mapper = new ObjectMapper();
List<String> keywordNames = tags.stream().map(Tag::getName).collect(Collectors.toList()); String valueJson = JavaToJson.objectStringToJson(value);
return keywordNames; List<Tag> tags = Arrays.asList(mapper.readValue(valueJson, Tag[].class));
return tags.stream().map(Tag::getName).collect(Collectors.toList());
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
logger.warn(e.getMessage() + ". Attempting to parse it as a String list."); logger.warn(e.getMessage() + ". Attempting to parse it as a String list.");
if(!value.isEmpty()) {
return new ArrayList<>(Arrays.asList(value.replace(" ", "").split(","))); return new ArrayList<>(Arrays.asList(value.replace(" ", "").split(",")));
} }
} }
}
return new ArrayList<>(); return new ArrayList<>();
} }
} }

View File

@ -34,12 +34,49 @@ dataset.security_and_privacy.description
dataset.security_and_privacy.title dataset.security_and_privacy.title
dataset.sensitive_data dataset.sensitive_data
dataset.technical_resource.description dataset.technical_resource.description
dataset.technical_resource.technical_resource dataset.technical_resource.name
dataset.technical_resource.technical_resource.description dataset.title
dataset.technical_resource.technical_resource.name
dataset.type dataset.type
dataset.issued dataset.issued
dataset.dataset_id dataset.dataset_id
dataset.dataset_id.identifier dataset.dataset_id.identifier
dataset.dataset_id.type 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
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

View File

@ -19,7 +19,7 @@ elasticsearch.index=dmps
http-logger.server-address = http://localhost:31311 http-logger.server-address = http://localhost:31311
####################PDF OVERRIDES CONFIGURATIONS########## ####################PDF OVERRIDES CONFIGURATIONS##########
pdf.converter.url=http://localhost:88/ pdf.converter.url=http://localhost:3000/
####################CONFIGURATION FILES OVERRIDES CONFIGURATIONS########## ####################CONFIGURATION FILES OVERRIDES CONFIGURATIONS##########
configuration.externalUrls=externalUrls/ExternalUrls.xml configuration.externalUrls=externalUrls/ExternalUrls.xml

View File

@ -1034,6 +1034,10 @@
<mapping source="metadata.description" target="description" /> <mapping source="metadata.description" target="description" />
<mapping source="metadata.license.id" maDmpTarget="dataset.distribution.license.license_ref" /> <mapping source="metadata.license.id" maDmpTarget="dataset.distribution.license.license_ref" />
</mappings> </mappings>
<fixedMappings>
<fixedMapping target="tags" value="[{&quot;id&quot;: &quot;test&quot;, &quot;name&quot;: &quot;test&quot;}]"/>
<fixedMapping maDmpTarget="dataset.distribution.host.title" value="zenodo" />
</fixedMappings>
</prefillingGet> </prefillingGet>
</config> </config>
</prefillings> </prefillings>