From 67240affcfc99e582c87577d1528f561d60c3a86 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 21 Mar 2024 15:36:48 +0200 Subject: [PATCH] migration changes --- .../migration/DatasetMigrationService.java | 107 +++--------------- ...escriptionTemplateXmlMigrationService.java | 51 ++++++++- .../eudat/migration/DmpMigrationService.java | 40 ++++--- .../old/eudat/migration/MigrationTools.java | 95 ++++++++++++++++ 4 files changed, 182 insertions(+), 111 deletions(-) create mode 100644 dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/MigrationTools.java diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java index 675eaa227..0c4d46f34 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java @@ -15,7 +15,6 @@ import eu.eudat.model.Dmp; import eu.eudat.model.Reference; import eu.eudat.model.ReferenceType; import eu.eudat.query.*; -import eu.eudat.service.reference.ReferenceService; import eu.old.eudat.data.dao.entities.DatasetDao; import eu.old.eudat.data.entities.Dataset; import eu.old.eudat.logic.services.operations.DatabaseRepository; @@ -25,7 +24,6 @@ import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.logging.LoggerService; import jakarta.persistence.EntityManager; import jakarta.xml.bind.JAXBException; -import org.apache.commons.lang3.StringEscapeUtils; import org.json.JSONObject; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -54,16 +52,16 @@ public class DatasetMigrationService { private static final boolean TestMode = false; private final EntityManager entityManager; private final ConventionService conventionService; - private final ReferenceService referenceService; + private final MigrationTools migrationTools; - public DatasetMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, QueryFactory queryFactory, XmlHandlingService xmlHandlingService, EntityManager entityManager, ConventionService conventionService, ReferenceService referenceService) { + public DatasetMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, QueryFactory queryFactory, XmlHandlingService xmlHandlingService, EntityManager entityManager, ConventionService conventionService, MigrationTools migrationTools) { this.databaseRepository = databaseRepository; this.jsonHandlingService = jsonHandlingService; this.queryFactory = queryFactory; this.xmlHandlingService = xmlHandlingService; this.entityManager = entityManager; this.conventionService = conventionService; - this.referenceService = referenceService; + this.migrationTools = migrationTools; } public void migrate() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException { @@ -387,20 +385,20 @@ public class DatasetMigrationService { } case SELECT -> { if(!this.conventionService.isNullOrEmpty(textValue)) { - String[] valuesParsed = this.tryParseJsonAsObjectString(String[].class, textValue); + String[] valuesParsed = migrationTools.tryParseJsonAsObjectString(String[].class, textValue); fieldEntity.setTextListValue(valuesParsed == null ? List.of(textValue) : Arrays.stream(valuesParsed).toList()); } } case DATASET_IDENTIFIER, VALIDATION -> { if(!this.conventionService.isNullOrEmpty(textValue)) { - ExternalIdentifierEntity externalIdentifierEntity = this.tryParseJsonAsObjectString(ExternalIdentifierEntity.class, textValue); + ExternalIdentifierEntity externalIdentifierEntity = migrationTools.tryParseJsonAsObjectString(ExternalIdentifierEntity.class, textValue); if (externalIdentifierEntity == null) throw new MyApplicationException("Could not parse dataset External Identifier : " + textValue); fieldEntity.setExternalIdentifier(externalIdentifierEntity); } } case UPLOAD -> { if(!this.conventionService.isNullOrEmpty(textValue)) { - Map valuesParsed = this.tryParseJsonAsObjectString(Map.class, textValue); + Map valuesParsed = migrationTools.tryParseJsonAsObjectString(Map.class, textValue); if (valuesParsed == null) { valuesParsed = (Map) properties.get(currentField.getId()); } @@ -412,7 +410,7 @@ public class DatasetMigrationService { } case CURRENCY -> { if(!this.conventionService.isNullOrEmpty(textValue)) { - Currency currency = this.tryParseJsonAsObjectString(Currency.class, textValue); + Currency currency = migrationTools.tryParseJsonAsObjectString(Currency.class, textValue); if (currency == null && textValue.toUpperCase(Locale.ROOT).contains("EUR")) { currency = new Currency(); currency.setName("Euro"); @@ -431,12 +429,12 @@ public class DatasetMigrationService { } case TAGS -> { if(!this.conventionService.isNullOrEmpty(textValue)) { - Tag[] tags = this.tryParseJsonAsObjectString(Tag[].class, textValue); + Tag[] tags = migrationTools.tryParseJsonAsObjectString(Tag[].class, textValue); if (tags == null) { - Tag tag = this.tryParseJsonAsObjectString(Tag.class, textValue); + Tag tag = migrationTools.tryParseJsonAsObjectString(Tag.class, textValue); if (tag != null) tags = List.of(tag).toArray(Tag[]::new); } - if (tags == null) tags = this.jsonHandlingService.fromJsonSafe(Tag[].class, this.cleanTagString(textValue)); + if (tags == null) tags = this.jsonHandlingService.fromJsonSafe(Tag[].class, migrationTools.cleanTagString(textValue)); if (tags == null) throw new MyApplicationException("Could not parse tag : " + textValue); fieldEntity.setTextListValue(Arrays.stream(tags).toList().stream().map(Tag::getName).toList()); } @@ -446,13 +444,13 @@ public class DatasetMigrationService { case INTERNAL_ENTRIES_DESCRIPTIONS -> throw new MyApplicationException("Found INTERNAL_ENTRIES_DMPS into description"); case REFERENCE_TYPES -> { if(!this.conventionService.isNullOrEmpty(textValue)) { //TODO - Map[] references = this.tryParseJsonAsObjectString(Map[].class, textValue); + Map[] references = migrationTools.tryParseJsonAsObjectString(Map[].class, textValue); ReferenceTypeDataEntity referenceTypeDataEntity = (ReferenceTypeDataEntity)currentField.getData(); if (referenceTypeDataEntity == null) throw new MyApplicationException("Could not parse description template reference : " + textValue); if (references == null) { - Map reference = this.tryParseJsonAsObjectString(Map.class, textValue); + Map reference = migrationTools.tryParseJsonAsObjectString(Map.class, textValue); if (reference != null) references = List.of(reference).toArray(Map[]::new); } if (references == null && !textValue.contains("{") && !textValue.contains("[") ) { @@ -506,7 +504,7 @@ public class DatasetMigrationService { source = referenceTypeDefinition.getSources().getFirst().getKey(); String[] parts = null; if (textValue.startsWith("[\"")){ - parts = this.tryParseJsonAsObjectString(String[].class, textValue); + parts = migrationTools.tryParseJsonAsObjectString(String[].class, textValue); } else{ if (textValue.startsWith("[")) textValue = textValue.substring(1).trim(); if (textValue.endsWith("]")) textValue = textValue.substring(0, textValue.length() -1).trim(); @@ -564,7 +562,7 @@ public class DatasetMigrationService { if (textValue.equals("[\"-\"]")){ break; } else if (textValue.startsWith("[\"") && !textValue.startsWith("[\"{") && textValue.contains(",")){ - references = this.tryParseJsonAsObjectString(Map[].class, textValue.replace(textValue.substring(1, textValue.indexOf(",") + 1), "")); + references = migrationTools.tryParseJsonAsObjectString(Map[].class, textValue.replace(textValue.substring(1, textValue.indexOf(",") + 1), "")); } else if (textValue.contains(",") && !textValue.contains("{") && !textValue.contains("[") ){ String[] parts = textValue.split(","); @@ -601,7 +599,7 @@ public class DatasetMigrationService { } else if (!textValue.contains("{")) { String[] parts = null; if (textValue.startsWith("[\"")){ - parts = this.tryParseJsonAsObjectString(String[].class, textValue); + parts = migrationTools.tryParseJsonAsObjectString(String[].class, textValue); } else{ if (textValue.startsWith("[")) textValue = textValue.substring(1).trim(); if (textValue.endsWith("]")) textValue = textValue.substring(0, textValue.length() -1).trim(); @@ -985,81 +983,6 @@ public class DatasetMigrationService { } - private T tryParseJsonAsObjectString(Class type, String value){ - T item = this.jsonHandlingService.fromJsonSafe(type, value); - if (item == null) item = this.jsonHandlingService.fromJsonSafe(type, StringEscapeUtils.unescapeJava(value)); - if (item == null) item = this.jsonHandlingService.fromJsonSafe(type, StringEscapeUtils.unescapeJson(value)); - if (item == null) { - String newValue = StringEscapeUtils.unescapeJava(value); - newValue = newValue.trim().replace("[\"{", "[{"); - newValue = newValue.trim().replace("}\"]", "}]"); - newValue = newValue.trim().replace("}\", \"{", "}, {"); - newValue = newValue.trim().replace("}\",\"{", "},{"); - newValue = newValue.trim().replace(", \"{", ", {"); - newValue = newValue.trim().replace(",\"{", ",{"); - newValue = newValue.trim().replace("}\",", "},"); - - while (!this.conventionService.isNullOrEmpty(newValue) && newValue.startsWith("\"")) newValue = newValue.substring(1); - while (!this.conventionService.isNullOrEmpty(newValue) && newValue.endsWith("\"")) newValue = newValue.substring(0, newValue.length() - 1); - item = this.jsonHandlingService.fromJsonSafe(type, newValue); - } - if (item == null) { - String newValue = StringEscapeUtils.unescapeJson(value); - newValue = newValue.trim().replace("[\"{", "[{"); - newValue = newValue.trim().replace("}\"]", "}]"); - newValue = newValue.trim().replace("}\", \"{", "}, {"); - newValue = newValue.trim().replace("}\",\"{", "},{"); - newValue = newValue.trim().replace(", \"{", ", {"); - newValue = newValue.trim().replace(",\"{", ",{"); - newValue = newValue.trim().replace("}\",", "},"); - - while (!this.conventionService.isNullOrEmpty(newValue) && newValue.startsWith("\"")) newValue = newValue.substring(1); - while (!this.conventionService.isNullOrEmpty(newValue) && newValue.endsWith("\"")) newValue = newValue.substring(0, newValue.length() - 1); - item = this.jsonHandlingService.fromJsonSafe(type, newValue); - } - if (item == null) { - String newValue = value.trim().replace("\\", ""); - newValue = newValue.trim().replace("[\"{", "[{"); - newValue = newValue.trim().replace("}\"]", "}]"); - newValue = newValue.trim().replace("}\", \"{", "}, {"); - newValue = newValue.trim().replace("}\",\"{", "},{"); - newValue = newValue.trim().replace(", \"{", ", {"); - newValue = newValue.trim().replace(",\"{", ",{"); - newValue = newValue.trim().replace("}\",", "},"); - - while (!this.conventionService.isNullOrEmpty(newValue) && newValue.startsWith("\"")) newValue = newValue.substring(1); - while (!this.conventionService.isNullOrEmpty(newValue) && newValue.endsWith("\"")) newValue = newValue.substring(0, newValue.length() - 1); - item = this.jsonHandlingService.fromJsonSafe(type, newValue); - } - if (item == null) { - String newValue = value.trim().replace("=", ":"); - newValue = newValue.trim().replace("{", "{\""); - newValue = newValue.trim().replace("}", "\"}"); - newValue = newValue.trim().replace(":", "\":\""); - newValue = newValue.trim().replace(", ", "\", \""); - newValue = newValue.trim().replace("}\", \"{", "}, {"); - newValue = newValue.trim().replace("\"\"", "\""); - newValue = newValue.trim().replace(":\"null,", ":null,"); - newValue = newValue.trim().replace(":\"null\",", ":null,"); - newValue = newValue.trim().replace(":\"null\"", ":null"); - newValue = newValue.trim().replace(":\"null}\"", ":null}"); - newValue = newValue.trim().replace("https\":\"", "https:"); - newValue = newValue.trim().replace("datarepo\":\"", "datarepo:"); - - item = this.jsonHandlingService.fromJsonSafe(type, newValue); - } - return item; - } - - private String cleanTagString(String value){ - value = value.trim().replace("=", ":"); - value = value.trim().replace("{", "{\""); - value = value.trim().replace("}", "\"}"); - value = value.trim().replace(":", "\":\""); - value = value.trim().replace(", ", "\", \""); - value = value.trim().replace("}\", \"{", "}, {"); - return value; - } public static class Currency{ private String name; diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java index c8bac8079..693d8d88d 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java @@ -34,12 +34,16 @@ import org.w3c.dom.Document; import org.xml.sax.SAXException; import javax.management.InvalidApplicationException; +import javax.ws.rs.NotSupportedException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneOffset; +import java.time.format.DateTimeParseException; import java.util.*; import java.util.stream.Collectors; @@ -51,15 +55,17 @@ public class DescriptionTemplateXmlMigrationService { private final ConventionService conventionService; private final XmlHandlingService xmlHandlingService; private final QueryFactory queryFactory; + private final MigrationTools migrationTools; private static final int PageSize = 500; private static final boolean TestMode = false; - public DescriptionTemplateXmlMigrationService(EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, QueryFactory queryFactory) { + public DescriptionTemplateXmlMigrationService(EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, QueryFactory queryFactory, MigrationTools migrationTools) { this.entityManager = entityManager; this.conventionService = conventionService; this.xmlHandlingService = xmlHandlingService; this.queryFactory = queryFactory; + this.migrationTools = migrationTools; } public void migrate() throws IOException, NoSuchFieldException, IllegalAccessException, JAXBException, ParserConfigurationException, InstantiationException, SAXException, InvalidApplicationException, TransformerException, URISyntaxException { @@ -223,7 +229,7 @@ public class DescriptionTemplateXmlMigrationService { if (persist.getVisible() != null && !this.conventionService.isListNullOrEmpty(persist.getVisible().getRules())) { data.setVisibilityRules(new ArrayList<>()); for (Rule fieldPersist : persist.getVisible().getRules()) { - data.getVisibilityRules().add(this.buildRuleEntity(fieldPersist)); + data.getVisibilityRules().add(this.buildRuleEntity(fieldPersist, data.getData().getFieldType())); } } return data; @@ -392,13 +398,50 @@ public class DescriptionTemplateXmlMigrationService { } - private @NotNull RuleEntity buildRuleEntity(Rule persist) { + private @NotNull RuleEntity buildRuleEntity(Rule persist, FieldType fieldType) { RuleEntity data = new RuleEntity(); if (persist == null) return data; + String textValue = persist.getValue(); + if (textValue == null || textValue.isEmpty()) return data; data.setTarget(persist.getTarget()); - data.setValue(persist.getValue()); + switch (fieldType){ + case FREE_TEXT, TEXT_AREA, RICH_TEXT_AREA, RADIO_BOX -> data.setTextValue(textValue.trim()); + case CHECK_BOX, BOOLEAN_DECISION -> data.setTextValue(textValue.trim().toLowerCase(Locale.ROOT)); + case DATE_PICKER -> { + Instant instant = null; + if(!this.conventionService.isNullOrEmpty(textValue)) { + try { + instant = Instant.parse(textValue); + } catch (DateTimeParseException ex) { + instant = LocalDate.parse(textValue).atStartOfDay().toInstant(ZoneOffset.UTC); + } + } + data.setDateValue(instant); + } + case SELECT -> { + if(!this.conventionService.isNullOrEmpty(textValue)) { + String[] valuesParsed = migrationTools.tryParseJsonAsObjectString(String[].class, textValue); + data.setTextListValue(valuesParsed == null ? List.of(textValue) : Arrays.stream(valuesParsed).toList()); + } + } + case DATASET_IDENTIFIER, VALIDATION -> { + if(!this.conventionService.isNullOrEmpty(textValue)) { + eu.eudat.commons.types.descriptiontemplate.ExternalIdentifierEntity externalIdentifierEntity = migrationTools.tryParseJsonAsObjectString(eu.eudat.commons.types.descriptiontemplate.ExternalIdentifierEntity.class, textValue); + if (externalIdentifierEntity == null) throw new MyApplicationException("Could not parse dataset External Identifier : " + textValue); + data.setExternalIdentifier(externalIdentifierEntity); + } + } + case UPLOAD -> throw new NotSupportedException("Upload validator not supported"); + case CURRENCY -> throw new NotSupportedException("Currency validator not supported"); + case TAGS -> throw new NotSupportedException("Tags validator not supported"); + + case INTERNAL_ENTRIES_DMPS -> throw new NotSupportedException("INTERNAL_ENTRIES_DMPS validator not supported"); + case INTERNAL_ENTRIES_DESCRIPTIONS -> throw new NotSupportedException("INTERNAL_ENTRIES_DESCRIPTIONS validator not supported"); + case REFERENCE_TYPES -> throw new NotSupportedException("REFERENCE_TYPES validator not supported"); + default -> throw new MyApplicationException("unrecognized type " + fieldType); + } return data; } private @NotNull MultiplicityEntity buildMultiplicityEntity(Multiplicity persist) { diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpMigrationService.java index 7245ce39b..0ea6c1b24 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpMigrationService.java @@ -100,7 +100,7 @@ public class DmpMigrationService { DataManagementPlan model = new DataManagementPlan(); model.fromDataModel(item); List itemGroupDmps = groupDmpMap.get(item.getGroupId()); - DMP currentVersionDmp = itemGroupDmps.stream().max(Comparator.comparing(DMP::getVersion)).orElseThrow(); + DMP currentVersionDmp = itemGroupDmps.stream().filter(x-> DmpStatus.Finalized.getValue().equals(x.getStatus())).max(Comparator.comparing(DMP::getVersion)).orElse(null); DmpPropertiesEntity dmpProperties = new DmpPropertiesEntity(); dmpProperties.setDmpBlueprintValues(new ArrayList<>()); @@ -124,7 +124,16 @@ public class DmpMigrationService { } data.setGroupId(model.getGroupId()); data.setVersion((short) model.getVersion()); - data.setVersionStatus(currentVersionDmp.getId().equals(item.getId()) ? DmpVersionStatus.Current: DmpVersionStatus.Previous); + if (currentVersionDmp != null && currentVersionDmp.getId().equals(item.getId())){ + data.setVersionStatus(DmpVersionStatus.Current); + } else { + if (DmpStatus.Finalized.getValue().equals(item.getStatus())){ + if (currentVersionDmp == null) throw new MyApplicationException("Found Finalized Dmp out of the group "); + data.setVersionStatus(DmpVersionStatus.Previous); + } else { + data.setVersionStatus(DmpVersionStatus.NotFinalized); + } + } if (model.getCreated() != null) data.setCreatedAt(model.getCreated().toInstant()); if (model.getModified() != null) @@ -170,24 +179,25 @@ public class DmpMigrationService { } if (data.getCreatorId() == null){ throw new MyApplicationException("Migration skipped creator not found " + item.getId()); - } else { - boolean shouldCreateOwner = item.getUsers() == null || item.getUsers().stream().noneMatch(x-> x.getUser() != null && data.getCreatorId().equals(x.getUser().getId()) && DmpUserRole.Owner.getValue().equals(x.getRole().shortValue())); - if (shouldCreateOwner) { - DmpUserEntity dmpUserEntity = new DmpUserEntity(); - dmpUserEntity.setId(item.getId()); - dmpUserEntity.setDmpId(item.getId()); - dmpUserEntity.setUserId(data.getCreatorId()); - dmpUserEntity.setRole(DmpUserRole.Owner); - dmpUserEntity.setCreatedAt(data.getCreatedAt()); - dmpUserEntity.setUpdatedAt(data.getCreatedAt()); - dmpUserEntity.setIsActive(IsActive.Active); - this.entityManager.persist(dmpUserEntity); - } } this.entityManager.persist(data); this.entityManager.flush(); + boolean shouldCreateOwner = item.getUsers() == null || item.getUsers().stream().noneMatch(x-> x.getUser() != null && data.getCreatorId().equals(x.getUser().getId()) && DmpUserRole.Owner.getValue().equals(x.getRole().shortValue())); + if (shouldCreateOwner) { + DmpUserEntity dmpUserEntity = new DmpUserEntity(); + dmpUserEntity.setId(UUID.randomUUID()); + dmpUserEntity.setDmpId(data.getId()); + dmpUserEntity.setUserId(data.getCreatorId()); + dmpUserEntity.setRole(DmpUserRole.Owner); + dmpUserEntity.setCreatedAt(data.getCreatedAt()); + dmpUserEntity.setUpdatedAt(data.getCreatedAt()); + dmpUserEntity.setIsActive(IsActive.Active); + this.entityManager.persist(dmpUserEntity); + this.entityManager.flush(); + } + licenseIdByName = this.migrateLicense(item, model, licenseIdByName, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null)); this.migrateOrganizations(item, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null)); this.migrateResearchers(item, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null)); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/MigrationTools.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/MigrationTools.java new file mode 100644 index 000000000..0aaa78428 --- /dev/null +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/MigrationTools.java @@ -0,0 +1,95 @@ +package eu.old.eudat.migration; + +import eu.eudat.commons.JsonHandlingService; +import eu.eudat.convention.ConventionService; +import org.apache.commons.lang3.StringEscapeUtils; +import org.springframework.stereotype.Service; + +@Service +public class MigrationTools { + + private final JsonHandlingService jsonHandlingService; + + private final ConventionService conventionService; + + public MigrationTools(JsonHandlingService jsonHandlingService, ConventionService conventionService) { + this.jsonHandlingService = jsonHandlingService; + this.conventionService = conventionService; + } + + public T tryParseJsonAsObjectString(Class type, String value){ + T item = this.jsonHandlingService.fromJsonSafe(type, value); + if (item == null) item = this.jsonHandlingService.fromJsonSafe(type, StringEscapeUtils.unescapeJava(value)); + if (item == null) item = this.jsonHandlingService.fromJsonSafe(type, StringEscapeUtils.unescapeJson(value)); + if (item == null) { + String newValue = StringEscapeUtils.unescapeJava(value); + newValue = newValue.trim().replace("[\"{", "[{"); + newValue = newValue.trim().replace("}\"]", "}]"); + newValue = newValue.trim().replace("}\", \"{", "}, {"); + newValue = newValue.trim().replace("}\",\"{", "},{"); + newValue = newValue.trim().replace(", \"{", ", {"); + newValue = newValue.trim().replace(",\"{", ",{"); + newValue = newValue.trim().replace("}\",", "},"); + + while (!this.conventionService.isNullOrEmpty(newValue) && newValue.startsWith("\"")) newValue = newValue.substring(1); + while (!this.conventionService.isNullOrEmpty(newValue) && newValue.endsWith("\"")) newValue = newValue.substring(0, newValue.length() - 1); + item = this.jsonHandlingService.fromJsonSafe(type, newValue); + } + if (item == null) { + String newValue = StringEscapeUtils.unescapeJson(value); + newValue = newValue.trim().replace("[\"{", "[{"); + newValue = newValue.trim().replace("}\"]", "}]"); + newValue = newValue.trim().replace("}\", \"{", "}, {"); + newValue = newValue.trim().replace("}\",\"{", "},{"); + newValue = newValue.trim().replace(", \"{", ", {"); + newValue = newValue.trim().replace(",\"{", ",{"); + newValue = newValue.trim().replace("}\",", "},"); + + while (!this.conventionService.isNullOrEmpty(newValue) && newValue.startsWith("\"")) newValue = newValue.substring(1); + while (!this.conventionService.isNullOrEmpty(newValue) && newValue.endsWith("\"")) newValue = newValue.substring(0, newValue.length() - 1); + item = this.jsonHandlingService.fromJsonSafe(type, newValue); + } + if (item == null) { + String newValue = value.trim().replace("\\", ""); + newValue = newValue.trim().replace("[\"{", "[{"); + newValue = newValue.trim().replace("}\"]", "}]"); + newValue = newValue.trim().replace("}\", \"{", "}, {"); + newValue = newValue.trim().replace("}\",\"{", "},{"); + newValue = newValue.trim().replace(", \"{", ", {"); + newValue = newValue.trim().replace(",\"{", ",{"); + newValue = newValue.trim().replace("}\",", "},"); + + while (!this.conventionService.isNullOrEmpty(newValue) && newValue.startsWith("\"")) newValue = newValue.substring(1); + while (!this.conventionService.isNullOrEmpty(newValue) && newValue.endsWith("\"")) newValue = newValue.substring(0, newValue.length() - 1); + item = this.jsonHandlingService.fromJsonSafe(type, newValue); + } + if (item == null) { + String newValue = value.trim().replace("=", ":"); + newValue = newValue.trim().replace("{", "{\""); + newValue = newValue.trim().replace("}", "\"}"); + newValue = newValue.trim().replace(":", "\":\""); + newValue = newValue.trim().replace(", ", "\", \""); + newValue = newValue.trim().replace("}\", \"{", "}, {"); + newValue = newValue.trim().replace("\"\"", "\""); + newValue = newValue.trim().replace(":\"null,", ":null,"); + newValue = newValue.trim().replace(":\"null\",", ":null,"); + newValue = newValue.trim().replace(":\"null\"", ":null"); + newValue = newValue.trim().replace(":\"null}\"", ":null}"); + newValue = newValue.trim().replace("https\":\"", "https:"); + newValue = newValue.trim().replace("datarepo\":\"", "datarepo:"); + + item = this.jsonHandlingService.fromJsonSafe(type, newValue); + } + return item; + } + + public String cleanTagString(String value){ + value = value.trim().replace("=", ":"); + value = value.trim().replace("{", "{\""); + value = value.trim().replace("}", "\"}"); + value = value.trim().replace(":", "\":\""); + value = value.trim().replace(", ", "\", \""); + value = value.trim().replace("}\", \"{", "}, {"); + return value; + } +}