From 563711eae4652e6fb8215a05acce95b8529097b3 Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Tue, 15 Mar 2022 17:52:58 +0200 Subject: [PATCH] Fix issue saving tags from template when the field is a textField --- .../main/java/eu/eudat/logic/managers/DatasetManager.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index 7fd4ebea5..ffd26bb69 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -1058,13 +1058,19 @@ public class DatasetManager { if (!tagNodes.isEmpty()) { tagNodes.forEach(node -> { JsonNode value = node.get("value"); - if (!value.toString().equals("\"\"") && !value.toString().equals("null")) { + if (!value.toString().equals("\"\"") && !value.toString().equals("null") && value.toString().startsWith("[")) { String stringValue = value.toString().replaceAll("=", ":"); JSONArray values = new JSONArray(stringValue); values.iterator().forEachRemaining(element -> { Map data = ((JSONObject) element).toMap(); this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString()); }); + } else { + List values = Arrays.asList(value.textValue().split(", ")); + List tagValues = values.stream().map(stringValue -> new Tag(stringValue, stringValue)).collect(Collectors.toList()); + tagValues.iterator().forEachRemaining(tag -> { + this.addTag(tags, wizardModel.getTags(), tag.getId(), tag.getName()); + }); } }); }