Improve tags pre-filling mapping
This commit is contained in:
parent
0bd08c2fac
commit
3c42ee3531
|
@ -60,22 +60,6 @@ public class PrefillingMapper {
|
|||
}
|
||||
|
||||
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();
|
||||
//GK: Tags Special logic
|
||||
if (!value.equals("null") && prefillingMapping.getTarget().equals("tags")) {
|
||||
value = mapper.valueToTree(parseTags(value)).toString();
|
||||
}
|
||||
setterMethod.invoke(datasetWizardModel, mapper.readValue(value, params[0]));
|
||||
}catch (InvocationTargetException | IllegalAccessException | JsonProcessingException e) {
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", prefillingMapping.getMaDmpTarget());
|
||||
String trimRegex = prefillingMapping.getTrimRegex() != null ? prefillingMapping.getTrimRegex() : "";
|
||||
if (!value.startsWith("\"") && !value.startsWith("[") && !value.equals("null")) {
|
||||
value = "\"" + value + "\"";
|
||||
|
@ -106,6 +90,25 @@ public class PrefillingMapper {
|
|||
parsedValue = String.join(", ", values);
|
||||
}
|
||||
|
||||
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();
|
||||
//GK: Tags Special logic
|
||||
if (parsedValue != null && !parsedValue.equals("null") && prefillingMapping.getTarget().equals("tags")) {
|
||||
parsedValue = mapper.valueToTree(parseTags(parsedValue)).toString();
|
||||
} else {
|
||||
parsedValue = mapper.valueToTree(parsedValue).toString();
|
||||
}
|
||||
setterMethod.invoke(datasetWizardModel, mapper.readValue(parsedValue, params[0]));
|
||||
}catch (InvocationTargetException | IllegalAccessException | JsonProcessingException e) {
|
||||
throw e;
|
||||
}
|
||||
} 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")){
|
||||
|
@ -146,7 +149,7 @@ public class PrefillingMapper {
|
|||
properties.put(id, parseComboBoxValues(node, parsedValues));
|
||||
break;
|
||||
case TAGS:
|
||||
properties.put(id, mapper.valueToTree(parseTags(value)).toString());
|
||||
properties.put(id, mapper.valueToTree(parseTags(parsedValue)).toString());
|
||||
break;
|
||||
default:
|
||||
if (!parsedValues.isEmpty())
|
||||
|
@ -202,15 +205,10 @@ public class PrefillingMapper {
|
|||
private static List<Tag> parseTags(String value) throws JsonProcessingException {
|
||||
if (value == null || value.isEmpty())
|
||||
return new LinkedList<>();
|
||||
JsonNode rawTags = mapper.readTree(value);
|
||||
String[] rawTags = value.split(", ");
|
||||
List<Tag> parsedTags = new LinkedList<>();
|
||||
if (rawTags.isArray()) {
|
||||
for (int i = 0; i < rawTags.size(); i++) {
|
||||
parsedTags.add(new Tag(rawTags.get(i).textValue(), rawTags.get(i).textValue()));
|
||||
}
|
||||
} else if (rawTags.isTextual()) {
|
||||
List<String> tags = Arrays.asList(rawTags.textValue().split(", "));
|
||||
parsedTags.addAll(tags.stream().map(s -> new Tag(s, s)).collect(Collectors.toList()));
|
||||
for (String rawTag : rawTags) {
|
||||
parsedTags.add(new Tag(rawTag, rawTag));
|
||||
}
|
||||
return parsedTags;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue