Various improvements on DMP document export. (Issue #71)

This commit is contained in:
gkolokythas 2019-05-22 11:53:30 +03:00
parent 496b0bcf4e
commit 7844c33b7c
2 changed files with 48 additions and 6 deletions

View File

@ -38,7 +38,10 @@ import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.models.data.userinfo.UserListingModel;
import eu.eudat.queryable.QueryableList;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
@ -169,7 +172,24 @@ public class DataManagementPlanManager {
XWPFDocument document = new XWPFDocument(is);
eu.eudat.data.entities.DMP dmpEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.TITLE, BigInteger.ZERO);
// Space above DMP title.
XWPFParagraph parAboveDmpTitle = document.createParagraph();
XWPFParagraph parAboveDmpTitle1 = document.createParagraph();
XWPFParagraph parAboveDmpTitle2 = document.createParagraph();
XWPFParagraph parAboveDmpTitle3 = document.createParagraph();
// DMP title custom style.
//wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.TITLE, BigInteger.ZERO);
XWPFParagraph dmpLabelParagraph = document.createParagraph();
XWPFRun run = dmpLabelParagraph.createRun();
run.setText(dmpEntity.getLabel());
run.setBold(true);
run.setFontSize(20);
// Space below DMP title.
XWPFParagraph parBelowDmpTitle = document.createParagraph();
wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
wordBuilder.addParagraphContent("Organisations", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
@ -189,6 +209,10 @@ public class DataManagementPlanManager {
wordBuilder.addParagraphContent(dmpEntity.getProfile().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
}*/
// Page break at the end of the DMP title.
XWPFParagraph parBreakDMP = document.createParagraph();
parBreakDMP.setPageBreak(true);
wordBuilder.addParagraphContent("Datasets", document, ParagraphStyle.TITLE, BigInteger.ZERO);
dmpEntity.getDataset().stream().forEach(datasetEntity -> {
Map<String, Object> properties = new HashMap<>();
@ -196,7 +220,22 @@ public class DataManagementPlanManager {
JSONObject jobject = new JSONObject(datasetEntity.getProperties());
properties = jobject.toMap();
}
wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
// Custom style for the Dataset title.
//wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
XWPFParagraph datasetLabelParagraph = document.createParagraph();
XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun();
runDatasetTitle1.setText("Title: ");
runDatasetTitle1.setBold(true);
runDatasetTitle1.setFontSize(12);
XWPFRun runDatasetTitle = datasetLabelParagraph.createRun();
runDatasetTitle.setText(datasetEntity.getLabel());
runDatasetTitle.setColor("2E75B6");
runDatasetTitle.setBold(true);
runDatasetTitle.setFontSize(12);
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity);
@ -207,6 +246,8 @@ public class DataManagementPlanManager {
} catch (IOException e) {
e.printStackTrace();
}
// Page break at the end of the Dataset.
XWPFParagraph parBreakDataset = document.createParagraph();
});
String fileName = dmpEntity.getLabel();
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");

View File

@ -44,7 +44,8 @@ public class WordBuilder {
this.options.put(ParagraphStyle.TEXT, (mainDocumentPart, item) -> {
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText(item);
if (item != null)
run.setText(" " + item);
run.setFontSize(11);
return paragraph;
});
@ -71,7 +72,7 @@ public class WordBuilder {
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
paragraph.setStyle("Heading2");
XWPFRun run = paragraph.createRun();
run.setText(item);
run.setText(" " + item);
run.setBold(true);
run.setFontSize(12);
return paragraph;
@ -80,7 +81,7 @@ public class WordBuilder {
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
paragraph.setStyle("Heading3");
XWPFRun run = paragraph.createRun();
run.setText(item);
run.setText(" " + item);
run.setBold(true);
run.setFontSize(11);
return paragraph;
@ -94,7 +95,7 @@ public class WordBuilder {
this.options.put(ParagraphStyle.COMMENT, (mainDocumentPart, item) -> {
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText(item);
run.setText(" " + item);
run.setItalic(true);
return paragraph;
});