WordBuilder.java: #7869 - In exported file fix hidden question title and a. /b. /c for empty answers.

a. fix hidden question title when more than 1 multiplicity answers,
b. fix hidden question title when  no value in the last multiplicity answer,
c. Do not show a. / b. / c.... for empty multiplicity answers,
d. Do not show a. / b. / c.... when more than 1 multiplicity answers, but only one with value.
This commit is contained in:
Konstantina Galouni 2022-06-23 15:32:05 +03:00
parent b1788c2dc2
commit 18e98938d5
1 changed files with 32 additions and 4 deletions

View File

@ -285,33 +285,59 @@ public class WordBuilder {
for (FieldSet compositeField: compositeFields) {
if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) {
char c = 'a';
int multiplicityItems = 0;
boolean hasMultiplicityItems = false;
int paragraphPos = -1;
int paragraphPosInner = -1;
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
XWPFParagraph paragraph = addParagraphContent("\t" + page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
if(compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()){
addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
// addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId);
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
hasMultiplicityItems = true;
multiplicityItems++;
}
}
hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
if(hasValue){
returnedValue = true;
} else if(paragraphPosInner > -1){
mainDocumentPart.removeBodyElement(paragraphPosInner);
c--;
multiplicityItems--;
}
if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) {
List<FieldSet> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList());
for (FieldSet multiplicityFieldset : list) {
paragraphPosInner = -1;
if(!createListing){
c++;
addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
// addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId);
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
hasMultiplicityItems = true;
multiplicityItems++;
}
hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
if(hasValue){
// hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
boolean hasValueInner = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
// if(hasValue){
if(hasValueInner){
hasValue = true;
returnedValue = true;
} else if(paragraphPosInner > -1){
mainDocumentPart.removeBodyElement(paragraphPosInner);
c--;
multiplicityItems--;
}
}
if(multiplicityItems == 1) {
String text = mainDocumentPart.getLastParagraph().getRuns().get(0).getText(0);
if(text.equals("a. ")) {
mainDocumentPart.getLastParagraph().removeRun(0);
}
}
}
@ -422,6 +448,7 @@ public class WordBuilder {
if(hasMultiplicityItems && format != null){
mainDocumentPart.getLastParagraph().createRun().setText(format);
hasMultiplicityItems = false;
hasValue = true;
}
else{
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
@ -461,6 +488,7 @@ public class WordBuilder {
}
public XWPFParagraph addParagraphContent(Object content, XWPFDocument mainDocumentPart, ParagraphStyle style, BigInteger numId) {
// this.indent = 0;
if (content != null) {
if (content instanceof String && ((String)content).isEmpty()) {
return null;