From dcf88479bdb2eed7c75372fc8b7535bd6cff18ef Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Mon, 14 Jun 2021 14:21:27 +0300 Subject: [PATCH] Allow to store and retrieve combobox multivalues with commas --- .../user/components/datasetprofile/Field.java | 22 +++++++++++++++++++ .../form-field/form-field.component.ts | 8 ++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java index bffd8d702..10576100b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java @@ -17,6 +17,7 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -239,6 +240,18 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin } catch (JsonProcessingException e) { logger.error(e.getMessage(), e); } + } else if (this.value instanceof Collection) { + Collection valueCollection = (Collection) this.value; + StringBuilder valueBuilder = new StringBuilder(); + valueBuilder.append("["); + for (int i = 0; i < valueCollection.size(); i++) { + valueBuilder.append(parseString(valueCollection.stream().toArray()[i])); + if (i < valueCollection.size() - 1) { + valueBuilder.append(", "); + } + } + valueBuilder.append("]"); + fieldValues.put(this.id, valueBuilder.toString()); } else { fieldValues.put(this.id, this.value.toString()); } @@ -251,4 +264,13 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin public void toMap(Map fieldValues, int index) { fieldValues.put(this.id, this.value); } + + private String parseString(Object value) { + if (value instanceof String) { + if (((String)value).contains(",")) { + return "\"" + value + "\""; + } + } + return value.toString(); + } } \ No newline at end of file diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts index a76cfcae8..1e6c9a79e 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts @@ -106,7 +106,9 @@ export class FormFieldComponent extends BaseComponent implements OnInit { if (this.form.get('data').value.multiList) { const originalValue = this.form.get('value').value; if (originalValue !== null && typeof originalValue === 'string') { - let values = (this.form.get('value').value).slice(1, -1).split(', '); + let values = (this.form.get('value').value).slice(1, -1).split(', ').filter((value) => !value.includes('"')); + let specialValue = (this.form.get('value').value).split('"').filter((value) => !value.startsWith('[') && !value.endsWith(']') && !values.includes(value)); + specialValue.forEach(value => values.push(value)); if (!originalValue.startsWith('[') && !originalValue.endsWith(']')) { values = undefined; values = [originalValue]; @@ -385,8 +387,8 @@ export class FormFieldComponent extends BaseComponent implements OnInit { parseTags() { try{ - - + + let stringValue = this.form.get('value').value; if (typeof stringValue === 'string') { stringValue = (stringValue).replace(new RegExp('{', 'g'), '{"').replace(new RegExp('=', 'g'), '":"').replace(new RegExp(',', 'g'), '",').replace(new RegExp(', ', 'g'), ', "').replace(new RegExp('}', 'g'), '"}');