zenodo prefilling customizations
This commit is contained in:
parent
3c42ee3531
commit
494ee47620
|
@ -50,7 +50,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 PrefillingMapper.mapPrefilledEntityToDatasetWizard(prefillingEntity, prefillingGet, datasetProfile, datasetManager);
|
||||
return PrefillingMapper.mapPrefilledEntityToDatasetWizard(prefillingEntity, prefillingGet, prefillingConfig.getType(), datasetProfile, datasetManager);
|
||||
}
|
||||
|
||||
private Map<String, Object> getSingle(String url, String id) {
|
||||
|
|
|
@ -20,6 +20,7 @@ import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
|
|||
import eu.eudat.models.data.datasetprofile.RenderStyle;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -31,7 +32,7 @@ import java.util.stream.Collectors;
|
|||
public class PrefillingMapper {
|
||||
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 {
|
||||
DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
|
||||
datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(profile));
|
||||
|
@ -49,17 +50,17 @@ public class PrefillingMapper {
|
|||
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()) {
|
||||
setValue(fixedMapping, fixedMapping.getValue(), datasetWizardModel, parentNode, properties);
|
||||
setValue(fixedMapping, fixedMapping.getValue(), datasetWizardModel, parentNode, properties, type);
|
||||
}
|
||||
dataset.setProperties(mapper.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 {
|
||||
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() : "";
|
||||
if (!value.startsWith("\"") && !value.startsWith("[") && !value.equals("null")) {
|
||||
value = "\"" + value + "\"";
|
||||
|
@ -109,33 +110,29 @@ public class PrefillingMapper {
|
|||
} else {
|
||||
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
|
||||
/*if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){
|
||||
if(parsedValue != null && parsedValue.equals("open")){
|
||||
List<JsonNode> issuedNodes = JsonSearcher.findNodes(parentNode, "rdaProperty", "dataset.issued");
|
||||
String issuedIdNode = issuedNodes.get(0).get("id").asText();
|
||||
String issuedValue = (String)properties.get(issuedIdNode);
|
||||
List<JsonNode> licStartDateNodes = JsonSearcher.findNodes(parentNode, "rdaProperty", "dataset.distribution.license.start_date");
|
||||
for (JsonNode licStartDateNode: licStartDateNodes) {
|
||||
String licStartDateId = licStartDateNode.get(0) != null ? licStartDateNode.get(0).get("id").asText() : licStartDateNode.get("id").asText();
|
||||
properties.put(licStartDateId, issuedValue);
|
||||
// zenodo prefilling customizations
|
||||
if(type.equals("zenodo")){
|
||||
if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){
|
||||
if(parsedValue != null && parsedValue.equals("open")){
|
||||
List<JsonNode> issuedNodes = JsonSearcher.findNodes(parentNode, "rdaProperty", "dataset.issued");
|
||||
if(!issuedNodes.isEmpty()){
|
||||
String issuedIdNode = issuedNodes.get(0).get("id").asText();
|
||||
String issuedValue = (String) properties.get(issuedIdNode);
|
||||
List<JsonNode> licStartDateNodes = JsonSearcher.findNodes(parentNode, "rdaProperty", "dataset.distribution.license.start_date");
|
||||
for (JsonNode licStartDateNode : licStartDateNodes) {
|
||||
String licStartDateId = licStartDateNode.get(0) != null ? licStartDateNode.get(0).get("id").asText() : licStartDateNode.get("id").asText();
|
||||
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")) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd");
|
||||
LocalDate date = LocalDate.parse(parsedValue, formatter);
|
||||
date = date.plusYears(20);
|
||||
parsedValue = date.toString();
|
||||
if (prefillingMapping.getMaDmpTarget().equals("dataset.distribution.available_until") && parsedValue != null && !parsedValue.equals("null")) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd");
|
||||
LocalDate date = LocalDate.parse(parsedValue, formatter);
|
||||
date = date.plusYears(20);
|
||||
parsedValue = date.toString();
|
||||
}
|
||||
}
|
||||
|
||||
for (JsonNode node: nodes) {
|
||||
|
@ -151,6 +148,14 @@ public class PrefillingMapper {
|
|||
case TAGS:
|
||||
properties.put(id, mapper.valueToTree(parseTags(parsedValue)).toString());
|
||||
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:
|
||||
if (!parsedValues.isEmpty())
|
||||
properties.put(id, String.join(", ", parsedValues));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.logic.proxy.config.entities;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
|
@ -9,6 +10,8 @@ public class PrefillingConfig {
|
|||
private PrefillingSearch prefillingSearch;
|
||||
private PrefillingGet prefillingGet;
|
||||
|
||||
private String type;
|
||||
|
||||
public PrefillingSearch getPrefillingSearch() {
|
||||
return prefillingSearch;
|
||||
}
|
||||
|
@ -26,4 +29,13 @@ public class PrefillingConfig {
|
|||
public void setPrefillingGet(PrefillingGet prefillingGet) {
|
||||
this.prefillingGet = prefillingGet;
|
||||
}
|
||||
|
||||
@XmlAttribute(name = "type")
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType(){
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1156,7 +1156,7 @@ but not
|
|||
</validators>
|
||||
|
||||
<prefillings>
|
||||
<config id="zenodo">
|
||||
<config id="zenodo" type="zenodo">
|
||||
<prefillingSearch>
|
||||
<urlConfig>
|
||||
<key>zenodo</key>
|
||||
|
@ -1181,7 +1181,9 @@ but not
|
|||
<url>https://zenodo.org/api/records/{id}</url>
|
||||
<mappings>
|
||||
<mapping source="metadata.title" target="label" />
|
||||
<mapping source="metadata.title" maDmpTarget="dataset.distribution.title" />
|
||||
<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.keywords" target="tags"/>
|
||||
<mapping source="metadata.keywords" maDmpTarget="dataset.keyword"/>
|
||||
|
|
Loading…
Reference in New Issue