From 524cededb631ddf91663ced8db1212a819abc0b5 Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Wed, 6 Oct 2021 18:16:39 +0300 Subject: [PATCH] Fix issue when exporting to docx/pdf --- .../managers/DataManagementPlanManager.java | 10 +++++-- .../forms/VisibilityRuleServiceImpl.java | 26 ++++++++++++++----- .../utilities/documents/word/WordBuilder.java | 12 +++++---- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index 27af3fdd8..10f9cdb4d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -1181,8 +1181,14 @@ public class DataManagementPlanManager { .forEach(datasetEntity -> { Map properties = new HashMap<>(); if (datasetEntity.getProperties() != null) { - JSONObject jObject = new JSONObject(datasetEntity.getProperties()); - properties = jObject.toMap(); + ObjectMapper objectMapper = new ObjectMapper(); + try { + properties = objectMapper.readValue(datasetEntity.getProperties(), LinkedHashMap.class); + } catch (IOException e) { + logger.error(e.getLocalizedMessage(), e); + } + /*JSONObject jObject = new JSONObject(datasetEntity.getProperties()); + properties = jObject.toMap();*/ } // Custom style for the Dataset title. diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java index dbd00ed5b..d46e138de 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java @@ -3,9 +3,7 @@ package eu.eudat.logic.services.forms; import eu.eudat.models.data.user.components.commons.Rule; import org.springframework.stereotype.Service; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Created by ikalyvas on 3/5/2018. @@ -23,6 +21,15 @@ public class VisibilityRuleServiceImpl implements VisibilityRuleService { public void setProperties(Map properties) { this.properties = properties; + this.properties.entrySet().stream() + .filter(stringObjectEntry -> stringObjectEntry.getValue() instanceof String && ((String) stringObjectEntry.getValue()).startsWith("[") && ((String) stringObjectEntry.getValue()).endsWith("]")).forEach(stringObjectEntry -> { + stringObjectEntry.setValue(parseArray((String) stringObjectEntry.getValue())); + }); + } + + private List parseArray(String original) { + String parsed = original.replace("[", "").replace("\"", "").replace("]", ""); + return Arrays.asList(parsed.split(",")); } public void buildVisibilityContext(List sources) { @@ -34,12 +41,19 @@ public class VisibilityRuleServiceImpl implements VisibilityRuleService { private void evaluateVisibility(VisibilityRule rule) { List sources = rule.getVisibilityRuleSources(); for(int i = 0; i < sources.size(); i++){ - if (!properties.containsKey(sources.get(i).getVisibilityRuleSourceId()) || !properties.get(sources.get(i).getVisibilityRuleSourceId()).equals(sources.get(i).getVisibilityRuleSourceValue())) { + if (properties.containsKey(sources.get(i).getVisibilityRuleSourceId()) && (isContained(properties.get(sources.get(i).getVisibilityRuleSourceId()), sources.get(i).getVisibilityRuleSourceValue()) || properties.get(sources.get(i).getVisibilityRuleSourceId()).equals(sources.get(i).getVisibilityRuleSourceValue()))) { + this.elementVisibility.put(rule.getVisibilityRuleTargetId(), true); + }else{ this.elementVisibility.put(rule.getVisibilityRuleTargetId(), false); return; - }else{ - this.elementVisibility.put(rule.getVisibilityRuleTargetId(), true); } } } + + private Boolean isContained(Object values, String source) { + if (values instanceof List) { + return ((Collection) values).contains(source); + } + return false; + } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java index abd14e990..b5e6816e0 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java @@ -225,11 +225,13 @@ public class WordBuilder { if (visibilityRuleService.isElementVisible(field.getId())) { if (!createListing) { try { - XWPFParagraph paragraph = addParagraphContent(this.formatter(field), mainDocumentPart, ParagraphStyle.TEXT, numId); - if (paragraph != null) { - CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); - number.setVal(BigInteger.valueOf(indent)); - hasValue = true; + if (field.getValue() != null && !field.getValue().toString().isEmpty()) { + XWPFParagraph paragraph = addParagraphContent(this.formatter(field), mainDocumentPart, ParagraphStyle.TEXT, numId); + if (paragraph != null) { + CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); + number.setVal(BigInteger.valueOf(indent)); + hasValue = true; + } } } catch (IOException e) { logger.error(e.getMessage(), e);