|
|
|
@ -7,7 +7,8 @@ import eu.eudat.models.user.components.datasetprofile.FieldSet;
|
|
|
|
|
import eu.eudat.models.user.components.datasetprofile.Section;
|
|
|
|
|
import eu.eudat.models.user.composite.DatasetProfilePage;
|
|
|
|
|
import eu.eudat.models.user.composite.PagedDatasetProfile;
|
|
|
|
|
import eu.eudat.utilities.interfaces.Applier;
|
|
|
|
|
import eu.eudat.services.forms.VisibilityRuleService;
|
|
|
|
|
import eu.eudat.utilities.interfaces.ApplierWithValue;
|
|
|
|
|
import org.apache.poi.xwpf.usermodel.*;
|
|
|
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
|
|
|
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
|
|
|
|
@ -15,6 +16,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl;
|
|
|
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STNumberFormat;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
@ -27,7 +29,7 @@ import java.util.Map;
|
|
|
|
|
*/
|
|
|
|
|
public class WordBuilder {
|
|
|
|
|
|
|
|
|
|
private Map<ParagraphStyle, Applier<XWPFDocument, String, XWPFParagraph>> options = new HashMap<>();
|
|
|
|
|
private Map<ParagraphStyle, ApplierWithValue<XWPFDocument, String, XWPFParagraph>> options = new HashMap<>();
|
|
|
|
|
private CTAbstractNum cTAbstractNum;
|
|
|
|
|
private BigInteger numId;
|
|
|
|
|
|
|
|
|
@ -87,63 +89,69 @@ public class WordBuilder {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public File build(PagedDatasetProfile pagedDatasetProfile) throws IOException {
|
|
|
|
|
XWPFDocument document = new XWPFDocument();
|
|
|
|
|
|
|
|
|
|
public File build(PagedDatasetProfile pagedDatasetProfile, String label, VisibilityRuleService visibilityRuleService) throws IOException {
|
|
|
|
|
XWPFDocument document = new XWPFDocument(new FileInputStream((WordBuilder.class.getClassLoader().getResource("documents/h2020.docx")).getFile()));
|
|
|
|
|
this.buildOptions();
|
|
|
|
|
createPages(pagedDatasetProfile.getPages(), document, true);
|
|
|
|
|
createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService);
|
|
|
|
|
XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
|
|
|
|
|
XWPFNumbering numbering = document.createNumbering();
|
|
|
|
|
BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
|
|
|
|
|
this.numId = numbering.addNum(abstractNumID);
|
|
|
|
|
createPages(pagedDatasetProfile.getPages(), document, false);
|
|
|
|
|
File exportFile = new File("welcome.docx");
|
|
|
|
|
createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService);
|
|
|
|
|
File exportFile = new File(label);
|
|
|
|
|
FileOutputStream out = new FileOutputStream(exportFile);
|
|
|
|
|
document.write(out);
|
|
|
|
|
out.close();
|
|
|
|
|
return exportFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing) {
|
|
|
|
|
public void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing, VisibilityRuleService visibilityRuleService) {
|
|
|
|
|
//if (createListing) this.addListing(mainDocumentPart, 0, false, true);
|
|
|
|
|
datasetProfilePages.forEach(item -> {
|
|
|
|
|
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.TITLE, 0, createListing);
|
|
|
|
|
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.TITLE, 0, createListing, visibilityRuleService);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void createSections(List<Section> sections, XWPFDocument mainDocumentPart, ParagraphStyle style, Integer indent, Boolean createListing) {
|
|
|
|
|
public void createSections(List<Section> sections, XWPFDocument mainDocumentPart, ParagraphStyle style, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
|
|
|
|
|
if (createListing) this.addListing(mainDocumentPart, indent, false, true);
|
|
|
|
|
BigInteger listing = numId;
|
|
|
|
|
sections.forEach(section -> {
|
|
|
|
|
if (!createListing) {
|
|
|
|
|
XWPFParagraph paragraph = addParagraphContent(section.getTitle(), mainDocumentPart, style, listing);
|
|
|
|
|
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
|
|
|
number.setVal(BigInteger.valueOf(indent));
|
|
|
|
|
if (visibilityRuleService.isElementVisible(section.getId())) {
|
|
|
|
|
if (!createListing) {
|
|
|
|
|
XWPFParagraph paragraph = addParagraphContent(section.getTitle(), mainDocumentPart, style, listing);
|
|
|
|
|
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
|
|
|
number.setVal(BigInteger.valueOf(indent));
|
|
|
|
|
}
|
|
|
|
|
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER2, 1, createListing, visibilityRuleService);
|
|
|
|
|
createCompositeFields(section.getCompositeFields(), mainDocumentPart, 2, createListing, visibilityRuleService);
|
|
|
|
|
}
|
|
|
|
|
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER2, 1, createListing);
|
|
|
|
|
createCompositeFields(section.getCompositeFields(), mainDocumentPart, 2, createListing);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void createCompositeFields(List<FieldSet> compositeFields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing) {
|
|
|
|
|
public void createCompositeFields(List<FieldSet> compositeFields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
|
|
|
|
|
if (createListing) this.addListing(mainDocumentPart, indent, true, true);
|
|
|
|
|
compositeFields.forEach(compositeField -> {
|
|
|
|
|
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
|
|
|
|
|
XWPFParagraph paragraph = addParagraphContent(compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER3, numId);
|
|
|
|
|
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
|
|
|
number.setVal(BigInteger.valueOf(indent));
|
|
|
|
|
if (visibilityRuleService.isElementVisible(compositeField.getId())) {
|
|
|
|
|
|
|
|
|
|
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
|
|
|
|
|
XWPFParagraph paragraph = addParagraphContent(compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER3, numId);
|
|
|
|
|
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
|
|
|
number.setVal(BigInteger.valueOf(indent));
|
|
|
|
|
}
|
|
|
|
|
createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService);
|
|
|
|
|
}
|
|
|
|
|
createFields(compositeField.getFields(), mainDocumentPart, 3, createListing);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void createFields(List<Field> fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing) {
|
|
|
|
|
public void createFields(List<Field> fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
|
|
|
|
|
if (createListing) this.addListing(mainDocumentPart, indent, false, false);
|
|
|
|
|
fields.forEach(field -> {
|
|
|
|
|
if (!createListing) {
|
|
|
|
|
XWPFParagraph paragraph = addParagraphContent(field.getValue(), mainDocumentPart, ParagraphStyle.TEXT, numId);
|
|
|
|
|
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
|
|
|
number.setVal(BigInteger.valueOf(indent));
|
|
|
|
|
if (visibilityRuleService.isElementVisible(field.getId())) {
|
|
|
|
|
if (!createListing) {
|
|
|
|
|
XWPFParagraph paragraph = addParagraphContent(field.getValue() == null ? "" : field.getValue(), mainDocumentPart, ParagraphStyle.TEXT, numId);
|
|
|
|
|
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
|
|
|
number.setVal(BigInteger.valueOf(indent));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -173,13 +181,18 @@ public class WordBuilder {
|
|
|
|
|
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
|
|
|
|
|
cTLvl.addNewLvlText().setVal("Q " + textLevel);
|
|
|
|
|
cTLvl.addNewStart().setVal(BigInteger.valueOf(1));
|
|
|
|
|
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
|
|
|
|
} else if (!question && hasIndication) {
|
|
|
|
|
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
|
|
|
|
|
cTLvl.addNewLvlText().setVal(textLevel);
|
|
|
|
|
cTLvl.addNewStart().setVal(BigInteger.valueOf(1));
|
|
|
|
|
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
|
|
|
|
}
|
|
|
|
|
if (!question && !hasIndication) {
|
|
|
|
|
cTLvl.addNewNumFmt().setVal(STNumberFormat.NONE);
|
|
|
|
|
cTLvl.addNewLvlText().setVal("");
|
|
|
|
|
cTLvl.addNewStart().setVal(BigInteger.valueOf(1));
|
|
|
|
|
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*if (this.numId == null) {
|
|
|
|
|