Add fixedMappings for prefilling
This commit is contained in:
parent
1d68b2a379
commit
db01f2d119
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,35 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
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) {
|
||||
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);
|
||||
setterMethod.invoke(datasetWizardModel, sourceValue);
|
||||
}catch (InvocationTargetException | IllegalAccessException e) {
|
||||
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, sourceValue);
|
||||
properties.put(id, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
dataset.setProperties(objectMapper.writeValueAsString(properties));
|
||||
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset));
|
||||
return datasetWizardModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHint() {
|
||||
|
|
|
@ -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="[{"id": "xaxa", "name": "xaxa"}]"/>
|
||||
<fixedMapping maDmpTarget="dataset.distribution.host.title" value="zenodo" />
|
||||
</fixedMappings>
|
||||
</prefillingGet>
|
||||
</config>
|
||||
</prefillings>
|
||||
|
|
Loading…
Reference in New Issue