Generalized (again) dataset prefilling
This commit is contained in:
parent
d1eab0d019
commit
f6cb4a40d2
|
@ -70,11 +70,6 @@ public class PrefillingMapper {
|
||||||
//GK: Tags Special logic
|
//GK: Tags Special logic
|
||||||
if (!value.equals("null") && prefillingMapping.getTarget().equals("tags")) {
|
if (!value.equals("null") && prefillingMapping.getTarget().equals("tags")) {
|
||||||
value = mapper.valueToTree(parseTags(value)).toString();
|
value = mapper.valueToTree(parseTags(value)).toString();
|
||||||
List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", "dataset.keyword");
|
|
||||||
for (JsonNode node: nodes) {
|
|
||||||
String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText();
|
|
||||||
properties.put(id, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setterMethod.invoke(datasetWizardModel, mapper.readValue(value, params[0]));
|
setterMethod.invoke(datasetWizardModel, mapper.readValue(value, params[0]));
|
||||||
}catch (InvocationTargetException | IllegalAccessException | JsonProcessingException e) {
|
}catch (InvocationTargetException | IllegalAccessException | JsonProcessingException e) {
|
||||||
|
@ -88,7 +83,7 @@ public class PrefillingMapper {
|
||||||
}
|
}
|
||||||
JsonNode valueNode = mapper.readTree(value);
|
JsonNode valueNode = mapper.readTree(value);
|
||||||
List<String> parsedValues = new ArrayList<>();
|
List<String> parsedValues = new ArrayList<>();
|
||||||
if (valueNode.isArray() && (!valueNode.get(0).isTextual() || !valueNode.get(0).isNull())) {
|
if (valueNode.isArray() && (!valueNode.get(0).isTextual())) {
|
||||||
if (prefillingMapping.getSubSource() == null || prefillingMapping.getSubSource().isEmpty()) {
|
if (prefillingMapping.getSubSource() == null || prefillingMapping.getSubSource().isEmpty()) {
|
||||||
throw new IllegalArgumentException("Source value is an array but no subSource field have been set");
|
throw new IllegalArgumentException("Source value is an array but no subSource field have been set");
|
||||||
}
|
}
|
||||||
|
@ -104,6 +99,41 @@ public class PrefillingMapper {
|
||||||
String parsedValue = null;
|
String parsedValue = null;
|
||||||
if (valueNode.isTextual()) {
|
if (valueNode.isTextual()) {
|
||||||
parsedValue = valueNode.textValue().replace(trimRegex, "");
|
parsedValue = valueNode.textValue().replace(trimRegex, "");
|
||||||
|
}else if (valueNode.isArray() && valueNode.get(0).isTextual()) {
|
||||||
|
List<String> values = new LinkedList<>();
|
||||||
|
for (int i = 0; i < valueNode.size(); i++) {
|
||||||
|
values.add(valueNode.get(i).textValue().replace(trimRegex, ""));
|
||||||
|
}
|
||||||
|
parsedValue = String.join(", ", values);
|
||||||
|
}
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
//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();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JsonNode node: nodes) {
|
for (JsonNode node: nodes) {
|
||||||
|
@ -114,27 +144,7 @@ public class PrefillingMapper {
|
||||||
case COMBO_BOX:
|
case COMBO_BOX:
|
||||||
if (parsedValues.isEmpty())
|
if (parsedValues.isEmpty())
|
||||||
parsedValues.add(parsedValue);
|
parsedValues.add(parsedValue);
|
||||||
if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){
|
properties.put(id, parseComboBoxValues(node, parsedValues));
|
||||||
if(parsedValue != null && parsedValue.equals("open")){
|
|
||||||
properties.put(id, parsedValue);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(parsedValue != null && parsedValue.equals("restricted")){
|
|
||||||
properties.put(id, "shared");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
properties.put(id, "closed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
properties.put(id, parseComboBoxValues(node, parsedValues));
|
|
||||||
break;
|
break;
|
||||||
case TAGS:
|
case TAGS:
|
||||||
properties.put(id, parseTags(parsedValue));
|
properties.put(id, parseTags(parsedValue));
|
||||||
|
@ -143,21 +153,7 @@ public class PrefillingMapper {
|
||||||
if (!parsedValues.isEmpty())
|
if (!parsedValues.isEmpty())
|
||||||
properties.put(id, String.join(", ", parsedValues));
|
properties.put(id, String.join(", ", parsedValues));
|
||||||
else {
|
else {
|
||||||
if (prefillingMapping.getMaDmpTarget().equals("dataset.dataset_id")) {
|
properties.put(id, parsedValue);
|
||||||
JSONObject datasetID = new JSONObject();
|
|
||||||
datasetID.put("identifier", parsedValue);
|
|
||||||
datasetID.put("type", "doi");
|
|
||||||
properties.put(id, datasetID.toString());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
properties.put(id, parsedValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1184,6 +1184,7 @@ but not
|
||||||
<mapping source="metadata.description" target="description" />
|
<mapping source="metadata.description" target="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.filesize" maDmpTarget="dataset.distribution.byte_size"/>
|
<mapping source="metadata.filesize" maDmpTarget="dataset.distribution.byte_size"/>
|
||||||
<mapping source="metadata.language" maDmpTarget="dataset.metadata.language"/>
|
<mapping source="metadata.language" maDmpTarget="dataset.metadata.language"/>
|
||||||
<mapping source="metadata.dates.valid" maDmpTarget="dataset.distribution.available_until"/>
|
<mapping source="metadata.dates.valid" maDmpTarget="dataset.distribution.available_until"/>
|
||||||
|
|
Loading…
Reference in New Issue