#7597, #7893, #7895, #7898: Updated DMP template file (h2020.docx) for export | Added Dataset template file (h2020_dataset.docx) for export | Updated indentation on exported docs.

1. h2020.docx, h2020_dataset.docx: Updated DMP template & Added Dataset template.
2. application.properties, application-devel.properties, application-production.properties, application-staging.properties: Added property for dataset template file path configuration.h2020datasettemplate=documents/h2020_dataset.docx
3. ConfigLoader.java: Added method XWPFDocument getDatasetDocument();
4. DefaultConfigLoader.java: Added fiedls and methods for loading Dataset template (h2020_dataset.docx).
5. DataManagementPlanManager.java, DatasetManager.java, , HtmlToWorldBuilder.java, WordBuilder.java: Updated header/footer/first page in exports for DMPs and Datasets  | Updated indentation in exports.
This commit is contained in:
Konstantina Galouni 2022-07-26 17:00:54 +03:00
parent 9b4c7aeb6f
commit a2228a5fb6
12 changed files with 286 additions and 115 deletions

View File

@ -1190,7 +1190,17 @@ public class DataManagementPlanManager {
if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
throw new UnauthorisedException();
wordBuilder.fillFirstPage(dmpEntity, document);
wordBuilder.fillFirstPage(dmpEntity, null, document);
// int powered_pos = document.getParagraphs().size() - 3;
int powered_pos = wordBuilder.findPosOfPoweredBy(document);
XWPFParagraph powered_par = null;
XWPFParagraph argos_img_par = null;
if(powered_pos != -1) {
powered_par = document.getParagraphArray(powered_pos);
argos_img_par = document.getParagraphArray(powered_pos + 1);
}
// // DMP info on top of the document.
// wordBuilder.addParagraphContent("Data Management Plan Information", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
@ -1252,7 +1262,7 @@ public class DataManagementPlanManager {
// Custom style for the Dataset title.
//wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
XWPFParagraph datasetLabelParagraph = document.createParagraph();
datasetLabelParagraph.setStyle("Heading2");
// datasetLabelParagraph.setStyle("Heading2");
datasetLabelParagraph.setSpacingBetween(1.0);
XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun();
runDatasetTitle1.setText("Title: ");
@ -1261,12 +1271,12 @@ public class DataManagementPlanManager {
//runDatasetTitle1.setFontSize(12);
XWPFRun runDatasetTitle = datasetLabelParagraph.createRun();
runDatasetTitle.setText(datasetEntity.getLabel());
//runDatasetTitle.setColor("2E75B6");
runDatasetTitle.setColor("116a78");
//runDatasetTitle.setBold(true);
//runDatasetTitle.setFontSize(12);
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
datasetTemplateParagraph.setStyle("Heading3");
// datasetTemplateParagraph.setStyle("Heading3");
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
runDatasetTemplate1.setText("Template: ");
runDatasetTemplate1.setColor("000000");
@ -1274,7 +1284,7 @@ public class DataManagementPlanManager {
//runDatasetTemplate1.setFontSize(12);
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
//runDatasetTemplate.setColor("2E75B6");
runDatasetTemplate.setColor("116a78");
//runDatasetTemplate.setBold(true);
//runDatasetTemplate.setFontSize(12);
@ -1315,11 +1325,11 @@ public class DataManagementPlanManager {
// }*/
//
//
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0);
// Dataset Description custom style.
XWPFParagraph datasetDescriptionParagraph = document.createParagraph();
datasetDescriptionParagraph.setStyle("Heading3");
datasetDescriptionParagraph.setStyle("Heading4");
datasetDescriptionParagraph.setSpacingBetween(1.5);
XWPFRun datasetDescriptionRun = datasetDescriptionParagraph.createRun();
datasetDescriptionRun.setText("Dataset Description");
@ -1345,7 +1355,20 @@ public class DataManagementPlanManager {
// document.removeBodyElement(0);
// }
wordBuilder.fillFooter(dmpEntity, document);
if(powered_pos != -1) {
document.getLastParagraph().setPageBreak(false);
document.createParagraph();
document.setParagraph(powered_par, document.getParagraphs().size() - 1);
document.createParagraph();
document.setParagraph(argos_img_par, document.getParagraphs().size() - 1);
document.removeBodyElement(powered_pos + 1);
document.removeBodyElement(powered_pos + 1);
}
wordBuilder.fillFooter(dmpEntity, document, false);
String fileName = "DMP_" + dmpEntity.getGrant().getLabel();
if (versioned) {

View File

@ -396,29 +396,45 @@ public class DatasetManager {
return pagedDatasetProfile;
}
private XWPFDocument getWordDocument(ConfigLoader configLoader, eu.eudat.data.entities.Dataset datasetEntity, VisibilityRuleService visibilityRuleService) throws IOException {
private XWPFDocument getWordDocument(ConfigLoader configLoader, eu.eudat.data.entities.Dataset datasetEntity, VisibilityRuleService visibilityRuleService, Principal principal) throws IOException {
WordBuilder wordBuilder = new WordBuilder(this.environment);
DatasetWizardModel dataset = new DatasetWizardModel();
XWPFDocument document = configLoader.getDocument();
XWPFDocument document = configLoader.getDatasetDocument();
wordBuilder.addParagraphContent(datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
eu.eudat.data.entities.DMP dmpEntity = datasetEntity.getDmp();
if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
throw new UnauthorisedException();
wordBuilder.fillFirstPage(dmpEntity, datasetEntity, document);
wordBuilder.fillFooter(dmpEntity, document, true);
int powered_pos = wordBuilder.findPosOfPoweredBy(document);
XWPFParagraph powered_par = null;
XWPFParagraph argos_img_par = null;
if(powered_pos != -1) {
powered_par = document.getParagraphArray(powered_pos);
argos_img_par = document.getParagraphArray(powered_pos + 1);
}
// wordBuilder.addParagraphContent(datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
// Space below Dataset title.
XWPFParagraph parBreakDataset = document.createParagraph();
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
datasetTemplateParagraph.setStyle("Heading2");
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
runDatasetTemplate1.setText("Template: ");
runDatasetTemplate1.setBold(true);
runDatasetTemplate1.setFontSize(12);
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
runDatasetTemplate.setColor("2E75B6");
runDatasetTemplate.setBold(true);
runDatasetTemplate.setFontSize(12);
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
// XWPFParagraph parBreakDataset = document.createParagraph();
//
// XWPFParagraph datasetTemplateParagraph = document.createParagraph();
// datasetTemplateParagraph.setStyle("Heading2");
// XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
// runDatasetTemplate1.setText("Template: ");
// runDatasetTemplate1.setBold(true);
// runDatasetTemplate1.setFontSize(12);
// XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
// runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
// runDatasetTemplate.setColor("2E75B6");
// runDatasetTemplate.setBold(true);
// runDatasetTemplate.setFontSize(12);
//
// wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
/*XWPFParagraph externalReferencesParagraph = document.createParagraph();
externalReferencesParagraph.setStyle("Heading2");
@ -460,7 +476,7 @@ public class DatasetManager {
properties = jObject.toMap();
}
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
// wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity);
visibilityRuleService.setProperties(properties);
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
@ -469,8 +485,20 @@ public class DatasetManager {
// File exportFile = new File(label + ".docx");
// Removes the top empty headings.
for (int i = 0; i < 6; i++) {
document.removeBodyElement(0);
// for (int i = 0; i < 6; i++) {
// document.removeBodyElement(0);
// }
if(powered_pos != -1) {
document.getLastParagraph().setPageBreak(false);
document.createParagraph();
document.setParagraph(powered_par, document.getParagraphs().size() - 1);
document.createParagraph();
document.setParagraph(argos_img_par, document.getParagraphs().size() - 1);
document.removeBodyElement(powered_pos + 1);
document.removeBodyElement(powered_pos + 1);
}
return document;
@ -493,7 +521,7 @@ public class DatasetManager {
properties = jObject.toMap();
}
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO, 0);
visibilityRuleService.setProperties(properties);
visibilityRuleService.buildVisibilityContext(dataset.getDatasetProfileDefinition().getRules());
wordBuilder.build(document, dataset.getDatasetProfileDefinition(), visibilityRuleService);
@ -521,7 +549,7 @@ public class DatasetManager {
exportEnvelope.setFilename(label + ".docx");
String uuid = UUID.randomUUID().toString();
File exportFile = new File(this.environment.getProperty("temp.temp") + uuid + ".docx");
XWPFDocument document = getWordDocument(configLoader, datasetEntity, visibilityRuleService);
XWPFDocument document = getWordDocument(configLoader, datasetEntity, visibilityRuleService, principal);
FileOutputStream out = new FileOutputStream(exportFile);
document.write(out);
out.close();

View File

@ -12,6 +12,7 @@ public interface ConfigLoader {
ExternalUrls getExternalUrls();
List<String> getRdaProperties();
XWPFDocument getDocument();
XWPFDocument getDatasetDocument();
ConfigurableProviders getConfigurableProviders();
Map<String, String> getKeyToSourceMap();
List<DOIFunder> getDOIFunders();

View File

@ -38,6 +38,7 @@ public class DefaultConfigLoader implements ConfigLoader {
private ExternalUrls externalUrls;
private List<String> rdaProperties;
private XWPFDocument document;
private XWPFDocument datasetDocument;
private ConfigurableProviders configurableProviders;
private Map<String, String> keyToSourceMap;
private List<DOIFunder> doiFunders = new ArrayList<>();
@ -103,6 +104,24 @@ public class DefaultConfigLoader implements ConfigLoader {
}
}
private void setDatasetDocument() {
String filePath = environment.getProperty("configuration.h2020datasettemplate");
logger.info("Loaded also config file: " + filePath);
InputStream is = null;
try {
is = getStreamFromPath(filePath);
this.datasetDocument = new XWPFDocument(is);
} catch (IOException | NullPointerException e) {
logger.error(e.getMessage(), e);
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
logger.warn("Warning: Could not close a stream after reading from file: " + filePath, e);
}
}
}
private void setConfigurableProviders() {
String filePath = environment.getProperty("configuration.configurable_login_providers");
logger.info("Loaded also config file: " + filePath);
@ -183,6 +202,11 @@ public class DefaultConfigLoader implements ConfigLoader {
return document;
}
public XWPFDocument getDatasetDocument() {
this.setDatasetDocument();
return datasetDocument;
}
public ConfigurableProviders getConfigurableProviders() {
if (configurableProviders == null) {
configurableProviders = new ConfigurableProviders();

View File

@ -1,6 +1,7 @@
package eu.eudat.logic.utilities.documents.word;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlCursor;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;
@ -22,15 +23,17 @@ public class HtmlToWorldBuilder implements NodeVisitor {
private XWPFNumbering numbering;
private Queue<BigInteger> abstractNumId;
private BigInteger numberingLevel;
private XmlCursor cursor;
public static HtmlToWorldBuilder convert(XWPFDocument document, Document htmlDocument, float indentation) {
XWPFParagraph paragraph = document.createParagraph();
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(paragraph, indentation);
paragraph.setIndentFromLeft(Math.round(400 * indentation));
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(paragraph, indentation, null);
NodeTraversor.traverse(htmlToWorldBuilder, htmlDocument);
return htmlToWorldBuilder;
}
public HtmlToWorldBuilder(XWPFParagraph paragraph, float indentation) {
public HtmlToWorldBuilder(XWPFParagraph paragraph, float indentation, XmlCursor cursor) {
this.paragraph = paragraph;
this.run = this.paragraph.createRun();
this.dumpRun = false;
@ -40,6 +43,7 @@ public class HtmlToWorldBuilder implements NodeVisitor {
this.abstractNumId = new ArrayDeque<>();
this.numberingLevel = BigInteger.valueOf(-1);
this.setDefaultIndentation();
this.cursor = cursor;
}
@Override
@ -96,7 +100,13 @@ public class HtmlToWorldBuilder implements NodeVisitor {
break;
case "div":
case "p":
this.paragraph = this.paragraph.getDocument().createParagraph();
if(this.cursor != null) {
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
this.cursor = this.paragraph.getCTP().newCursor();
this.cursor.toNextSibling();
} else {
this.paragraph = this.paragraph.getDocument().createParagraph();
}
this.run = this.paragraph.createRun();
this.isIdentationUsed = false;
this.setDefaultIndentation();
@ -108,10 +118,15 @@ public class HtmlToWorldBuilder implements NodeVisitor {
}
break;
case "blockquote":
this.paragraph = this.paragraph.getDocument().createParagraph();
if(this.cursor != null) {
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
this.cursor = this.paragraph.getCTP().newCursor();
} else {
this.paragraph = this.paragraph.getDocument().createParagraph();
}
this.run = this.paragraph.createRun();
if (stringBooleanEntry.getValue()) {
this.paragraph.setIndentationLeft(720);
this.paragraph.setIndentationLeft(400);
} else {
this.isIdentationUsed = false;
this.setDefaultIndentation();
@ -121,7 +136,12 @@ public class HtmlToWorldBuilder implements NodeVisitor {
if (stringBooleanEntry.getValue()) {
createNumbering(STNumberFormat.BULLET);
} else {
this.paragraph = this.paragraph.getDocument().createParagraph();
if(this.cursor != null) {
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
this.cursor = this.paragraph.getCTP().newCursor();
} else {
this.paragraph = this.paragraph.getDocument().createParagraph();
}
this.run = this.paragraph.createRun();
this.isIdentationUsed = false;
this.setDefaultIndentation();
@ -133,7 +153,12 @@ public class HtmlToWorldBuilder implements NodeVisitor {
if (stringBooleanEntry.getValue()) {
createNumbering(STNumberFormat.DECIMAL);
} else {
this.paragraph = this.paragraph.getDocument().createParagraph();
if(this.cursor != null) {
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
this.cursor = this.paragraph.getCTP().newCursor();
} else {
this.paragraph = this.paragraph.getDocument().createParagraph();
}
this.run = this.paragraph.createRun();
this.isIdentationUsed = false;
this.setDefaultIndentation();
@ -143,8 +168,14 @@ public class HtmlToWorldBuilder implements NodeVisitor {
break;
case "li":
if (stringBooleanEntry.getValue()) {
this.paragraph = this.paragraph.getDocument().createParagraph();
this.paragraph.setIndentationLeft(Math.round(indentation * 720) * (numberingLevel.intValue() + 1));
if(this.cursor != null) {
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
this.cursor = this.paragraph.getCTP().newCursor();
} else {
this.paragraph = this.paragraph.getDocument().createParagraph();
}
// this.paragraph.setIndentationLeft(Math.round(indentation * 720) * (numberingLevel.intValue() + 1));
this.paragraph.setIndentFromLeft(Math.round(numberingLevel.intValue() * 400 + this.indentation*400));
this.run = this.paragraph.createRun();
this.paragraph.setNumID(((ArrayDeque<BigInteger>)abstractNumId).getLast());
}
@ -238,7 +269,8 @@ public class HtmlToWorldBuilder implements NodeVisitor {
private void setDefaultIndentation() {
if (!isIdentationUsed) {
this.paragraph.setIndentationLeft(Math.round(indentation * 720.0F));
// this.paragraph.setIndentationLeft(Math.round(indentation * 720.0F));
this.paragraph.setIndentFromLeft(Math.round(indentation * 400));
this.isIdentationUsed = true;
}
}

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Dataset;
import eu.eudat.data.entities.Organisation;
import eu.eudat.data.entities.Researcher;
import eu.eudat.logic.services.forms.VisibilityRuleService;
@ -19,10 +20,12 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlCursor;
import org.json.JSONArray;
import org.json.JSONException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.NodeTraversor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -88,7 +91,8 @@ public class WordBuilder {
});
this.options.put(ParagraphStyle.HTML, (mainDocumentPart, item) -> {
Document htmlDoc = Jsoup.parse(((String)item).replaceAll("\n", "<br>"));
HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convert(mainDocumentPart, htmlDoc, indent > 0 ? (indent/2.0F) * 0.8F : 0.8F);
// HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convert(mainDocumentPart, htmlDoc, indent > 0 ? (indent/2.0F) * 0.8F : 0.8F);
HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convert(mainDocumentPart, htmlDoc, this.indent);
return htmlToWorldBuilder.getParagraph();
});
this.options.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> {
@ -228,19 +232,20 @@ public class WordBuilder {
}
public XWPFDocument build(XWPFDocument document, PagedDatasetProfile pagedDatasetProfile, VisibilityRuleService visibilityRuleService) throws IOException {
createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService);
XWPFNumbering numbering = document.createNumbering();
BigInteger tempNumId = BigInteger.ONE;
boolean found = false;
while (!found) {
Object o = numbering.getAbstractNum(tempNumId);
found = (o == null);
if (!found) tempNumId = tempNumId.add(BigInteger.ONE);
}
cTAbstractNum.setAbstractNumId(tempNumId);
XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
this.numId = numbering.addNum(abstractNumID);
// createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService);
// XWPFNumbering numbering = document.createNumbering();
// BigInteger tempNumId = BigInteger.ONE;
// boolean found = false;
// while (!found) {
// Object o = numbering.getAbstractNum(tempNumId);
// found = (o == null);
// if (!found) tempNumId = tempNumId.add(BigInteger.ONE);
// }
// cTAbstractNum.setAbstractNumId(tempNumId);
// XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
// BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
// this.numId = numbering.addNum(abstractNumID);
createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService);
return document;
}
@ -248,7 +253,7 @@ public class WordBuilder {
private void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing, VisibilityRuleService visibilityRuleService) {
datasetProfilePages.forEach(item -> {
try {
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.HEADER4, 0, createListing, visibilityRuleService, item.getOrdinal() + 1, null);
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, 0, createListing, visibilityRuleService, item.getOrdinal() + 1, null);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
@ -263,13 +268,13 @@ public class WordBuilder {
String tempSectionString = sectionString != null ? sectionString + "." + (section.getOrdinal() + 1) : "" + (section.getOrdinal() + 1);
if (visibilityRuleService.isElementVisible(section.getId())) {
if (!createListing) {
XWPFParagraph paragraph = addParagraphContent(page + "." + tempSectionString + " " + section.getTitle(), mainDocumentPart, style, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
XWPFParagraph paragraph = addParagraphContent(page + "." + tempSectionString + " " + section.getTitle(), mainDocumentPart, style, numId, indent);
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
// number.setVal(BigInteger.valueOf(indent));
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
}
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER4, 1, createListing, visibilityRuleService, page, tempSectionString);
hasValue = createCompositeFields(section.getCompositeFields(), mainDocumentPart, 2, createListing, visibilityRuleService, page, tempSectionString);
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, indent+1, createListing, visibilityRuleService, page, tempSectionString);
hasValue = createCompositeFields(section.getCompositeFields(), mainDocumentPart, indent+1, createListing, visibilityRuleService, page, tempSectionString);
if (!hasValue && paragraphPos > -1) {
mainDocumentPart.removeBodyElement(paragraphPos);
@ -290,19 +295,18 @@ public class WordBuilder {
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));
XWPFParagraph paragraph = addParagraphContent(page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId, indent);
// 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);
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId);
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId, indent);
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
hasMultiplicityItems = true;
multiplicityItems++;
}
}
hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
hasValue = createFields(compositeField.getFields(), mainDocumentPart, indent, createListing, visibilityRuleService, hasMultiplicityItems);
if(hasValue){
returnedValue = true;
} else if(paragraphPosInner > -1){
@ -317,13 +321,13 @@ public class WordBuilder {
if(!createListing){
c++;
// addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId);
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId, indent);
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
hasMultiplicityItems = true;
multiplicityItems++;
}
// hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
boolean hasValueInner = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
boolean hasValueInner = createFields(multiplicityFieldset.getFields(), mainDocumentPart, indent, createListing, visibilityRuleService, hasMultiplicityItems);
// if(hasValue){
if(hasValueInner){
hasValue = true;
@ -342,9 +346,9 @@ public class WordBuilder {
}
}
if (hasValue && compositeField.getHasCommentField() && compositeField.getCommentFieldValue() != null && !compositeField.getCommentFieldValue().isEmpty() && !createListing) {
XWPFParagraph paragraph = addParagraphContent("<i>Comment:</i>\n"+compositeField.getCommentFieldValue(), mainDocumentPart, ParagraphStyle.HTML, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
XWPFParagraph paragraph = addParagraphContent("<i>Comment:</i>\n"+compositeField.getCommentFieldValue(), mainDocumentPart, ParagraphStyle.HTML, numId, indent);
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
// number.setVal(BigInteger.valueOf(indent));
}
if (!hasValue && paragraphPos > -1) {
mainDocumentPart.removeBodyElement(paragraphPos);
@ -373,10 +377,10 @@ public class WordBuilder {
}
if(isImage){
if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
XWPFParagraph paragraph = addParagraphContent(mapper.convertValue(field.getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId);
XWPFParagraph paragraph = addParagraphContent(mapper.convertValue(field.getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId, 0);
if (paragraph != null) {
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
// number.setVal(BigInteger.valueOf(indent));
hasValue = true;
}
if(hasMultiplicityItems){
@ -407,7 +411,7 @@ public class WordBuilder {
String orcId = null;
if(isResearcher && val.contains("orcid:")){
orcId = val.substring(val.indexOf(':') + 1, val.indexOf(')'));
val = val.substring(0, val.indexOf(':') + 1);
val = val.substring(0, val.indexOf(':') + 1) + " ";
orcidResearcher = true;
}
format = "" + val;
@ -423,7 +427,7 @@ public class WordBuilder {
hasMultiplicityItems = false;
}
else{
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
if(orcidResearcher){
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
run.setText(orcId);
@ -432,8 +436,8 @@ public class WordBuilder {
paragraph.createRun().setText(")");
}
if (paragraph != null) {
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
// number.setVal(BigInteger.valueOf(indent));
hasValue = true;
}
}
@ -451,10 +455,10 @@ public class WordBuilder {
hasValue = true;
}
else{
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
if (paragraph != null) {
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
// number.setVal(BigInteger.valueOf(indent));
hasValue = true;
}
}
@ -487,14 +491,16 @@ public class WordBuilder {
}
}
public XWPFParagraph addParagraphContent(Object content, XWPFDocument mainDocumentPart, ParagraphStyle style, BigInteger numId) {
public XWPFParagraph addParagraphContent(Object content, XWPFDocument mainDocumentPart, ParagraphStyle style, BigInteger numId, int indent) {
// this.indent = 0;
if (content != null) {
if (content instanceof String && ((String)content).isEmpty()) {
return null;
}
this.indent = indent;
XWPFParagraph paragraph = this.options.get(style).apply(mainDocumentPart, content);
if (paragraph != null) {
paragraph.setIndentFromLeft(400*indent);
if (numId != null) {
paragraph.setNumID(numId);
}
@ -511,18 +517,19 @@ public class WordBuilder {
for (int i = 0; i <= indent; i++) {
textLevel += "%" + (i + 1) + ".";
}
if (question) {
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
cTLvl.addNewLvlText().setVal("");
// cTLvl.addNewLvlText().setVal("");
cTLvl.setIlvl(BigInteger.valueOf(indent));
} else if (!question && hasIndication) {
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
cTLvl.addNewLvlText().setVal("");
// cTLvl.addNewLvlText().setVal("");
cTLvl.setIlvl(BigInteger.valueOf(indent));
}
if (!question && !hasIndication) {
cTLvl.addNewNumFmt().setVal(STNumberFormat.NONE);
cTLvl.addNewLvlText().setVal("");
// cTLvl.addNewLvlText().setVal("");
cTLvl.setIlvl(BigInteger.valueOf(indent));
}
}
@ -658,60 +665,112 @@ public class WordBuilder {
return result;
}
public void fillFirstPage(DMP dmpEntity, XWPFDocument document) {
public int findPosOfPoweredBy(XWPFDocument document) {
for (XWPFParagraph p : document.getParagraphs()) {
List<XWPFRun> runs = p.getRuns();
if (runs != null) {
for (XWPFRun r : runs) {
String text = r.getText(0);
if (text != null) {
if (text.equals("Powered by")) {
return document.getPosOfParagraph(p) - 1;
}
}
}
}
}
return -1;
}
public void fillFirstPage(DMP dmpEntity, Dataset datasetEntity, XWPFDocument document) {
int parPos = 0;
int descrParPos = -1;
XWPFParagraph descrPar = null;
for(XWPFParagraph p: document.getParagraphs()){
List<XWPFRun> runs = p.getRuns();
if(runs != null){
for(XWPFRun r : runs){
String text = r.getText(0);
if(text != null){
if(text.contains("{ARGOS.DMP.VERSION}")){
text = text.replace("{ARGOS.DMP.VERSION}", "VERSION " + dmpEntity.getVersion());
if(text.contains("{ARGOS.DMP.TITLE}")) {
text = text.replace("{ARGOS.DMP.TITLE}", dmpEntity.getLabel());
r.setText(text, 0);
}
else if(text.contains("{ARGOS.DMP.FUNDER}")){
text = text.replace("{ARGOS.DMP.FUNDER}", dmpEntity.getGrant().getFunder().getLabel());
} else if(text.contains("{ARGOS.DMP.VERSION}")) {
text = text.replace("{ARGOS.DMP.VERSION}", "Version " + dmpEntity.getVersion());
r.setText(text, 0);
}
else if(text.contains("{ARGOS.DMP.GRANT}")){
text = text.replace("{ARGOS.DMP.GRANT}", dmpEntity.getGrant().getLabel());
} else if(datasetEntity != null && text.contains("{ARGOS.DATASET.TITLE}")) {
text = text.replace("{ARGOS.DATASET.TITLE}", datasetEntity.getLabel());
r.setText(text, 0);
} else if(datasetEntity != null && text.contains("{ARGOS.DATASET.DESCRIPTION}")) {
descrParPos = parPos;
descrPar = p;
text = text.replace("{ARGOS.DATASET.DESCRIPTION}", "");
r.setText(text, 0);
} else if(text.equals("{ARGOS.DMP.RESEARCHERS}")) {
String researchersNames = "";
Set<Researcher> researchers = dmpEntity.getResearchers();
int i = 0;
for(Researcher researcher : researchers){
i++;
researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : "");
}
text = text.replace("{ARGOS.DMP.RESEARCHERS}", researchersNames);
r.setText(text, 0);
r.setFontSize(17);
} else if(text.equals("{ARGOS.DMP.ORGANIZATIONS}")) {
String organisationsNames = "";
Set<Organisation> organisations = dmpEntity.getOrganisations();
int i = 0;
for(Organisation organisation : organisations){
i++;
organisationsNames += organisation.getLabel() + (i < organisations.size() ? ", " : "");
}
text = text.replace("{ARGOS.DMP.ORGANIZATIONS}", organisationsNames);
r.setText(text, 0);
r.setFontSize(17);
}
}
}
}
parPos++;
}
if(descrParPos != -1 && datasetEntity.getDescription() != null) {
XmlCursor cursor = descrPar.getCTP().newCursor();
cursor.toNextSibling();
Document htmlDoc = Jsoup.parse(((String)datasetEntity.getDescription()).replaceAll("\n", "<br>"));
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(descrPar, 0, cursor);
NodeTraversor.traverse(htmlToWorldBuilder, htmlDoc);
}
int researchers = dmpEntity.getResearchers().size();
int organizations = dmpEntity.getOrganisations().size();
if(researchers > 0 || organizations > 0){
XWPFTable tbl = document.getTables().get(0);
for(int i = (Integer.max(researchers, organizations) - 1); i > 0; i--)
tbl.createRow();
Iterator<XWPFTableRow> it = tbl.getRows().iterator();
it.next(); // skip first row
for(Researcher researcher : dmpEntity.getResearchers()){
if(it.hasNext()){
XWPFRun run = it.next().getCell(0).getParagraphs().get(0).createRun();
run.setText(researcher.getLabel());
run.setFontSize(17);
}
if(it.hasNext()){
XWPFParagraph p = it.next().getCell(0).getParagraphs().get(0);
XWPFRun run = p.createRun();
run.setText(dmpEntity.getGrant().getFunder().getLabel());
run.setFontSize(17);
p.setAlignment(ParagraphAlignment.CENTER);
}
it = tbl.getRows().iterator();
it.next();
for(Organisation organisation : dmpEntity.getOrganisations()){
if(it.hasNext()){
XWPFParagraph p = it.next().getCell(1).getParagraphs().get(0);
XWPFRun run = p.createRun();
run.setText(organisation.getLabel());
run.setFontSize(17);
p.setAlignment(ParagraphAlignment.RIGHT);
if(it.hasNext()){
XWPFParagraph p = it.next().getCell(1).getParagraphs().get(0);
XWPFRun run = p.createRun();
String text = dmpEntity.getGrant().getLabel();
String reference = dmpEntity.getGrant().getReference();
if(reference != null) {
String[] parts = reference.split("::");
text += parts.length > 1 ? "/ No "+parts[parts.length - 1] : "";
}
run.setText(text);
run.setFontSize(17);
p.setAlignment(ParagraphAlignment.CENTER);
}
}
}
public void fillFooter(DMP dmpEntity, XWPFDocument document) {
public void fillFooter(DMP dmpEntity, XWPFDocument document, boolean isDataset) {
document.getFooterList().forEach(xwpfFooter -> {
List<XWPFRun> runs = xwpfFooter.getParagraphs().get(0).getRuns();
if(runs != null){

View File

@ -25,6 +25,7 @@ pdf.converter.url=http://localhost:3000/
configuration.externalUrls=externalUrls/ExternalUrls.xml
configuration.rda=RDACommonStandards.txt
configuration.h2020template=documents/h2020.docx
configuration.h2020datasettemplate=documents/h2020_dataset.docx
configuration.configurable_login_providers=configurableLoginProviders.json
configuration.doi_funder=DOI_Funder.json

View File

@ -19,6 +19,7 @@ pdf.converter.url=http://docsbox-web/
configuration.externalUrls=externalUrls/ExternalUrls.xml
configuration.rda=RDACommonStandards.txt
configuration.h2020template=documents/h2020.docx
configuration.h2020datasettemplate=documents/h2020_dataset.docx
configuration.configurable_login_providers=ConfigurableLoginProviders.json
configuration.doi_funder=DOI_Funder.json

View File

@ -19,6 +19,7 @@ pdf.converter.url=http://docsbox-web/
configuration.externalUrls=externalUrls/ExternalUrls.xml
configuration.rda=RDACommonStandards.txt
configuration.h2020template=documents/h2020.docx
configuration.h2020datasettemplate=documents/h2020_dataset.docx
configuration.configurable_login_providers=ConfigurableLoginProviders.json
configuration.doi_funder=DOI_Funder.json

View File

@ -50,6 +50,7 @@ elasticsearch.certKey=
configuration.externalUrls=externalUrls/ExternalUrls.xml
configuration.rda=RDACommonStandards.txt
configuration.h2020template=documents/h2020.docx
configuration.h2020datasettemplate=documents/h2020_dataset.docx
configuration.configurable_login_providers=ConfigurableLoginProviders.json
configuration.doi_funder=DOI_Funder.json