Ficxed Issues with Document Generation

This commit is contained in:
Ioannis Kalyvas 2018-10-22 13:34:39 +03:00
parent 38d356703a
commit 889a2ae262
3 changed files with 16 additions and 42 deletions

View File

@ -1,38 +0,0 @@
package eu.eudat.document;
import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlCursor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* Created by ikalyvas on 10/17/2018.
*/
public class DocxDocumentBuilderAdapter extends XWPFDocument {
public DocxDocumentBuilderAdapter(OPCPackage pkg) throws IOException {
super(pkg);
}
public DocxDocumentBuilderAdapter(InputStream is) throws IOException {
super(is);
}
public DocxDocumentBuilderAdapter() {
}
@Override
public void createTOC() {
super.createTOC();
}
}

View File

@ -10,7 +10,6 @@ import eu.eudat.data.dao.entities.*;
import eu.eudat.data.entities.*;
import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
import eu.eudat.document.DocxDocumentBuilderAdapter;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsException;
import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.logic.builders.entity.UserInfoBuilder;
@ -91,18 +90,18 @@ public class DataManagementPlanManager {
DatasetWizardModel dataset = new DatasetWizardModel();
String fileUrl = environment.getProperty("configuration.h2020template");
InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
DocxDocumentBuilderAdapter document = new DocxDocumentBuilderAdapter(is);
XWPFDocument document = new XWPFDocument(is);
eu.eudat.data.entities.DMP dmpEntity = dmpRepository.find(UUID.fromString(id));
wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.TITLE, BigInteger.ZERO);
wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
wordBuilder.addParagraphContent("Organisations", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(x-> x.getLabel()).collect(Collectors.joining(","))
wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(x -> x.getLabel()).collect(Collectors.joining(","))
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
wordBuilder.addParagraphContent("Researchers", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
wordBuilder.addParagraphContent(dmpEntity.getResearchers().stream().map(x-> x.getLabel()).collect(Collectors.joining(","))
wordBuilder.addParagraphContent(dmpEntity.getResearchers().stream().map(x -> x.getLabel()).collect(Collectors.joining(","))
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
wordBuilder.addParagraphContent("Datasets", document, ParagraphStyle.TITLE, BigInteger.ZERO);

View File

@ -91,6 +91,13 @@ public class WordBuilder {
run.setText(item);
return paragraph;
});
this.options.put(ParagraphStyle.COMMENT, (mainDocumentPart, item) -> {
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText(item);
run.setItalic(true);
return paragraph;
});
}
public XWPFDocument build(XWPFDocument document, PagedDatasetProfile pagedDatasetProfile, VisibilityRuleService visibilityRuleService) throws IOException {
@ -134,6 +141,11 @@ public class WordBuilder {
number.setVal(BigInteger.valueOf(indent));
}
createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService);
if (compositeField.getHasCommentField() && !createListing) {
XWPFParagraph paragraph = addParagraphContent("Comment: " + compositeField.getCommentFieldValue(), mainDocumentPart, ParagraphStyle.COMMENT, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
}
}
});
}
@ -213,6 +225,7 @@ public class WordBuilder {
return field.getValue();
case "checkBox":
CheckBoxData data = (CheckBoxData) field.getData();
if (field.getValue() == null || field.getValue().equals("false")) return null;
return data.getLabel();
case "freetext":
return field.getValue();