Fix issue when exporting to docx/pdf

This commit is contained in:
George Kalampokis 2021-10-06 18:16:39 +03:00
parent cb1d7b5340
commit 524cededb6
3 changed files with 35 additions and 13 deletions

View File

@ -1181,8 +1181,14 @@ public class DataManagementPlanManager {
.forEach(datasetEntity -> {
Map<String, Object> 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.

View File

@ -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<String, Object> 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<String> parseArray(String original) {
String parsed = original.replace("[", "").replace("\"", "").replace("]", "");
return Arrays.asList(parsed.split(","));
}
public void buildVisibilityContext(List<Rule> sources) {
@ -34,12 +41,19 @@ public class VisibilityRuleServiceImpl implements VisibilityRuleService {
private void evaluateVisibility(VisibilityRule rule) {
List<VisibilityRuleSource> 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;
}
}

View File

@ -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);