zenodo prefilling customizations

This commit is contained in:
Bernaldo Mihasi 2022-02-22 15:53:25 +02:00
parent 3c42ee3531
commit 494ee47620
4 changed files with 49 additions and 30 deletions

View File

@ -50,7 +50,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 PrefillingMapper.mapPrefilledEntityToDatasetWizard(prefillingEntity, prefillingGet, datasetProfile, datasetManager); return PrefillingMapper.mapPrefilledEntityToDatasetWizard(prefillingEntity, prefillingGet, prefillingConfig.getType(), datasetProfile, datasetManager);
} }
private Map<String, Object> getSingle(String url, String id) { private Map<String, Object> getSingle(String url, String id) {

View File

@ -20,6 +20,7 @@ import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
import eu.eudat.models.data.datasetprofile.RenderStyle; import eu.eudat.models.data.datasetprofile.RenderStyle;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel; import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel; import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
import org.json.JSONObject;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -31,7 +32,7 @@ import java.util.stream.Collectors;
public class PrefillingMapper { public class PrefillingMapper {
private static final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); private static final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
public static DatasetWizardModel mapPrefilledEntityToDatasetWizard(Map<String, Object> prefilledEntity, PrefillingGet prefillingGet, public static DatasetWizardModel mapPrefilledEntityToDatasetWizard(Map<String, Object> prefilledEntity, PrefillingGet prefillingGet, String type,
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));
@ -49,17 +50,17 @@ public class PrefillingMapper {
sourceValue = ((Map)sourceValue).get(sourceKey); sourceValue = ((Map)sourceValue).get(sourceKey);
} }
} }
setValue(prefillingMapping, mapper.writeValueAsString(sourceValue), datasetWizardModel, parentNode, properties); setValue(prefillingMapping, mapper.writeValueAsString(sourceValue), datasetWizardModel, parentNode, properties, type);
} }
for (PrefillingFixedMapping fixedMapping: prefillingGet.getFixedMappings()) { for (PrefillingFixedMapping fixedMapping: prefillingGet.getFixedMappings()) {
setValue(fixedMapping, fixedMapping.getValue(), datasetWizardModel, parentNode, properties); setValue(fixedMapping, fixedMapping.getValue(), datasetWizardModel, parentNode, properties, type);
} }
dataset.setProperties(mapper.writeValueAsString(properties)); dataset.setProperties(mapper.writeValueAsString(properties));
datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset)); datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset));
return datasetWizardModel; return datasetWizardModel;
} }
private static void setValue(PrefillingMapping prefillingMapping, String value, DatasetWizardModel datasetWizardModel, JsonNode parentNode, Map<String, Object> properties) throws InvocationTargetException, IllegalAccessException, JsonProcessingException { private static void setValue(PrefillingMapping prefillingMapping, String value, DatasetWizardModel datasetWizardModel, JsonNode parentNode, Map<String, Object> properties, String type) throws InvocationTargetException, IllegalAccessException, JsonProcessingException {
String trimRegex = prefillingMapping.getTrimRegex() != null ? prefillingMapping.getTrimRegex() : ""; String trimRegex = prefillingMapping.getTrimRegex() != null ? prefillingMapping.getTrimRegex() : "";
if (!value.startsWith("\"") && !value.startsWith("[") && !value.equals("null")) { if (!value.startsWith("\"") && !value.startsWith("[") && !value.equals("null")) {
value = "\"" + value + "\""; value = "\"" + value + "\"";
@ -109,10 +110,12 @@ public class PrefillingMapper {
} else { } else {
List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", prefillingMapping.getMaDmpTarget()); List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", prefillingMapping.getMaDmpTarget());
//GK: This is not generic and it will crash if the dataset.issued is not available on the template // zenodo prefilling customizations
/*if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){ if(type.equals("zenodo")){
if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){
if(parsedValue != null && parsedValue.equals("open")){ if(parsedValue != null && parsedValue.equals("open")){
List<JsonNode> issuedNodes = JsonSearcher.findNodes(parentNode, "rdaProperty", "dataset.issued"); List<JsonNode> issuedNodes = JsonSearcher.findNodes(parentNode, "rdaProperty", "dataset.issued");
if(!issuedNodes.isEmpty()){
String issuedIdNode = issuedNodes.get(0).get("id").asText(); String issuedIdNode = issuedNodes.get(0).get("id").asText();
String issuedValue = (String) properties.get(issuedIdNode); String issuedValue = (String) properties.get(issuedIdNode);
List<JsonNode> licStartDateNodes = JsonSearcher.findNodes(parentNode, "rdaProperty", "dataset.distribution.license.start_date"); List<JsonNode> licStartDateNodes = JsonSearcher.findNodes(parentNode, "rdaProperty", "dataset.distribution.license.start_date");
@ -121,15 +124,8 @@ public class PrefillingMapper {
properties.put(licStartDateId, issuedValue); properties.put(licStartDateId, issuedValue);
} }
} }
}*/ }
}
//GK: How do we know what field will get that value? and why is only DOI?
/*if (prefillingMapping.getMaDmpTarget().equals("dataset.dataset_id")) {
JSONObject datasetID = new JSONObject();
datasetID.put("identifier", parsedValue);
datasetID.put("type", "doi");
properties.put(id, datasetID.toString());
}*/
if (prefillingMapping.getMaDmpTarget().equals("dataset.distribution.available_until") && parsedValue != null && !parsedValue.equals("null")) { if (prefillingMapping.getMaDmpTarget().equals("dataset.distribution.available_until") && parsedValue != null && !parsedValue.equals("null")) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd");
@ -137,6 +133,7 @@ public class PrefillingMapper {
date = date.plusYears(20); date = date.plusYears(20);
parsedValue = date.toString(); parsedValue = date.toString();
} }
}
for (JsonNode node: nodes) { for (JsonNode node: nodes) {
String id = node.isArray() ? node.get(0).get("id").asText() : node.get("id").asText(); String id = node.isArray() ? node.get(0).get("id").asText() : node.get("id").asText();
@ -151,6 +148,14 @@ public class PrefillingMapper {
case TAGS: case TAGS:
properties.put(id, mapper.valueToTree(parseTags(parsedValue)).toString()); properties.put(id, mapper.valueToTree(parseTags(parsedValue)).toString());
break; break;
case DATASET_IDENTIFIER:
JSONObject datasetID = new JSONObject();
datasetID.put("identifier", parsedValue);
if(type.equals("zenodo")){
datasetID.put("type", "doi");
}
properties.put(id, datasetID.toString());
break;
default: default:
if (!parsedValues.isEmpty()) if (!parsedValues.isEmpty())
properties.put(id, String.join(", ", parsedValues)); properties.put(id, String.join(", ", parsedValues));

View File

@ -1,5 +1,6 @@
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.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@ -9,6 +10,8 @@ public class PrefillingConfig {
private PrefillingSearch prefillingSearch; private PrefillingSearch prefillingSearch;
private PrefillingGet prefillingGet; private PrefillingGet prefillingGet;
private String type;
public PrefillingSearch getPrefillingSearch() { public PrefillingSearch getPrefillingSearch() {
return prefillingSearch; return prefillingSearch;
} }
@ -26,4 +29,13 @@ public class PrefillingConfig {
public void setPrefillingGet(PrefillingGet prefillingGet) { public void setPrefillingGet(PrefillingGet prefillingGet) {
this.prefillingGet = prefillingGet; this.prefillingGet = prefillingGet;
} }
@XmlAttribute(name = "type")
public void setType(String type) {
this.type = type;
}
public String getType(){
return type;
}
} }

View File

@ -1156,7 +1156,7 @@ but not
</validators> </validators>
<prefillings> <prefillings>
<config id="zenodo"> <config id="zenodo" type="zenodo">
<prefillingSearch> <prefillingSearch>
<urlConfig> <urlConfig>
<key>zenodo</key> <key>zenodo</key>
@ -1181,7 +1181,9 @@ but not
<url>https://zenodo.org/api/records/{id}</url> <url>https://zenodo.org/api/records/{id}</url>
<mappings> <mappings>
<mapping source="metadata.title" target="label" /> <mapping source="metadata.title" target="label" />
<mapping source="metadata.title" maDmpTarget="dataset.distribution.title" />
<mapping source="metadata.description" target="description" /> <mapping source="metadata.description" target="description" />
<mapping source="metadata.description" maDmpTarget="dataset.distribution.description" />
<mapping source="metadata.license.id" maDmpTarget="dataset.distribution.license.license_ref" /> <mapping source="metadata.license.id" maDmpTarget="dataset.distribution.license.license_ref" />
<mapping source="metadata.keywords" target="tags"/> <mapping source="metadata.keywords" target="tags"/>
<mapping source="metadata.keywords" maDmpTarget="dataset.keyword"/> <mapping source="metadata.keywords" maDmpTarget="dataset.keyword"/>