2018-06-27 12:29:21 +02:00
|
|
|
package eu.eudat.logic.utilities.documents.word;
|
2018-03-01 10:14:10 +01:00
|
|
|
|
2020-07-23 11:01:37 +02:00
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
2018-10-19 11:59:54 +02:00
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2023-10-27 17:46:34 +02:00
|
|
|
import eu.eudat.commons.types.descriptiontemplate.fielddata.*;
|
2023-11-06 15:17:57 +01:00
|
|
|
import eu.eudat.data.DescriptionEntity;
|
2023-11-16 13:01:39 +01:00
|
|
|
import eu.eudat.data.DmpEntity;
|
2023-06-21 11:00:20 +02:00
|
|
|
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
2018-10-08 17:14:27 +02:00
|
|
|
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.utilities.documents.types.ParagraphStyle;
|
2018-10-08 17:14:27 +02:00
|
|
|
import eu.eudat.logic.utilities.interfaces.ApplierWithValue;
|
2022-03-22 13:03:22 +01:00
|
|
|
import eu.eudat.logic.utilities.json.JavaToJson;
|
2023-06-21 11:00:20 +02:00
|
|
|
import eu.eudat.models.data.pid.PidLink;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.user.components.datasetprofile.Field;
|
|
|
|
import eu.eudat.models.data.user.components.datasetprofile.FieldSet;
|
|
|
|
import eu.eudat.models.data.user.components.datasetprofile.Section;
|
|
|
|
import eu.eudat.models.data.user.composite.DatasetProfilePage;
|
|
|
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
2022-03-17 09:47:50 +01:00
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
|
import org.apache.poi.util.Units;
|
2018-03-01 10:14:10 +01:00
|
|
|
import org.apache.poi.xwpf.usermodel.*;
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
import org.apache.xmlbeans.XmlCursor;
|
2022-03-22 13:03:22 +01:00
|
|
|
import org.json.JSONArray;
|
2022-03-24 08:43:13 +01:00
|
|
|
import org.json.JSONException;
|
2021-10-06 14:15:41 +02:00
|
|
|
import org.jsoup.Jsoup;
|
|
|
|
import org.jsoup.nodes.Document;
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
import org.jsoup.select.NodeTraversor;
|
2022-03-17 09:47:50 +01:00
|
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
|
2020-01-16 16:46:24 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2022-03-17 09:47:50 +01:00
|
|
|
import org.springframework.core.env.Environment;
|
2018-03-01 10:14:10 +01:00
|
|
|
|
2022-03-17 09:47:50 +01:00
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
import javax.imageio.ImageReader;
|
|
|
|
import javax.imageio.stream.ImageInputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
2018-10-08 17:14:27 +02:00
|
|
|
import java.io.IOException;
|
2018-03-01 10:14:10 +01:00
|
|
|
import java.math.BigInteger;
|
2022-06-13 14:16:48 +02:00
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
2021-11-17 09:30:31 +01:00
|
|
|
import java.time.Instant;
|
2022-02-10 12:21:21 +01:00
|
|
|
import java.time.LocalDate;
|
2021-11-17 09:30:31 +01:00
|
|
|
import java.time.ZoneId;
|
2022-02-10 12:21:21 +01:00
|
|
|
import java.time.ZoneOffset;
|
2021-11-17 09:30:31 +01:00
|
|
|
import java.time.format.DateTimeFormatter;
|
2021-11-24 15:41:01 +01:00
|
|
|
import java.time.format.DateTimeParseException;
|
2020-07-23 11:01:37 +02:00
|
|
|
import java.util.*;
|
2021-09-27 17:11:55 +02:00
|
|
|
import java.util.stream.Collectors;
|
2022-03-17 16:08:45 +01:00
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
import static org.apache.poi.xwpf.usermodel.Document.*;
|
2018-03-01 10:14:10 +01:00
|
|
|
|
|
|
|
public class WordBuilder {
|
2020-01-16 16:46:24 +01:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(WordBuilder.class);
|
2022-03-17 16:08:45 +01:00
|
|
|
private static final Map<String, Integer> IMAGE_TYPE_MAP = Stream.of(new Object[][] {
|
2022-03-21 17:19:51 +01:00
|
|
|
{"image/jpeg", PICTURE_TYPE_JPEG},
|
|
|
|
{"image/png", PICTURE_TYPE_PNG},
|
|
|
|
{"image/gif", PICTURE_TYPE_GIF},
|
|
|
|
{"image/tiff", PICTURE_TYPE_TIFF},
|
|
|
|
{"image/bmp", PICTURE_TYPE_BMP},
|
|
|
|
{"image/wmf", PICTURE_TYPE_WMF}
|
|
|
|
}
|
2022-03-17 16:08:45 +01:00
|
|
|
).collect(Collectors.toMap(objects -> (String)objects[0], o -> (Integer)o[1]));
|
2018-03-01 10:14:10 +01:00
|
|
|
|
2022-03-17 09:47:50 +01:00
|
|
|
private Map<ParagraphStyle, ApplierWithValue<XWPFDocument, Object, XWPFParagraph>> options = new HashMap<>();
|
2022-11-08 13:39:23 +01:00
|
|
|
private Map<ParagraphStyle, ApplierWithValue<XWPFTableCell, Object, XWPFParagraph>> optionsInTable = new HashMap<>();
|
2018-03-01 10:14:10 +01:00
|
|
|
private CTAbstractNum cTAbstractNum;
|
|
|
|
private BigInteger numId;
|
2021-11-09 16:44:47 +01:00
|
|
|
private Integer indent;
|
2022-06-07 12:10:06 +02:00
|
|
|
private final ObjectMapper mapper;
|
|
|
|
private Integer imageCount;
|
2023-06-21 11:00:20 +02:00
|
|
|
private ConfigLoader configLoader;
|
2018-03-01 10:14:10 +01:00
|
|
|
|
2023-06-21 11:00:20 +02:00
|
|
|
public WordBuilder(Environment environment, ConfigLoader configLoader) {
|
2018-03-01 10:14:10 +01:00
|
|
|
this.cTAbstractNum = CTAbstractNum.Factory.newInstance();
|
|
|
|
this.cTAbstractNum.setAbstractNumId(BigInteger.valueOf(1));
|
2021-11-09 16:44:47 +01:00
|
|
|
this.indent = 0;
|
2022-06-07 12:10:06 +02:00
|
|
|
this.imageCount = 0;
|
|
|
|
this.mapper = new ObjectMapper();
|
2022-03-17 09:47:50 +01:00
|
|
|
this.buildOptions(environment);
|
2022-11-08 13:39:23 +01:00
|
|
|
this.buildOptionsInTable(environment);
|
2023-06-21 11:00:20 +02:00
|
|
|
this.configLoader = configLoader;
|
2022-11-08 13:39:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void buildOptionsInTable(Environment environment) {
|
|
|
|
this.optionsInTable.put(ParagraphStyle.TEXT, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.addParagraph();
|
|
|
|
XWPFRun run = paragraph.createRun();
|
|
|
|
if (item != null)
|
|
|
|
run.setText("" + item);
|
|
|
|
run.setFontSize(11);
|
|
|
|
return paragraph;
|
|
|
|
});
|
|
|
|
this.optionsInTable.put(ParagraphStyle.HTML, (mainDocumentPart, item) -> {
|
|
|
|
Document htmlDoc = Jsoup.parse(((String)item).replaceAll("\n", "<br>"));
|
|
|
|
HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convertInTable(mainDocumentPart, htmlDoc, 0);
|
|
|
|
return htmlToWorldBuilder.getParagraph();
|
|
|
|
});
|
|
|
|
this.optionsInTable.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.addParagraph();
|
|
|
|
paragraph.setStyle("Title");
|
|
|
|
paragraph.setAlignment(ParagraphAlignment.CENTER);
|
|
|
|
XWPFRun run = paragraph.createRun();
|
|
|
|
run.setText((String)item);
|
|
|
|
run.setBold(true);
|
|
|
|
run.setFontSize(14);
|
|
|
|
return paragraph;
|
|
|
|
});
|
|
|
|
this.optionsInTable.put(ParagraphStyle.IMAGE, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.addParagraph();
|
|
|
|
XWPFRun run = paragraph.createRun();
|
|
|
|
if (item != null)
|
|
|
|
run.setText(((Map<String, String>)item).get("name"));
|
|
|
|
run.setFontSize(11);
|
|
|
|
run.setItalic(true);
|
|
|
|
return paragraph;
|
|
|
|
});
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
|
|
|
|
2022-03-17 09:47:50 +01:00
|
|
|
private void buildOptions(Environment environment) {
|
2018-03-01 10:14:10 +01:00
|
|
|
this.options.put(ParagraphStyle.TEXT, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
|
|
|
XWPFRun run = paragraph.createRun();
|
2019-05-22 10:53:30 +02:00
|
|
|
if (item != null)
|
2022-06-14 09:24:35 +02:00
|
|
|
run.setText("" + item);
|
2018-03-01 10:14:10 +01:00
|
|
|
run.setFontSize(11);
|
|
|
|
return paragraph;
|
|
|
|
});
|
2021-10-05 16:58:46 +02:00
|
|
|
this.options.put(ParagraphStyle.HTML, (mainDocumentPart, item) -> {
|
2022-03-17 09:47:50 +01:00
|
|
|
Document htmlDoc = Jsoup.parse(((String)item).replaceAll("\n", "<br>"));
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convert(mainDocumentPart, htmlDoc, this.indent);
|
2021-11-01 10:39:43 +01:00
|
|
|
return htmlToWorldBuilder.getParagraph();
|
2021-10-05 16:58:46 +02:00
|
|
|
});
|
2018-03-01 10:14:10 +01:00
|
|
|
this.options.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
2018-10-18 11:33:13 +02:00
|
|
|
paragraph.setStyle("Title");
|
|
|
|
paragraph.setAlignment(ParagraphAlignment.CENTER);
|
2018-03-01 10:14:10 +01:00
|
|
|
XWPFRun run = paragraph.createRun();
|
2022-03-17 09:47:50 +01:00
|
|
|
run.setText((String)item);
|
2018-03-01 10:14:10 +01:00
|
|
|
run.setBold(true);
|
|
|
|
run.setFontSize(14);
|
|
|
|
return paragraph;
|
|
|
|
});
|
|
|
|
this.options.put(ParagraphStyle.HEADER1, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
2018-10-18 11:33:13 +02:00
|
|
|
paragraph.setStyle("Heading1");
|
2018-03-01 10:14:10 +01:00
|
|
|
XWPFRun run = paragraph.createRun();
|
2022-03-17 09:47:50 +01:00
|
|
|
run.setText((String)item);
|
2019-10-30 13:30:31 +01:00
|
|
|
// run.setBold(true);
|
|
|
|
// run.setFontSize(12);
|
|
|
|
// run.setStyle("0");
|
2018-03-01 10:14:10 +01:00
|
|
|
return paragraph;
|
|
|
|
});
|
|
|
|
this.options.put(ParagraphStyle.HEADER2, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
2018-10-18 11:33:13 +02:00
|
|
|
paragraph.setStyle("Heading2");
|
2018-03-01 10:14:10 +01:00
|
|
|
XWPFRun run = paragraph.createRun();
|
2022-06-14 09:24:35 +02:00
|
|
|
run.setText("" + item);
|
2019-10-30 13:30:31 +01:00
|
|
|
// run.setBold(true);
|
|
|
|
// run.setFontSize(12);
|
2018-03-01 10:14:10 +01:00
|
|
|
return paragraph;
|
|
|
|
});
|
|
|
|
this.options.put(ParagraphStyle.HEADER3, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
2018-10-18 11:33:13 +02:00
|
|
|
paragraph.setStyle("Heading3");
|
2018-03-01 10:14:10 +01:00
|
|
|
XWPFRun run = paragraph.createRun();
|
2022-06-14 09:24:35 +02:00
|
|
|
run.setText("" + item);
|
2019-10-30 13:30:31 +01:00
|
|
|
// run.setBold(true);
|
|
|
|
// run.setFontSize(11);
|
|
|
|
return paragraph;
|
|
|
|
});
|
|
|
|
this.options.put(ParagraphStyle.HEADER4, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
|
|
|
paragraph.setStyle("Heading4");
|
|
|
|
XWPFRun run = paragraph.createRun();
|
2022-03-17 09:47:50 +01:00
|
|
|
run.setText((String)item);
|
2019-10-30 13:30:31 +01:00
|
|
|
return paragraph;
|
|
|
|
});
|
|
|
|
this.options.put(ParagraphStyle.HEADER5, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
|
|
|
paragraph.setStyle("Heading5");
|
|
|
|
XWPFRun run = paragraph.createRun();
|
2022-06-14 09:24:35 +02:00
|
|
|
run.setText("" + item);
|
2018-03-01 10:14:10 +01:00
|
|
|
return paragraph;
|
|
|
|
});
|
2019-10-31 11:07:28 +01:00
|
|
|
this.options.put(ParagraphStyle.HEADER6, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
|
|
|
paragraph.setStyle("Heading6");
|
|
|
|
XWPFRun run = paragraph.createRun();
|
2022-06-14 09:24:35 +02:00
|
|
|
run.setText("" + item);
|
2019-10-31 11:07:28 +01:00
|
|
|
return paragraph;
|
|
|
|
});
|
2018-03-01 10:14:10 +01:00
|
|
|
this.options.put(ParagraphStyle.FOOTER, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
|
|
|
XWPFRun run = paragraph.createRun();
|
2022-03-17 09:47:50 +01:00
|
|
|
run.setText((String)item);
|
2018-03-01 10:14:10 +01:00
|
|
|
return paragraph;
|
|
|
|
});
|
2018-10-22 12:34:39 +02:00
|
|
|
this.options.put(ParagraphStyle.COMMENT, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
|
|
|
XWPFRun run = paragraph.createRun();
|
2022-06-14 09:24:35 +02:00
|
|
|
run.setText("" + item);
|
2018-10-22 12:34:39 +02:00
|
|
|
run.setItalic(true);
|
|
|
|
return paragraph;
|
|
|
|
});
|
2022-03-17 09:47:50 +01:00
|
|
|
this.options.put(ParagraphStyle.IMAGE, (mainDocumentPart, item) -> {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
2022-03-21 17:19:51 +01:00
|
|
|
paragraph.setPageBreak(true);
|
2022-06-07 12:10:06 +02:00
|
|
|
paragraph.setSpacingAfter(0);
|
|
|
|
paragraph.setAlignment(ParagraphAlignment.CENTER); //GK: Center the image if it is too small
|
2022-03-17 09:47:50 +01:00
|
|
|
XWPFRun run = paragraph.createRun();
|
|
|
|
String imageId = ((Map<String, String>)item).get("id");
|
|
|
|
String fileName = ((Map<String, String>)item).get("name");
|
2022-03-21 17:19:51 +01:00
|
|
|
String fileType = ((Map<String, String>)item).get("type");
|
2022-03-17 16:08:45 +01:00
|
|
|
int format;
|
2022-03-21 17:19:51 +01:00
|
|
|
format = IMAGE_TYPE_MAP.getOrDefault(fileType, 0);
|
2022-03-17 09:47:50 +01:00
|
|
|
try {
|
|
|
|
FileInputStream image = new FileInputStream(environment.getProperty("file.storage") + imageId);
|
|
|
|
ImageInputStream iis = ImageIO.createImageInputStream(new File(environment.getProperty("file.storage") + imageId));
|
|
|
|
Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
|
|
|
|
if (readers.hasNext()) {
|
|
|
|
ImageReader reader = readers.next();
|
|
|
|
reader.setInput(iis);
|
2022-03-21 17:19:51 +01:00
|
|
|
|
|
|
|
int initialImageWidth = reader.getWidth(0);
|
|
|
|
int initialImageHeight = reader.getHeight(0);
|
|
|
|
|
|
|
|
float ratio = initialImageHeight / (float)initialImageWidth;
|
|
|
|
|
|
|
|
int marginLeftInDXA = mainDocumentPart.getDocument().getBody().getSectPr().getPgMar().getLeft().intValue();
|
|
|
|
int marginRightInDXA = mainDocumentPart.getDocument().getBody().getSectPr().getPgMar().getRight().intValue();
|
|
|
|
int pageWidthInDXA = mainDocumentPart.getDocument().getBody().getSectPr().getPgSz().getW().intValue();
|
|
|
|
int pageWidth = Math.round((pageWidthInDXA - marginLeftInDXA - marginRightInDXA) / (float)20); // /20 converts dxa to points
|
|
|
|
|
|
|
|
int imageWidth = Math.round(initialImageWidth*(float)0.75); // *0.75 converts pixels to points
|
2022-03-17 09:47:50 +01:00
|
|
|
int width = Math.min(imageWidth, pageWidth);
|
2022-03-21 17:19:51 +01:00
|
|
|
|
|
|
|
int marginTopInDXA = mainDocumentPart.getDocument().getBody().getSectPr().getPgMar().getTop().intValue();
|
|
|
|
int marginBottomInDXA = mainDocumentPart.getDocument().getBody().getSectPr().getPgMar().getBottom().intValue();
|
|
|
|
int pageHeightInDXA = mainDocumentPart.getDocument().getBody().getSectPr().getPgSz().getH().intValue();
|
|
|
|
int pageHeight = Math.round((pageHeightInDXA - marginTopInDXA - marginBottomInDXA) / (float)20); // /20 converts dxa to points
|
|
|
|
|
|
|
|
int imageHeight = Math.round(initialImageHeight * ((float)0.75)); // *0.75 converts pixels to points
|
|
|
|
|
|
|
|
int height = Math.round(width*ratio);
|
|
|
|
if(height > pageHeight) {
|
|
|
|
// height calculated with ratio is too large. Image may have Portrait (vertical) orientation. Recalculate image dimensions.
|
|
|
|
height = Math.min(imageHeight, pageHeight);
|
|
|
|
width = Math.round(height/ratio);
|
|
|
|
}
|
|
|
|
|
2022-06-07 12:10:06 +02:00
|
|
|
XWPFPicture picture = run.addPicture(image, format, fileName, Units.toEMU(width), Units.toEMU(height));
|
2022-03-21 17:19:51 +01:00
|
|
|
paragraph.setPageBreak(false);
|
2022-06-07 12:10:06 +02:00
|
|
|
imageCount++;
|
|
|
|
XWPFParagraph captionParagraph = mainDocumentPart.createParagraph();
|
|
|
|
captionParagraph.setAlignment(ParagraphAlignment.CENTER);
|
|
|
|
captionParagraph.setSpacingBefore(0);
|
2022-06-07 13:52:48 +02:00
|
|
|
captionParagraph.setStyle("Caption");
|
2022-06-07 12:10:06 +02:00
|
|
|
XWPFRun captionRun = captionParagraph.createRun();
|
|
|
|
captionRun.setText("Image " + imageCount);
|
|
|
|
|
2022-03-17 09:47:50 +01:00
|
|
|
}
|
|
|
|
} catch (IOException | InvalidFormatException e){
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
return paragraph;
|
|
|
|
});
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
|
|
|
|
2018-10-18 11:33:13 +02:00
|
|
|
public XWPFDocument build(XWPFDocument document, PagedDatasetProfile pagedDatasetProfile, VisibilityRuleService visibilityRuleService) throws IOException {
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
// 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);
|
|
|
|
|
2018-03-05 17:18:45 +01:00
|
|
|
createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService);
|
2018-10-18 11:33:13 +02:00
|
|
|
return document;
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
|
|
|
|
2019-12-17 12:08:01 +01:00
|
|
|
private void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing, VisibilityRuleService visibilityRuleService) {
|
2018-03-01 10:14:10 +01:00
|
|
|
datasetProfilePages.forEach(item -> {
|
2020-02-26 12:37:54 +01:00
|
|
|
try {
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, 0, createListing, visibilityRuleService, item.getOrdinal() + 1, null);
|
2020-02-26 12:37:54 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
2018-03-01 10:14:10 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-14 17:01:29 +02:00
|
|
|
private void createSections(List<Section> sections, XWPFDocument mainDocumentPart, ParagraphStyle style, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService, Integer page, String sectionString) {
|
2018-03-01 10:14:10 +01:00
|
|
|
if (createListing) this.addListing(mainDocumentPart, indent, false, true);
|
2021-06-30 16:17:17 +02:00
|
|
|
boolean hasValue = false;
|
|
|
|
for (Section section: sections) {
|
|
|
|
int paragraphPos = -1;
|
2021-06-14 17:01:29 +02:00
|
|
|
String tempSectionString = sectionString != null ? sectionString + "." + (section.getOrdinal() + 1) : "" + (section.getOrdinal() + 1);
|
2018-03-05 17:18:45 +01:00
|
|
|
if (visibilityRuleService.isElementVisible(section.getId())) {
|
|
|
|
if (!createListing) {
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
XWPFParagraph paragraph = addParagraphContent(page + "." + tempSectionString + " " + section.getTitle(), mainDocumentPart, style, numId, indent);
|
|
|
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
|
|
// number.setVal(BigInteger.valueOf(indent));
|
2021-06-30 16:17:17 +02:00
|
|
|
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
|
2018-03-05 17:18:45 +01:00
|
|
|
}
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, indent+1, createListing, visibilityRuleService, page, tempSectionString);
|
|
|
|
hasValue = createCompositeFields(section.getCompositeFields(), mainDocumentPart, indent+1, createListing, visibilityRuleService, page, tempSectionString);
|
2021-06-30 16:17:17 +02:00
|
|
|
|
|
|
|
if (!hasValue && paragraphPos > -1) {
|
|
|
|
mainDocumentPart.removeBodyElement(paragraphPos);
|
|
|
|
}
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
2021-06-30 16:17:17 +02:00
|
|
|
}
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
|
|
|
|
2021-06-30 16:17:17 +02:00
|
|
|
private Boolean createCompositeFields(List<FieldSet> compositeFields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService, Integer page, String section) {
|
2018-03-01 10:14:10 +01:00
|
|
|
if (createListing) this.addListing(mainDocumentPart, indent, true, true);
|
2021-06-30 16:17:17 +02:00
|
|
|
boolean hasValue = false;
|
2022-02-08 08:44:55 +01:00
|
|
|
boolean returnedValue = false;
|
2022-11-08 13:39:23 +01:00
|
|
|
|
2021-06-30 16:17:17 +02:00
|
|
|
for (FieldSet compositeField: compositeFields) {
|
2019-02-15 08:52:44 +01:00
|
|
|
if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) {
|
2022-01-12 13:10:00 +01:00
|
|
|
char c = 'a';
|
2022-06-23 14:32:05 +02:00
|
|
|
int multiplicityItems = 0;
|
2022-06-08 15:27:47 +02:00
|
|
|
boolean hasMultiplicityItems = false;
|
2021-06-30 16:17:17 +02:00
|
|
|
int paragraphPos = -1;
|
2022-06-23 14:32:05 +02:00
|
|
|
int paragraphPosInner = -1;
|
2018-03-05 17:18:45 +01:00
|
|
|
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
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));
|
2021-06-30 16:17:17 +02:00
|
|
|
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
|
2022-11-08 13:39:23 +01:00
|
|
|
if(!compositeField.getMultiplicity().getTableView() && compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()){
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId, indent);
|
2022-06-23 14:32:05 +02:00
|
|
|
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
|
2022-06-08 15:27:47 +02:00
|
|
|
hasMultiplicityItems = true;
|
2022-06-23 14:32:05 +02:00
|
|
|
multiplicityItems++;
|
2022-01-12 13:10:00 +01:00
|
|
|
}
|
2018-03-05 17:18:45 +01:00
|
|
|
}
|
2022-11-08 13:39:23 +01:00
|
|
|
XWPFTable tbl = null;
|
|
|
|
XWPFTableRow row = null;
|
|
|
|
int numOfRows = 0;
|
|
|
|
if(compositeField.getMultiplicity().getTableView()) {
|
|
|
|
tbl = mainDocumentPart.createTable();
|
|
|
|
tbl.setTableAlignment(TableRowAlign.CENTER);
|
|
|
|
mainDocumentPart.createParagraph();
|
|
|
|
createHeadersInTable(compositeField.getFields(), tbl, visibilityRuleService);
|
|
|
|
numOfRows = tbl.getRows().size();
|
|
|
|
row = tbl.createRow();
|
|
|
|
}
|
|
|
|
if(compositeField.getMultiplicity().getTableView()) {
|
|
|
|
hasValue = createFieldsInTable(compositeField.getFields(), row, indent, createListing, visibilityRuleService, hasMultiplicityItems, numOfRows);
|
|
|
|
numOfRows++;
|
|
|
|
} else {
|
|
|
|
hasValue = createFields(compositeField.getFields(), mainDocumentPart, indent, createListing, visibilityRuleService, hasMultiplicityItems);
|
|
|
|
}
|
2022-02-08 08:44:55 +01:00
|
|
|
if(hasValue){
|
|
|
|
returnedValue = true;
|
2022-06-23 14:32:05 +02:00
|
|
|
} else if(paragraphPosInner > -1){
|
|
|
|
mainDocumentPart.removeBodyElement(paragraphPosInner);
|
|
|
|
c--;
|
|
|
|
multiplicityItems--;
|
2022-02-08 08:44:55 +01:00
|
|
|
}
|
2019-10-30 13:30:31 +01:00
|
|
|
if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) {
|
2021-09-27 17:11:55 +02:00
|
|
|
List<FieldSet> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList());
|
|
|
|
for (FieldSet multiplicityFieldset : list) {
|
2022-06-23 14:32:05 +02:00
|
|
|
paragraphPosInner = -1;
|
2022-11-08 13:39:23 +01:00
|
|
|
if(!compositeField.getMultiplicity().getTableView() && !createListing){
|
2022-01-12 13:10:00 +01:00
|
|
|
c++;
|
2022-06-23 14:32:05 +02:00
|
|
|
// addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId, indent);
|
2022-06-23 14:32:05 +02:00
|
|
|
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
|
2022-06-08 15:27:47 +02:00
|
|
|
hasMultiplicityItems = true;
|
2022-06-23 14:32:05 +02:00
|
|
|
multiplicityItems++;
|
2022-01-12 13:10:00 +01:00
|
|
|
}
|
2022-06-23 14:32:05 +02:00
|
|
|
// hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
2022-11-08 13:39:23 +01:00
|
|
|
boolean hasValueInner = false;
|
|
|
|
if(compositeField.getMultiplicity().getTableView()) {
|
|
|
|
row = tbl.createRow();
|
|
|
|
hasValueInner = createFieldsInTable(multiplicityFieldset.getFields(), row, indent, createListing, visibilityRuleService, hasMultiplicityItems, numOfRows);
|
|
|
|
numOfRows++;
|
|
|
|
} else {
|
|
|
|
hasValueInner = createFields(multiplicityFieldset.getFields(), mainDocumentPart, indent, createListing, visibilityRuleService, hasMultiplicityItems);
|
|
|
|
}
|
2022-06-23 14:32:05 +02:00
|
|
|
// if(hasValue){
|
|
|
|
if(hasValueInner){
|
|
|
|
hasValue = true;
|
2022-02-08 08:44:55 +01:00
|
|
|
returnedValue = true;
|
2022-06-23 14:32:05 +02:00
|
|
|
} 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);
|
2022-02-08 08:44:55 +01:00
|
|
|
}
|
2019-06-05 15:57:05 +02:00
|
|
|
}
|
|
|
|
}
|
2023-10-27 17:46:34 +02:00
|
|
|
//TODO: Dataset Profile
|
|
|
|
// if (hasValue && compositeField.getHasCommentField() && compositeField.getCommentFieldValue() != null && !compositeField.getCommentFieldValue().isEmpty() && !createListing) {
|
|
|
|
// 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));
|
|
|
|
// }
|
2021-06-30 16:17:17 +02:00
|
|
|
if (!hasValue && paragraphPos > -1) {
|
|
|
|
mainDocumentPart.removeBodyElement(paragraphPos);
|
|
|
|
}
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
2021-06-30 16:17:17 +02:00
|
|
|
}
|
2022-11-08 13:39:23 +01:00
|
|
|
|
2022-02-08 08:44:55 +01:00
|
|
|
return returnedValue;
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
|
|
|
|
2022-11-08 13:39:23 +01:00
|
|
|
private void createHeadersInTable(List<Field> fields, XWPFTable table, VisibilityRuleService visibilityRuleService) {
|
|
|
|
boolean atLeastOneHeader = false;
|
|
|
|
List<Field> tempFields = fields.stream().sorted(Comparator.comparingInt(Field::getOrdinal)).collect(Collectors.toList());
|
|
|
|
int index = 0;
|
|
|
|
XWPFTableRow row = table.getRow(0);
|
|
|
|
for (Field field: tempFields) {
|
|
|
|
if (visibilityRuleService.isElementVisible(field.getId()) && field.getExport()) {
|
|
|
|
XWPFTableCell cell;
|
|
|
|
if(index == 0) {
|
|
|
|
cell = row.getCell(0);
|
|
|
|
} else {
|
|
|
|
cell = row.createCell();
|
|
|
|
}
|
|
|
|
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.valueOf("CENTER"));
|
2023-10-27 17:46:34 +02:00
|
|
|
String label = ((BaseFieldDataEntity) field.getData()).getLabel();
|
2022-11-08 13:39:23 +01:00
|
|
|
if(label != null && label != "") {
|
|
|
|
XWPFParagraph paragraph = cell.getParagraphs().get(0);
|
|
|
|
paragraph.setIndentationFirstLine(50);
|
|
|
|
XWPFRun run = paragraph.createRun();
|
|
|
|
run.setText(label);
|
|
|
|
run.setBold(true);
|
|
|
|
run.setFontSize(12);
|
|
|
|
paragraph.setAlignment(ParagraphAlignment.CENTER);
|
|
|
|
paragraph.setSpacingBefore(100);
|
|
|
|
|
|
|
|
atLeastOneHeader = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!atLeastOneHeader) {
|
|
|
|
table.removeRow(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Boolean createFieldsInTable(List<Field> fields, XWPFTableRow mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService, boolean hasMultiplicityItems, int numOfRows) {
|
|
|
|
int numOfCells = 0;
|
|
|
|
boolean hasValue = false;
|
|
|
|
List<Field> tempFields = fields.stream().sorted(Comparator.comparingInt(Field::getOrdinal)).collect(Collectors.toList());
|
|
|
|
for (Field field: tempFields) {
|
|
|
|
if (visibilityRuleService.isElementVisible(field.getId()) && field.getExport()) {
|
|
|
|
if (!createListing) {
|
|
|
|
try {
|
2023-10-27 17:46:34 +02:00
|
|
|
if(field.getViewStyle().getFieldType().equals("upload")){
|
2022-11-08 13:39:23 +01:00
|
|
|
boolean isImage = false;
|
2024-01-30 15:31:03 +01:00
|
|
|
for(UploadDataEntity.UploadDataOptionEntity type: ((UploadDataEntity)field.getData()).getTypes()){
|
2022-11-08 13:39:23 +01:00
|
|
|
String fileFormat = type.getValue();
|
|
|
|
if(IMAGE_TYPE_MAP.containsKey(fileFormat)){
|
|
|
|
isImage = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isImage){
|
|
|
|
if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
|
|
|
|
XWPFParagraph paragraph = addCellContent(mapper.convertValue(field.getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId, 0, numOfRows, numOfCells, 0);
|
|
|
|
if (paragraph != null) {
|
|
|
|
hasValue = true;
|
|
|
|
}
|
|
|
|
if(hasMultiplicityItems){
|
|
|
|
hasMultiplicityItems = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
|
|
|
|
this.indent = indent;
|
|
|
|
String format = this.formatter(field);
|
2023-10-27 17:46:34 +02:00
|
|
|
if (field.getViewStyle().getFieldType().equals("tags")) {
|
2022-11-08 13:39:23 +01:00
|
|
|
format = getCommaSeparatedFormatsFromJson(format, "name");
|
2023-10-27 17:46:34 +02:00
|
|
|
} else if (field.getViewStyle().getFieldType().equals("combobox") && field.getData() instanceof AutoCompleteDataEntity) {
|
2022-11-08 13:39:23 +01:00
|
|
|
format = getCommaSeparatedFormatsFromJson(format, "label");
|
|
|
|
}
|
2023-10-27 17:46:34 +02:00
|
|
|
boolean isResearcher = field.getViewStyle().getFieldType().equals("researchers");
|
2022-11-08 13:39:23 +01:00
|
|
|
if(format != null && !format.isEmpty()){
|
|
|
|
Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete");
|
|
|
|
boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete;
|
|
|
|
boolean arrayStringFormat = format.charAt(0) == '[';
|
|
|
|
if(arrayStringFormat || isMultiAutoComplete){
|
|
|
|
List<String> values = (arrayStringFormat) ? Arrays.asList(format.substring(1, format.length() - 1).split(",[ ]*")) : Arrays.asList(format.split(",[ ]*"));
|
|
|
|
if(values.size() > 1) {
|
|
|
|
boolean orcidResearcher;
|
|
|
|
int numOfValuesInCell = 0;
|
|
|
|
for (String val : values) {
|
|
|
|
orcidResearcher = false;
|
|
|
|
String orcId = null;
|
|
|
|
if(isResearcher && val.contains("orcid:")){
|
|
|
|
orcId = val.substring(val.indexOf(':') + 1, val.indexOf(')'));
|
|
|
|
val = val.substring(0, val.indexOf(':') + 1) + " ";
|
|
|
|
orcidResearcher = true;
|
|
|
|
}
|
|
|
|
format = "• " + val;
|
|
|
|
if(hasMultiplicityItems){
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.getCell(mainDocumentPart.getTableCells().size()).addParagraph();
|
|
|
|
paragraph.createRun().setText(format);
|
|
|
|
if(orcidResearcher){
|
|
|
|
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
|
|
|
run.setText(orcId);
|
|
|
|
run.setUnderline(UnderlinePatterns.SINGLE);
|
|
|
|
run.setColor("0000FF");
|
|
|
|
paragraph.createRun().setText(")");
|
|
|
|
}
|
|
|
|
hasMultiplicityItems = false;
|
|
|
|
}
|
|
|
|
else{
|
2023-10-27 17:46:34 +02:00
|
|
|
XWPFParagraph paragraph = addCellContent(format, mainDocumentPart, field.getViewStyle().getFieldType().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent, numOfRows, numOfCells, numOfValuesInCell);
|
2022-11-08 13:39:23 +01:00
|
|
|
numOfValuesInCell++;
|
|
|
|
if(orcidResearcher){
|
|
|
|
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
|
|
|
run.setText(orcId);
|
|
|
|
run.setUnderline(UnderlinePatterns.SINGLE);
|
|
|
|
run.setColor("0000FF");
|
|
|
|
paragraph.createRun().setText(")");
|
|
|
|
}
|
|
|
|
if (paragraph != null) {
|
|
|
|
hasValue = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
format = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(values.size() == 1){
|
|
|
|
format = values.get(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(hasMultiplicityItems && format != null){
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.getCell(mainDocumentPart.getTableCells().size()).addParagraph();
|
|
|
|
paragraph.createRun().setText(format);
|
|
|
|
hasMultiplicityItems = false;
|
|
|
|
hasValue = true;
|
|
|
|
}
|
|
|
|
else{
|
2023-10-27 17:46:34 +02:00
|
|
|
XWPFParagraph paragraph = addCellContent(format, mainDocumentPart, field.getViewStyle().getFieldType().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent, numOfRows, numOfCells, 0);
|
2022-11-08 13:39:23 +01:00
|
|
|
if (paragraph != null) {
|
|
|
|
hasValue = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
numOfCells++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasValue;
|
|
|
|
}
|
|
|
|
|
2023-06-21 11:00:20 +02:00
|
|
|
private void createHypeLink(XWPFDocument mainDocumentPart, String format, String pidType, String pid, boolean hasMultiplicityItems, boolean isMultiAutoComplete){
|
|
|
|
PidLink pidLink = this.configLoader.getPidLinks().getPidLinks().stream().filter(pl -> pl.getPid().equals(pidType)).findFirst().orElse(null);
|
|
|
|
if (pidLink != null) {
|
|
|
|
if (!hasMultiplicityItems) {
|
|
|
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
|
|
|
paragraph.setIndentFromLeft(400 * indent);
|
|
|
|
if (numId != null) {
|
|
|
|
paragraph.setNumID(numId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isMultiAutoComplete) {
|
|
|
|
XWPFRun r = mainDocumentPart.getLastParagraph().createRun();
|
|
|
|
r.setText("• ");
|
|
|
|
}
|
|
|
|
XWPFHyperlinkRun run = mainDocumentPart.getLastParagraph().createHyperlinkRun(pidLink.getLink().replace("{pid}", pid));
|
|
|
|
run.setText(format);
|
|
|
|
run.setUnderline(UnderlinePatterns.SINGLE);
|
|
|
|
run.setColor("0000FF");
|
|
|
|
run.setFontSize(11);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
String newFormat = (isMultiAutoComplete) ? "• " + format : format;
|
|
|
|
if (hasMultiplicityItems) {
|
|
|
|
mainDocumentPart.getLastParagraph().createRun().setText(newFormat);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addParagraphContent(newFormat, mainDocumentPart, ParagraphStyle.TEXT, numId, indent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 15:27:47 +02:00
|
|
|
private Boolean createFields(List<Field> fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService, boolean hasMultiplicityItems) {
|
2018-03-01 10:14:10 +01:00
|
|
|
if (createListing) this.addListing(mainDocumentPart, indent, false, false);
|
2021-06-30 16:17:17 +02:00
|
|
|
boolean hasValue = false;
|
2021-09-27 17:11:55 +02:00
|
|
|
List<Field> tempFields = fields.stream().sorted(Comparator.comparingInt(Field::getOrdinal)).collect(Collectors.toList());
|
|
|
|
for (Field field: tempFields) {
|
2022-06-07 10:00:13 +02:00
|
|
|
if (visibilityRuleService.isElementVisible(field.getId()) && field.getExport()) {
|
2018-03-05 17:18:45 +01:00
|
|
|
if (!createListing) {
|
2018-10-19 11:59:54 +02:00
|
|
|
try {
|
2023-10-27 17:46:34 +02:00
|
|
|
if(field.getViewStyle().getFieldType().equals("upload")){
|
2022-03-17 09:47:50 +01:00
|
|
|
boolean isImage = false;
|
2024-01-30 15:31:03 +01:00
|
|
|
for(UploadDataEntity.UploadDataOptionEntity type: ((UploadDataEntity)field.getData()).getTypes()){
|
2022-03-17 09:47:50 +01:00
|
|
|
String fileFormat = type.getValue();
|
2022-03-22 13:03:22 +01:00
|
|
|
if(IMAGE_TYPE_MAP.containsKey(fileFormat)){
|
2022-03-17 09:47:50 +01:00
|
|
|
isImage = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isImage){
|
2022-06-08 15:27:47 +02:00
|
|
|
if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
XWPFParagraph paragraph = addParagraphContent(mapper.convertValue(field.getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId, 0);
|
2022-03-17 09:47:50 +01:00
|
|
|
if (paragraph != null) {
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
|
|
// number.setVal(BigInteger.valueOf(indent));
|
2022-03-17 09:47:50 +01:00
|
|
|
hasValue = true;
|
|
|
|
}
|
2022-06-08 15:27:47 +02:00
|
|
|
if(hasMultiplicityItems){
|
|
|
|
hasMultiplicityItems = false;
|
|
|
|
}
|
2022-03-17 09:47:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
|
2021-11-09 16:44:47 +01:00
|
|
|
this.indent = indent;
|
2021-12-29 14:24:46 +01:00
|
|
|
String format = this.formatter(field);
|
2023-10-27 17:46:34 +02:00
|
|
|
if (field.getViewStyle().getFieldType().equals("tags")) {
|
2022-03-22 13:03:22 +01:00
|
|
|
format = getCommaSeparatedFormatsFromJson(format, "name");
|
2023-10-27 17:46:34 +02:00
|
|
|
} else if (field.getViewStyle().getFieldType().equals("combobox") && field.getData() instanceof AutoCompleteDataEntity) {
|
2022-03-22 13:03:22 +01:00
|
|
|
format = getCommaSeparatedFormatsFromJson(format, "label");
|
|
|
|
}
|
2023-10-27 17:46:34 +02:00
|
|
|
switch (field.getViewStyle().getFieldType().getValue()) {
|
2023-06-21 11:00:20 +02:00
|
|
|
case "organizations":
|
|
|
|
case "externalDatasets":
|
|
|
|
case "publications":
|
|
|
|
if(format != null && !format.isEmpty()){
|
|
|
|
Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete");
|
|
|
|
boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete;
|
|
|
|
if(!isMultiAutoComplete){
|
|
|
|
Map<String, String> value = mapper.readValue((String)field.getValue(), Map.class);
|
2022-06-08 15:27:47 +02:00
|
|
|
if(hasMultiplicityItems){
|
2023-06-21 11:00:20 +02:00
|
|
|
createHypeLink(mainDocumentPart, format, value.get("pidTypeField"), value.get("pid"), true, false);
|
2022-06-08 15:27:47 +02:00
|
|
|
hasMultiplicityItems = false;
|
|
|
|
}
|
|
|
|
else{
|
2023-06-21 11:00:20 +02:00
|
|
|
createHypeLink(mainDocumentPart, format, value.get("pidTypeField"), value.get("pid"), false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
|
|
|
List<Map<String, Object>> values = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
values = Arrays.asList(mapper.readValue(field.getValue().toString(), HashMap[].class));
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
Map <String, Object> map = new HashMap<>();
|
|
|
|
map.put("label", field.getValue());
|
|
|
|
values.add(map);
|
|
|
|
}
|
|
|
|
if (values.size() > 1) {
|
|
|
|
for (Map<String, Object> value : values) {
|
|
|
|
if(hasMultiplicityItems){
|
|
|
|
createHypeLink(mainDocumentPart, (String) value.get("name"), (String) value.get("pidTypeField"), (String) value.get("pid"), true, true);
|
|
|
|
hasMultiplicityItems = false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
createHypeLink(mainDocumentPart, (String) value.get("name"), (String) value.get("pidTypeField"), (String) value.get("pid"), false, true);
|
|
|
|
}
|
2022-06-13 14:16:48 +02:00
|
|
|
}
|
2023-06-21 11:00:20 +02:00
|
|
|
}
|
|
|
|
else if(values.size() == 1){
|
|
|
|
if(hasMultiplicityItems){
|
|
|
|
createHypeLink(mainDocumentPart, format, (String) values.get(0).get("pidTypeField"), (String) values.get(0).get("pid"), true, false);
|
|
|
|
hasMultiplicityItems = false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
createHypeLink(mainDocumentPart, format, (String) values.get(0).get("pidTypeField"), (String) values.get(0).get("pid"), false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hasValue = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2023-10-27 17:46:34 +02:00
|
|
|
boolean isResearcher = field.getViewStyle().getFieldType().equals("researchers");
|
2023-06-21 11:00:20 +02:00
|
|
|
if(format != null && !format.isEmpty()){
|
|
|
|
Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete");
|
|
|
|
boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete;
|
|
|
|
boolean arrayStringFormat = format.charAt(0) == '[';
|
|
|
|
if(arrayStringFormat || isMultiAutoComplete){
|
|
|
|
List<String> values = (arrayStringFormat) ? Arrays.asList(format.substring(1, format.length() - 1).split(",[ ]*")) : Arrays.asList(format.split(",[ ]*"));
|
|
|
|
if(values.size() > 1) {
|
|
|
|
boolean orcidResearcher;
|
|
|
|
for (String val : values) {
|
|
|
|
orcidResearcher = false;
|
|
|
|
String orcId = null;
|
|
|
|
if(isResearcher && val.contains("orcid:")){
|
|
|
|
orcId = val.substring(val.indexOf(':') + 1, val.indexOf(')'));
|
|
|
|
val = val.substring(0, val.indexOf(':') + 1) + " ";
|
|
|
|
orcidResearcher = true;
|
|
|
|
}
|
|
|
|
format = "• " + val;
|
|
|
|
if(hasMultiplicityItems){
|
|
|
|
mainDocumentPart.getLastParagraph().createRun().setText(format);
|
|
|
|
if(orcidResearcher){
|
|
|
|
XWPFHyperlinkRun run = mainDocumentPart.getLastParagraph().createHyperlinkRun("https://orcid.org/" + orcId);
|
|
|
|
run.setText(orcId);
|
|
|
|
run.setUnderline(UnderlinePatterns.SINGLE);
|
|
|
|
run.setColor("0000FF");
|
|
|
|
mainDocumentPart.getLastParagraph().createRun().setText(")");
|
|
|
|
}
|
|
|
|
hasMultiplicityItems = false;
|
|
|
|
}
|
|
|
|
else{
|
2023-10-27 17:46:34 +02:00
|
|
|
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getFieldType().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
|
2023-06-21 11:00:20 +02:00
|
|
|
if(orcidResearcher){
|
|
|
|
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
|
|
|
run.setText(orcId);
|
|
|
|
run.setUnderline(UnderlinePatterns.SINGLE);
|
|
|
|
run.setColor("0000FF");
|
|
|
|
paragraph.createRun().setText(")");
|
|
|
|
}
|
|
|
|
if (paragraph != null) {
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
|
|
// number.setVal(BigInteger.valueOf(indent));
|
2023-06-21 11:00:20 +02:00
|
|
|
hasValue = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
format = null;
|
2022-06-08 15:27:47 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-21 11:00:20 +02:00
|
|
|
else if(values.size() == 1){
|
|
|
|
format = values.get(0);
|
|
|
|
}
|
2022-06-08 15:27:47 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-21 11:00:20 +02:00
|
|
|
if (format != null) {
|
|
|
|
if (hasMultiplicityItems) {
|
|
|
|
mainDocumentPart.getLastParagraph().createRun().setText(format);
|
|
|
|
hasMultiplicityItems = false;
|
|
|
|
hasValue = true;
|
|
|
|
}
|
|
|
|
else {
|
2023-10-27 17:46:34 +02:00
|
|
|
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getFieldType().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
|
2023-06-21 11:00:20 +02:00
|
|
|
if (paragraph != null) {
|
|
|
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
|
|
// number.setVal(BigInteger.valueOf(indent));
|
|
|
|
hasValue = true;
|
|
|
|
}
|
|
|
|
}
|
2022-06-08 15:27:47 +02:00
|
|
|
}
|
2021-10-06 17:16:39 +02:00
|
|
|
}
|
2021-06-30 16:17:17 +02:00
|
|
|
}
|
2018-10-19 11:59:54 +02:00
|
|
|
} catch (IOException e) {
|
2020-01-16 16:46:24 +01:00
|
|
|
logger.error(e.getMessage(), e);
|
2018-10-19 11:59:54 +02:00
|
|
|
}
|
2018-03-05 17:18:45 +01:00
|
|
|
}
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
2021-06-30 16:17:17 +02:00
|
|
|
}
|
|
|
|
return hasValue;
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
|
|
|
|
2022-03-22 13:03:22 +01:00
|
|
|
private String getCommaSeparatedFormatsFromJson(String format, String attribute){
|
|
|
|
if((format == null || format.isEmpty()) || (attribute == null || attribute.isEmpty())){
|
|
|
|
return null;
|
|
|
|
}
|
2022-03-24 08:43:13 +01:00
|
|
|
try {
|
|
|
|
JSONArray array = new JSONArray(JavaToJson.objectStringToJson(format));
|
|
|
|
StringBuilder multipleFormats = new StringBuilder();
|
|
|
|
for (int i = 0; i < array.length(); i++) {
|
|
|
|
multipleFormats.append(array.getJSONObject(i).getString(attribute)).append(", ");
|
|
|
|
}
|
|
|
|
if (multipleFormats.length() > 0) {
|
|
|
|
multipleFormats.setLength(multipleFormats.length() - 2);
|
|
|
|
}
|
|
|
|
return multipleFormats.toString();
|
|
|
|
} catch (JSONException e) {
|
|
|
|
return format;
|
2022-03-22 13:03:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 13:39:23 +01:00
|
|
|
public XWPFParagraph addCellContent(Object content, XWPFTableRow mainDocumentPart, ParagraphStyle style, BigInteger numId, int indent, int numOfRows, int numOfCells, int numOfValuesInCell) {
|
|
|
|
if (content != null) {
|
|
|
|
if (content instanceof String && ((String)content).isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
this.indent = indent;
|
|
|
|
XWPFTableCell cell;
|
|
|
|
if(numOfRows > 0 || numOfValuesInCell > 0) {
|
|
|
|
cell = mainDocumentPart.getCell(numOfCells);
|
|
|
|
} else {
|
|
|
|
cell = mainDocumentPart.createCell();
|
|
|
|
}
|
|
|
|
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.valueOf("CENTER"));
|
|
|
|
if(numOfValuesInCell == 0) {
|
|
|
|
cell.removeParagraph(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
XWPFParagraph paragraph = this.optionsInTable.get(style).apply(cell, content);
|
|
|
|
if (paragraph != null) {
|
|
|
|
paragraph.setAlignment(ParagraphAlignment.CENTER);
|
|
|
|
paragraph.setSpacingBefore(100);
|
|
|
|
if (numId != null) {
|
|
|
|
paragraph.setNumID(numId);
|
|
|
|
}
|
|
|
|
return paragraph;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
public XWPFParagraph addParagraphContent(Object content, XWPFDocument mainDocumentPart, ParagraphStyle style, BigInteger numId, int indent) {
|
2022-06-23 14:32:05 +02:00
|
|
|
// this.indent = 0;
|
2022-03-17 09:47:50 +01:00
|
|
|
if (content != null) {
|
|
|
|
if (content instanceof String && ((String)content).isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
this.indent = indent;
|
2022-03-17 09:47:50 +01:00
|
|
|
XWPFParagraph paragraph = this.options.get(style).apply(mainDocumentPart, content);
|
2021-10-05 16:58:46 +02:00
|
|
|
if (paragraph != null) {
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
paragraph.setIndentFromLeft(400*indent);
|
2021-10-05 16:58:46 +02:00
|
|
|
if (numId != null) {
|
|
|
|
paragraph.setNumID(numId);
|
|
|
|
}
|
|
|
|
return paragraph;
|
2021-06-30 16:17:17 +02:00
|
|
|
}
|
2018-10-18 11:33:13 +02:00
|
|
|
}
|
2021-06-30 16:17:17 +02:00
|
|
|
return null;
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
|
|
|
|
2019-12-17 12:08:01 +01:00
|
|
|
private void addListing(XWPFDocument document, int indent, Boolean question, Boolean hasIndication) {
|
2018-03-01 10:14:10 +01:00
|
|
|
CTLvl cTLvl = this.cTAbstractNum.addNewLvl();
|
|
|
|
|
|
|
|
String textLevel = "";
|
|
|
|
for (int i = 0; i <= indent; i++) {
|
|
|
|
textLevel += "%" + (i + 1) + ".";
|
|
|
|
}
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
|
2018-03-01 10:14:10 +01:00
|
|
|
if (question) {
|
|
|
|
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
// cTLvl.addNewLvlText().setVal("");
|
2018-03-05 17:18:45 +01:00
|
|
|
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
2018-03-01 10:14:10 +01:00
|
|
|
} else if (!question && hasIndication) {
|
|
|
|
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
// cTLvl.addNewLvlText().setVal("");
|
2018-03-05 17:18:45 +01:00
|
|
|
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
|
|
|
if (!question && !hasIndication) {
|
|
|
|
cTLvl.addNewNumFmt().setVal(STNumberFormat.NONE);
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
// cTLvl.addNewLvlText().setVal("");
|
2018-03-05 17:18:45 +01:00
|
|
|
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 12:08:01 +01:00
|
|
|
private String formatter(Field field) throws IOException {
|
2022-01-24 10:30:03 +01:00
|
|
|
if (field.getValue() == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2023-10-27 17:46:34 +02:00
|
|
|
switch (field.getViewStyle().getFieldType()) {
|
|
|
|
case RESEARCHERS:
|
|
|
|
// case "projects": //TODO: Description Templatedefinition
|
|
|
|
case ORGANIZATIONS:
|
|
|
|
case EXTERNAL_DATASETS:
|
|
|
|
case DATA_REPOSITORIES:
|
|
|
|
case PUB_REPOSITORIES:
|
|
|
|
case JOURNAL_REPOSITORIES:
|
|
|
|
case TAXONOMIES:
|
|
|
|
case LICENSES:
|
|
|
|
case PUBLICATIONS:
|
|
|
|
case REGISTRIES:
|
|
|
|
case SERVICES:
|
|
|
|
case TAGS:
|
2024-01-30 15:31:03 +01:00
|
|
|
// case CURRENCY:
|
|
|
|
// comboboxType = FieldDataComboBoxType.Autocomplete;
|
|
|
|
// case COMBO_BOX: {
|
|
|
|
// if (comboboxType == null) {
|
|
|
|
// comboboxType = ((ComboBoxDataEntity) field.getData()).getFieldSubType();
|
|
|
|
// }
|
|
|
|
// if (comboboxType.equals(FieldDataComboBoxType.Autocomplete)) {
|
|
|
|
// mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
|
|
|
// if (field.getValue() == null) return null;
|
|
|
|
// List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
|
// if (!field.getValue().equals("") && field.getValue().toString() != null) {
|
|
|
|
// try {
|
|
|
|
// mapList = Arrays.asList(mapper.readValue(field.getValue().toString(), HashMap[].class));
|
|
|
|
// }catch (Exception e) {
|
|
|
|
// // logger.warn(e.getMessage(), e);
|
|
|
|
// // logger.info("Moving to fallback parsing");
|
|
|
|
// Map <String, Object> map = new HashMap<>();
|
|
|
|
// map.put("label", field.getValue().toString());
|
|
|
|
// mapList.add(map);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// StringBuilder sb = new StringBuilder();
|
|
|
|
// int index = 0;
|
|
|
|
// for (Map<String, Object> map: mapList) {
|
|
|
|
// for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
|
// if (entry.getValue() != null && (entry.getKey().equals("label") || entry.getKey().equals("description") || entry.getKey().equals("name"))) {
|
|
|
|
// sb.append(entry.getValue());
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// if (index != mapList.size() - 1) sb.append(", ");
|
|
|
|
// index++;
|
|
|
|
// }
|
|
|
|
// return sb.toString();
|
|
|
|
// } else if (comboboxType.equals(FieldDataComboBoxType.Wordlist)) {
|
|
|
|
// WordListDataEntity wordListDataEntity = (WordListDataEntity) field.getData();
|
|
|
|
// if (field.getValue() != null){
|
|
|
|
// ComboBoxDataEntity.Option selectedOption = null;
|
|
|
|
// if (!wordListDataEntity.getOptions().isEmpty()) {
|
|
|
|
// for (ComboBoxDataEntity.Option option : wordListDataEntity.getOptions()) {
|
|
|
|
// if (option.getValue().equals(field.getValue())) {
|
|
|
|
// selectedOption = option;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return selectedOption != null ? selectedOption.getLabel() : field.getValue().toString();
|
|
|
|
// }
|
|
|
|
// return "";
|
|
|
|
// }
|
|
|
|
// }
|
2023-10-27 17:46:34 +02:00
|
|
|
case BOOLEAN_DECISION:
|
2018-10-19 11:59:54 +02:00
|
|
|
if (field.getValue() != null && field.getValue().equals("true")) return "Yes";
|
2021-07-19 13:08:48 +02:00
|
|
|
if (field.getValue() != null && field.getValue().equals("false")) return "No";
|
|
|
|
return null;
|
2023-10-27 17:46:34 +02:00
|
|
|
case RADIO_BOX:
|
2020-07-23 11:01:37 +02:00
|
|
|
return field.getValue() != null ? field.getValue().toString() : null;
|
2023-10-27 17:46:34 +02:00
|
|
|
case CHECK_BOX:
|
2024-01-08 15:10:29 +01:00
|
|
|
LabelDataEntity data = (LabelDataEntity) field.getData();
|
2018-10-22 12:34:39 +02:00
|
|
|
if (field.getValue() == null || field.getValue().equals("false")) return null;
|
2018-10-19 11:59:54 +02:00
|
|
|
return data.getLabel();
|
2023-10-27 17:46:34 +02:00
|
|
|
case DATE_PICKER:{
|
2021-11-24 15:41:01 +01:00
|
|
|
Instant instant;
|
2022-01-24 10:30:03 +01:00
|
|
|
if (!((String)field.getValue()).isEmpty()) {
|
|
|
|
try {
|
|
|
|
instant = Instant.parse((String) field.getValue());
|
|
|
|
} catch (DateTimeParseException ex) {
|
2022-02-10 12:21:21 +01:00
|
|
|
instant = LocalDate.parse((String) field.getValue()).atStartOfDay().toInstant(ZoneOffset.UTC);
|
2022-01-24 10:30:03 +01:00
|
|
|
}
|
|
|
|
return field.getValue() != null ? DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(instant) : "";
|
2021-11-24 15:41:01 +01:00
|
|
|
}
|
2022-01-24 10:30:03 +01:00
|
|
|
return (String) field.getValue();
|
2021-11-24 15:41:01 +01:00
|
|
|
}
|
2023-10-27 17:46:34 +02:00
|
|
|
case FREE_TEXT:
|
|
|
|
case TEXT_AREA:
|
|
|
|
case RICH_TEXT_AREA:
|
2020-02-26 12:37:54 +01:00
|
|
|
return field.getValue() != null ? field.getValue().toString(): "";
|
2023-10-27 17:46:34 +02:00
|
|
|
case DATASET_IDENTIFIER:
|
|
|
|
case VALIDATION:
|
2021-08-27 11:58:06 +02:00
|
|
|
if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
|
2021-06-30 16:17:17 +02:00
|
|
|
Map<String, String> identifierData;
|
|
|
|
try {
|
|
|
|
identifierData = mapper.readValue(field.getValue().toString(), HashMap.class);
|
2021-08-27 11:58:06 +02:00
|
|
|
} catch (Exception ex) {
|
|
|
|
// logger.warn(ex.getLocalizedMessage(), ex);
|
|
|
|
// logger.info("Reverting to custom parsing");
|
|
|
|
identifierData = customParse(field.getValue().toString());
|
2021-04-13 09:46:06 +02:00
|
|
|
}
|
2023-06-21 11:00:20 +02:00
|
|
|
return "id: " + identifierData.get("identifier") + ", Type: " + identifierData.get("type");
|
2021-04-13 09:46:06 +02:00
|
|
|
}
|
2021-06-30 16:17:17 +02:00
|
|
|
return "";
|
2018-10-19 11:59:54 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-02-15 08:52:44 +01:00
|
|
|
private boolean hasVisibleFields(FieldSet compositeFields, VisibilityRuleService visibilityRuleService) {
|
2022-06-07 10:00:13 +02:00
|
|
|
return compositeFields.getFields().stream().anyMatch(field -> visibilityRuleService.isElementVisible(field.getId()) && field.getExport());
|
2019-02-15 08:52:44 +01:00
|
|
|
}
|
2021-08-27 11:58:06 +02:00
|
|
|
|
|
|
|
private Map<String, String> customParse(String value) {
|
|
|
|
Map<String, String> result = new LinkedHashMap<>();
|
|
|
|
String parsedValue = value.replaceAll("[^a-zA-Z0-9\\s:=,]", "");
|
|
|
|
StringTokenizer commaTokens = new StringTokenizer(parsedValue, ", ");
|
|
|
|
String delimeter = parsedValue.contains("=") ? "=" : ":";
|
|
|
|
while (commaTokens.hasMoreTokens()) {
|
|
|
|
String token = commaTokens.nextToken();
|
|
|
|
StringTokenizer delimiterTokens = new StringTokenizer(token, delimeter);
|
|
|
|
result.put(delimiterTokens.nextToken(), delimiterTokens.nextToken());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2022-06-13 14:16:48 +02:00
|
|
|
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-11-16 13:01:39 +01:00
|
|
|
public void fillFirstPage(DmpEntity dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) {
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
int parPos = 0;
|
|
|
|
int descrParPos = -1;
|
|
|
|
XWPFParagraph descrPar = null;
|
2022-06-13 14:16:48 +02:00
|
|
|
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){
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
if(text.contains("{ARGOS.DMP.TITLE}")) {
|
|
|
|
text = text.replace("{ARGOS.DMP.TITLE}", dmpEntity.getLabel());
|
2022-06-13 14:16:48 +02:00
|
|
|
r.setText(text, 0);
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
} else if(text.contains("{ARGOS.DMP.VERSION}")) {
|
|
|
|
text = text.replace("{ARGOS.DMP.VERSION}", "Version " + dmpEntity.getVersion());
|
2022-06-13 14:16:48 +02:00
|
|
|
r.setText(text, 0);
|
2023-11-06 15:17:57 +01:00
|
|
|
} else if(descriptionEntityEntity != null && text.contains("{ARGOS.DATASET.TITLE}")) {
|
|
|
|
text = text.replace("{ARGOS.DATASET.TITLE}", descriptionEntityEntity.getLabel());
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
r.setText(text, 0);
|
2023-04-05 10:13:26 +02:00
|
|
|
// } else if(text.equals("Description") && ((!isDataset && (dmpEntity == null || dmpEntity.getDescription() != null)) || (isDataset && (datasetEntity == null || datasetEntity.getDescription() == null)))) {
|
|
|
|
// r.setText("", 0);
|
2023-11-06 15:17:57 +01:00
|
|
|
} else if((dmpEntity != null && text.contains("{ARGOS.DMP.DESCRIPTION}") && !isDataset) || (descriptionEntityEntity != null && text.contains("{ARGOS.DATASET.DESCRIPTION}") && isDataset)) {
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
descrParPos = parPos;
|
|
|
|
descrPar = p;
|
2023-04-05 10:13:26 +02:00
|
|
|
if(dmpEntity != null && !isDataset) {
|
2023-02-28 10:01:44 +01:00
|
|
|
text = text.replace("{ARGOS.DMP.DESCRIPTION}", "");
|
2023-11-06 15:17:57 +01:00
|
|
|
} else if(descriptionEntityEntity != null && isDataset) {
|
2023-02-28 10:01:44 +01:00
|
|
|
text = text.replace("{ARGOS.DATASET.DESCRIPTION}", "");
|
|
|
|
}
|
2022-06-13 14:16:48 +02:00
|
|
|
r.setText(text, 0);
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
} else if(text.equals("{ARGOS.DMP.RESEARCHERS}")) {
|
|
|
|
String researchersNames = "";
|
2023-11-16 13:01:39 +01:00
|
|
|
//TODO
|
|
|
|
// Set<Researcher> researchers = dmpEntity.getResearchers();
|
|
|
|
// int i = 0;
|
|
|
|
// for(Researcher researcher : researchers){
|
|
|
|
// i++;
|
|
|
|
// researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : "");
|
|
|
|
// }
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
text = text.replace("{ARGOS.DMP.RESEARCHERS}", researchersNames);
|
|
|
|
r.setText(text, 0);
|
|
|
|
r.setFontSize(17);
|
|
|
|
} else if(text.equals("{ARGOS.DMP.ORGANIZATIONS}")) {
|
|
|
|
String organisationsNames = "";
|
2023-11-16 13:01:39 +01:00
|
|
|
//TODO
|
|
|
|
// Set<Organisation> organisations = dmpEntity.getOrganisations();
|
|
|
|
// int i = 0;
|
|
|
|
// for(Organisation organisation : organisations){
|
|
|
|
// i++;
|
|
|
|
// organisationsNames += organisation.getLabel() + (i < organisations.size() ? ", " : "");
|
|
|
|
// }
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
text = text.replace("{ARGOS.DMP.ORGANIZATIONS}", organisationsNames);
|
|
|
|
r.setText(text, 0);
|
|
|
|
r.setFontSize(17);
|
2022-06-13 14:16:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
parPos++;
|
|
|
|
}
|
2023-04-05 10:13:26 +02:00
|
|
|
|
|
|
|
if((descrParPos != -1) && (dmpEntity!=null) && (dmpEntity.getDescription() != null) && !isDataset) {
|
2023-02-28 10:01:44 +01:00
|
|
|
XmlCursor cursor = descrPar.getCTP().newCursor();
|
|
|
|
cursor.toNextSibling();
|
|
|
|
Document htmlDoc = Jsoup.parse(((String)dmpEntity.getDescription()).replaceAll("\n", "<br>"));
|
|
|
|
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(descrPar, 0, cursor);
|
|
|
|
NodeTraversor.traverse(htmlToWorldBuilder, htmlDoc);
|
|
|
|
}
|
2023-11-06 15:17:57 +01:00
|
|
|
if((descrParPos != -1) && (descriptionEntityEntity != null) && (descriptionEntityEntity.getDescription() != null) && isDataset) {
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
XmlCursor cursor = descrPar.getCTP().newCursor();
|
|
|
|
cursor.toNextSibling();
|
2023-11-06 15:17:57 +01:00
|
|
|
Document htmlDoc = Jsoup.parse(((String) descriptionEntityEntity.getDescription()).replaceAll("\n", "<br>"));
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(descrPar, 0, cursor);
|
|
|
|
NodeTraversor.traverse(htmlToWorldBuilder, htmlDoc);
|
2022-06-13 14:16:48 +02:00
|
|
|
}
|
|
|
|
|
#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.
2022-07-26 16:00:54 +02:00
|
|
|
|
2022-06-13 14:16:48 +02:00
|
|
|
XWPFTable tbl = document.getTables().get(0);
|
|
|
|
Iterator<XWPFTableRow> it = tbl.getRows().iterator();
|
|
|
|
it.next(); // skip first row
|
2023-11-16 13:01:39 +01:00
|
|
|
//TODO
|
|
|
|
// if(it.hasNext() && dmpEntity.getGrant() != null){
|
|
|
|
// 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();
|
|
|
|
// if(it.hasNext() && dmpEntity.getGrant() != null){
|
|
|
|
// 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);
|
|
|
|
// }
|
2022-06-13 14:16:48 +02:00
|
|
|
}
|
|
|
|
|
2023-11-16 13:01:39 +01:00
|
|
|
public void fillFooter(DmpEntity dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) {
|
2022-06-13 14:16:48 +02:00
|
|
|
document.getFooterList().forEach(xwpfFooter -> {
|
|
|
|
List<XWPFRun> runs = xwpfFooter.getParagraphs().get(0).getRuns();
|
|
|
|
if(runs != null){
|
|
|
|
for(XWPFRun r : runs){
|
|
|
|
String text = r.getText(0);
|
|
|
|
if(text != null){
|
|
|
|
if(text.contains("{ARGOS.DMP.TITLE}")){
|
|
|
|
text = text.replace("{ARGOS.DMP.TITLE}", dmpEntity.getLabel());
|
|
|
|
r.setText(text, 0);
|
|
|
|
}
|
2023-11-06 15:17:57 +01:00
|
|
|
if(text.contains("{ARGOS.DATASET.TITLE}") && descriptionEntityEntity != null){
|
|
|
|
text = text.replace("{ARGOS.DATASET.TITLE}", descriptionEntityEntity.getLabel());
|
2022-07-28 16:30:44 +02:00
|
|
|
r.setText(text, 0);
|
|
|
|
}
|
2023-11-16 13:01:39 +01:00
|
|
|
//TODO
|
|
|
|
// if(text.contains("{ARGOS.DMP.LICENSE}")){
|
|
|
|
// try{
|
|
|
|
// Map<String, String> license = ((Map<String, String>) mapper.readValue(dmpEntity.getExtraProperties(), Map.class).get("license"));
|
|
|
|
// text = text.replace("{ARGOS.DMP.LICENSE}", license.get("pid"));
|
|
|
|
// }
|
|
|
|
// catch (JsonProcessingException | NullPointerException e){
|
|
|
|
// text = text.replace("{ARGOS.DMP.LICENSE}", "License: -");
|
|
|
|
// }
|
|
|
|
// r.setText(text, 0);
|
|
|
|
// }
|
|
|
|
// if(text.contains("{ARGOS.DMP.DOI}")){
|
|
|
|
// if(dmpEntity.getDois() != null && !dmpEntity.getDois().isEmpty())
|
|
|
|
// text = text.replace("{ARGOS.DMP.DOI}", dmpEntity.getDois().iterator().next().getDoi());
|
|
|
|
// else
|
|
|
|
// text = text.replace("{ARGOS.DMP.DOI}", "-");
|
|
|
|
// r.setText(text, 0);
|
|
|
|
// }
|
2022-06-13 14:16:48 +02:00
|
|
|
if(text.contains("{ARGOS.DMP.LAST_MODIFIED}")){
|
|
|
|
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
|
2023-11-16 13:01:39 +01:00
|
|
|
text = text.replace("{ARGOS.DMP.LAST_MODIFIED}", formatter.format(dmpEntity.getUpdatedAt()));
|
2022-06-13 14:16:48 +02:00
|
|
|
r.setText(text, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-03-01 10:14:10 +01:00
|
|
|
}
|