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.setLanguage(oldDatasetProfile.getLanguage());
apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
eu.eudat.data.entities.DatasetProfile datasetProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
this.storeDatasetProfileUsers(datasetProfile, profile);
return modelDefinition;
} else {
throw new DatasetProfileNewVersionException("Version to update not the latest.");

View File

@ -52,7 +52,7 @@ public class PrefillingManager {
PrefillingGet prefillingGet = prefillingConfig.getPrefillingGet();
Map<String, Object> prefillingEntity = getSingle(prefillingGet.getUrl(), prefillId);
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) {

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;
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.XmlElementWrapper;
import java.util.List;
public class PrefillingGet{
private String url;
private List<PrefillingMapping> mappings;
private List<DefaultPrefillingMapping> mappings;
private List<PrefillingFixedMapping> fixedMappings;
public String getUrl() {
return url;
@ -20,13 +18,23 @@ public class PrefillingGet{
this.url = url;
}
public List<PrefillingMapping> getMappings() {
public List<DefaultPrefillingMapping> getMappings() {
return mappings;
}
@XmlElement(name = "mapping")
@XmlElementWrapper
public void setMappings(List<PrefillingMapping> mappings) {
public void setMappings(List<DefaultPrefillingMapping> 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;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "mapping")
public class PrefillingMapping {
private String source;
private String target;
private String maDmpTarget;
public interface PrefillingMapping {
String getTarget();
public String getSource() {
return source;
}
void setTarget(String target);
@XmlAttribute(name = "source")
public void setSource(String source) {
this.source = source;
}
String getMaDmpTarget();
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;
}
void setMaDmpTarget(String maDmpTarget);
}

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) {
@ -193,18 +193,26 @@ public class WordBuilder {
boolean hasValue = false;
for (FieldSet compositeField: compositeFields) {
if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) {
char c = 'a';
int paragraphPos = -1;
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
XWPFParagraph paragraph = addParagraphContent(page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
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);
if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) {
List<FieldSet> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList());
for (FieldSet multiplicityFieldset : list) {
hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService);
if(!createListing){
c++;
addParagraphContent(c + ".\n", mainDocumentPart, ParagraphStyle.HEADER6, numId);
}
hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService);
}
}
if (hasValue && compositeField.getHasCommentField() && compositeField.getCommentFieldValue() != null && !compositeField.getCommentFieldValue().isEmpty() && !createListing) {
@ -224,13 +232,31 @@ public class WordBuilder {
if (createListing) this.addListing(mainDocumentPart, indent, false, false);
boolean hasValue = false;
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) {
if (visibilityRuleService.isElementVisible(field.getId())) {
if (!createListing) {
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){
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) {
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

@ -1,10 +1,14 @@
package eu.eudat.models.data.datasetwizard;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.entities.*;
import eu.eudat.elastic.entities.Tag;
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.utilities.json.JsonSearcher;
import eu.eudat.models.DataModel;
@ -20,7 +24,6 @@ import net.minidev.json.JSONValue;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@ -305,7 +308,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
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 {
DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(profile));
@ -314,7 +317,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
Map<String, Object> properties = new HashMap<>();
ObjectMapper objectMapper = new ObjectMapper();
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("\\."));
Object sourceValue = null;
for (String sourceKey: sourceKeys) {
@ -324,27 +327,36 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
sourceValue = ((Map)sourceValue).get(sourceKey);
}
}
if (prefillingMapping.getTarget() != null) {
try {
String methodName = "set" + prefillingMapping.getTarget().substring(0, 1).toUpperCase(Locale.ROOT) + prefillingMapping.getTarget().substring(1);
Method setterMethod = DatasetWizardModel.class.getMethod(methodName, String.class);
setterMethod.invoke(datasetWizardModel, sourceValue);
}catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
} else {
List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", prefillingMapping.getMaDmpTarget());
for (JsonNode node: nodes) {
String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText();
properties.put(id, sourceValue);
}
}
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) {
try {
String methodName = "set" + prefillingMapping.getTarget().substring(0, 1).toUpperCase(Locale.ROOT) + prefillingMapping.getTarget().substring(1);
Method setterMethod = Arrays.stream(DatasetWizardModel.class.getDeclaredMethods())
.filter(method -> method.getName().equals(methodName)).collect(Collectors.toList()).get(0);
Class<?>[] params = setterMethod.getParameterTypes();
setterMethod.invoke(datasetWizardModel, new ObjectMapper().readValue(value, params[0]));
}catch (InvocationTargetException | IllegalAccessException | JsonProcessingException e) {
throw e;
}
} else {
List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", prefillingMapping.getMaDmpTarget());
for (JsonNode node: nodes) {
String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText();
properties.put(id, value);
}
}
}
@Override
public String getHint() {
return "datasetWizardModel";

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

@ -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;
@ -20,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
import java.net.URI;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
@ -43,7 +41,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, eu.eudat.models.rda.Dmp dmp) {
Dataset rda = new Dataset();
// rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId()));
if (dataset.getLabel() == null) {
@ -128,7 +126,11 @@ public class DatasetRDAMapper {
}
List<JsonNode> personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.personal_data");
if (!personalDataNodes.isEmpty()) {
rda.setPersonalData(personalDataNodes.stream().map(personalDataNode -> Dataset.PersonalData.fromValue(personalDataNode.get("value").asText())).findFirst().get());
try{
rda.setPersonalData(personalDataNodes.stream().map(personalDataNode -> Dataset.PersonalData.fromValue(personalDataNode.get("value").asText())).findFirst().get());
}catch(IllegalArgumentException e){
rda.setPersonalData(Dataset.PersonalData.UNKNOWN);
}
} else {
rda.setPersonalData(Dataset.PersonalData.UNKNOWN);
}
@ -140,7 +142,11 @@ public class DatasetRDAMapper {
}
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());
try{
rda.setSensitiveData(sensitiveDataNodes.stream().map(sensitiveDataNode -> Dataset.SensitiveData.fromValue(sensitiveDataNode.get("value").asText())).findFirst().get());
}catch(IllegalArgumentException e){
rda.setSensitiveData(Dataset.SensitiveData.UNKNOWN);
}
} else {
rda.setSensitiveData(Dataset.SensitiveData.UNKNOWN);
}
@ -156,15 +162,58 @@ public class DatasetRDAMapper {
}
List<JsonNode> contributorNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dmp.contributor");
if (!contributorNodes.isEmpty()) {
contributors.addAll(contributorNodes.stream().map(contributorNode -> {
dmp.getContributor().addAll(contributorNodes.stream().map(contributorNode -> {
JsonNode value = contributorNode.get("value");
if (value.isArray()) {
return StreamSupport.stream(value.spliterator(), false).map(node -> ContributorRDAMapper.toRDA(node.asText())).collect(Collectors.toList());
} else {
return Collections.singletonList(new Contributor());
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()) {
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,
keywordNodes, personalDataNodes, securityAndPrivacyNodes, sensitiveDataNodes, technicalResourceNodes).flatMap(Collection::stream).collect(Collectors.toList());
templateIdsToValues.entrySet().forEach(entry -> {

View File

@ -1,7 +1,11 @@
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.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 eu.eudat.models.rda.License;
@ -21,7 +25,8 @@ public class DistributionRDAMapper {
for (JsonNode node: nodes) {
String rdaProperty = node.get("rdaProperty").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;
}
String key = node.get("numbering").asText();
@ -39,10 +44,10 @@ public class DistributionRDAMapper {
rda = new Distribution();
rdaMap.put(key, rda);
}
/* Distribution rda = getRelative(rdaMap, node.get("numbering").asText());
/* 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) {
@ -78,7 +83,25 @@ public class DistributionRDAMapper {
rda.setLicense(license != null? Collections.singletonList(license): new ArrayList<>());
break;
case FORMAT:
rda.setFormat(new ArrayList<>(Arrays.asList(rdaValue.replace(" ", "").split(","))));
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.setAdditionalProperty(ImportPropertyName.FORMAT.getName(), node.get("id").asText());
break;
case TITLE:

View File

@ -68,7 +68,7 @@ public class DmpRDAMapper {
if (!extraProperties.isEmpty()) {
if (extraProperties.get("ethicalIssues") != null) {
rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(extraProperties.get("ethicalIsses").toString()));
rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(extraProperties.get("ethicalIssues").toString()));
} else {
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.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.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray());
return rda;

View File

@ -22,7 +22,7 @@ public class HostRDAMapper {
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;
@ -67,7 +67,14 @@ public class HostRDAMapper {
while(iter.hasNext()) {
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.setAdditionalProperty(ImportPropertyName.PID_SYSTEM.getName(), node.get("id").asText());
}

View File

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

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
dmp.contributor
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

View File

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

View File

@ -1034,6 +1034,10 @@
<mapping source="metadata.description" target="description" />
<mapping source="metadata.license.id" maDmpTarget="dataset.distribution.license.license_ref" />
</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>
</config>
</prefillings>