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

This commit is contained in:
DESKTOP-4ES9U2E\aldom 2022-01-12 14:11:18 +02:00
commit dc1f59d8b5
16 changed files with 152 additions and 64 deletions

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

@ -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

@ -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>

View File

@ -8,9 +8,14 @@
<mat-progress-bar color="primary" mode="indeterminate"></mat-progress-bar>
</div>
<div mat-dialog-content *ngIf="prefillForm" [formGroup]="prefillForm" class="definition-content">
<div class="row d-flex align-items-center justify-content-center">
<div class="pb-4 pl-4 pr-4">
{{'DATASET-CREATE-WIZARD.PREFILL-STEP.HINT' | translate}}
</div>
</div>
<div class="row d-flex align-items-center justify-content-center" [class.pb-4]="isPrefilled">
<button mat-raised-button type="button" class="empty-btn"
(click)="closeDialog()">{{'DATASET-CREATE-WIZARD.PREFILL-STEP.EMPTY' | translate}}</button>
(click)="closeDialog()">{{'DATASET-CREATE-WIZARD.PREFILL-STEP.MANUALLY' | translate}}</button>
<div class="ml-2 mr-2">{{'DATASET-CREATE-WIZARD.PREFILL-STEP.OR' | translate}}</div>
<button mat-raised-button type="button" class="prefill-btn"
(click)="isPrefilled = true">{{'DATASET-CREATE-WIZARD.PREFILL-STEP.PREFILL' | translate}}</button>

View File

@ -1275,7 +1275,8 @@
"TITLE": "Initialize your Dataset",
"PREFILL": "Prefill",
"OR": "OR",
"EMPTY": "Empty",
"HINT": "Select the dataset from Zenodo to automatically retrieve answers to some questions in your template or start by answering the questions manually.",
"MANUALLY": "Manually",
"PROFILE": "Dataset Template",
"PREFILLED-DATASET": "Prefilled Dataset",
"SEARCH": "Search a Dataset",

View File

@ -1275,7 +1275,8 @@
"TITLE": "Initialize your Dataset",
"PREFILL": "Prefill",
"OR": "OR",
"EMPTY": "Empty",
"HINT": "Select the dataset from Zenodo to automatically retrieve answers to some questions in your template or start by answering the questions manually.",
"MANUALLY": "Manually",
"PROFILE": "Dataset Template",
"PREFILLED-DATASET": "Prefilled Dataset",
"SEARCH": "Search a Dataset",

View File

@ -1275,7 +1275,8 @@
"TITLE": "Initialize your Dataset",
"PREFILL": "Prefill",
"OR": "OR",
"EMPTY": "Empty",
"HINT": "Select the dataset from Zenodo to automatically retrieve answers to some questions in your template or start by answering the questions manually.",
"MANUALLY": "Manually",
"PROFILE": "Dataset Template",
"PREFILLED-DATASET": "Prefilled Dataset",
"SEARCH": "Search a Dataset",

View File

@ -1275,7 +1275,8 @@
"TITLE": "Initialize your Dataset",
"PREFILL": "Prefill",
"OR": "OR",
"EMPTY": "Empty",
"HINT": "Select the dataset from Zenodo to automatically retrieve answers to some questions in your template or start by answering the questions manually.",
"MANUALLY": "Manually",
"PROFILE": "Dataset Template",
"PREFILLED-DATASET": "Prefilled Dataset",
"SEARCH": "Search a Dataset",

View File

@ -1275,7 +1275,8 @@
"TITLE": "Initialize your Dataset",
"PREFILL": "Prefill",
"OR": "OR",
"EMPTY": "Empty",
"HINT": "Select the dataset from Zenodo to automatically retrieve answers to some questions in your template or start by answering the questions manually.",
"MANUALLY": "Manually",
"PROFILE": "Dataset Template",
"PREFILLED-DATASET": "Prefilled Dataset",
"SEARCH": "Search a Dataset",

View File

@ -1275,7 +1275,8 @@
"TITLE": "Initialize your Dataset",
"PREFILL": "Prefill",
"OR": "OR",
"EMPTY": "Empty",
"HINT": "Select the dataset from Zenodo to automatically retrieve answers to some questions in your template or start by answering the questions manually.",
"MANUALLY": "Manually",
"PROFILE": "Dataset Template",
"PREFILLED-DATASET": "Prefilled Dataset",
"SEARCH": "Search a Dataset",

View File

@ -1275,7 +1275,8 @@
"TITLE": "Initialize your Dataset",
"PREFILL": "Prefill",
"OR": "OR",
"EMPTY": "Empty",
"HINT": "Select the dataset from Zenodo to automatically retrieve answers to some questions in your template or start by answering the questions manually.",
"MANUALLY": "Manually",
"PROFILE": "Dataset Template",
"PREFILLED-DATASET": "Prefilled Dataset",
"SEARCH": "Search a Dataset",

View File

@ -1275,7 +1275,8 @@
"TITLE": "Initialize your Dataset",
"PREFILL": "Prefill",
"OR": "OR",
"EMPTY": "Empty",
"HINT": "Select the dataset from Zenodo to automatically retrieve answers to some questions in your template or start by answering the questions manually.",
"MANUALLY": "Manually",
"PROFILE": "Dataset Template",
"PREFILLED-DATASET": "Prefilled Dataset",
"SEARCH": "Search a Dataset",