1. export redesign based on new word template

2. orcid researchers in export are clickable
This commit is contained in:
Bernaldo Mihasi 2022-06-13 15:16:48 +03:00
parent 941cca8103
commit 0ac5902bfd
4 changed files with 225 additions and 92 deletions

View File

@ -173,13 +173,13 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
<version>4.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/fop -->

View File

@ -1190,43 +1190,45 @@ public class DataManagementPlanManager {
if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
throw new UnauthorisedException();
// DMP info on top of the document.
wordBuilder.addParagraphContent("Data Management Plan Information", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
// DMP title custom style.
wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.HEADER2, BigInteger.ZERO);
wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
wordBuilder.fillFirstPage(dmpEntity, document);
wordBuilder.addParagraphContent("Funder", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
if (dmpEntity.getGrant().getFunder() != null)
wordBuilder.addParagraphContent(dmpEntity.getGrant().getFunder().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
wordBuilder.addParagraphContent("Grant", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
wordBuilder.addParagraphContent(dmpEntity.getGrant().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
wordBuilder.addParagraphContent("Organisations", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
if (dmpEntity.getOrganisations().size() > 0) {
wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(Organisation::getLabel).collect(Collectors.joining(", "))
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
}
wordBuilder.addParagraphContent("Researchers", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
if (dmpEntity.getResearchers().size() > 0) {
wordBuilder.addParagraphContent(dmpEntity.getResearchers().stream().map(Researcher::getLabel).collect(Collectors.joining(", "))
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
}
/*wordBuilder.addParagraphContent("DMP Profile", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
if (dmpEntity.getProfile() != null){
wordBuilder.addParagraphContent(dmpEntity.getProfile().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
}*/
// Page break at the end of the DMP title.
XWPFParagraph parBreakDMP = document.createParagraph();
parBreakDMP.setPageBreak(true);
wordBuilder.addParagraphContent("Datasets", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
// Space below Datasets.
XWPFParagraph parBreakDatasets = document.createParagraph();
// // DMP info on top of the document.
// wordBuilder.addParagraphContent("Data Management Plan Information", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
// // DMP title custom style.
// wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.HEADER2, BigInteger.ZERO);
// wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
//
// wordBuilder.addParagraphContent("Funder", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
// if (dmpEntity.getGrant().getFunder() != null)
// wordBuilder.addParagraphContent(dmpEntity.getGrant().getFunder().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
//
// wordBuilder.addParagraphContent("Grant", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
// wordBuilder.addParagraphContent(dmpEntity.getGrant().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
//
// wordBuilder.addParagraphContent("Organisations", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
// if (dmpEntity.getOrganisations().size() > 0) {
// wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(Organisation::getLabel).collect(Collectors.joining(", "))
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
// }
//
// wordBuilder.addParagraphContent("Researchers", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
// if (dmpEntity.getResearchers().size() > 0) {
// wordBuilder.addParagraphContent(dmpEntity.getResearchers().stream().map(Researcher::getLabel).collect(Collectors.joining(", "))
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
// }
//
// /*wordBuilder.addParagraphContent("DMP Profile", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
// if (dmpEntity.getProfile() != null){
// wordBuilder.addParagraphContent(dmpEntity.getProfile().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
// }*/
//
// // Page break at the end of the DMP title.
// XWPFParagraph parBreakDMP = document.createParagraph();
// parBreakDMP.setPageBreak(true);
//
// wordBuilder.addParagraphContent("Datasets", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
// // Space below Datasets.
// XWPFParagraph parBreakDatasets = document.createParagraph();
final Boolean isFinalized = dmpEntity.getStatus() == DMP.DMPStatus.FINALISED.getValue();
final Boolean isPublic = dmpEntity.isPublic();
dmpEntity.getDataset().stream()
@ -1251,73 +1253,79 @@ public class DataManagementPlanManager {
//wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
XWPFParagraph datasetLabelParagraph = document.createParagraph();
datasetLabelParagraph.setStyle("Heading2");
datasetLabelParagraph.setSpacingBetween(1.0);
XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun();
runDatasetTitle1.setText("Title: ");
runDatasetTitle1.setBold(true);
runDatasetTitle1.setFontSize(12);
runDatasetTitle1.setColor("000000");
//runDatasetTitle1.setBold(true);
//runDatasetTitle1.setFontSize(12);
XWPFRun runDatasetTitle = datasetLabelParagraph.createRun();
runDatasetTitle.setText(datasetEntity.getLabel());
runDatasetTitle.setColor("2E75B6");
runDatasetTitle.setBold(true);
runDatasetTitle.setFontSize(12);
//runDatasetTitle.setColor("2E75B6");
//runDatasetTitle.setBold(true);
//runDatasetTitle.setFontSize(12);
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
datasetTemplateParagraph.setStyle("Heading3");
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
runDatasetTemplate1.setText("Template: ");
runDatasetTemplate1.setBold(true);
runDatasetTemplate1.setFontSize(12);
runDatasetTemplate1.setColor("000000");
//runDatasetTemplate1.setBold(true);
//runDatasetTemplate1.setFontSize(12);
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
runDatasetTemplate.setColor("2E75B6");
runDatasetTemplate.setBold(true);
runDatasetTemplate.setFontSize(12);
//runDatasetTemplate.setColor("2E75B6");
//runDatasetTemplate.setBold(true);
//runDatasetTemplate.setFontSize(12);
/*XWPFParagraph externalReferencesParagraph = document.createParagraph();
externalReferencesParagraph.setStyle("Heading3");
XWPFRun externalReferencesRun = externalReferencesParagraph.createRun();
externalReferencesRun.setText("External References");
externalReferencesRun.setColor("2E75B6");
externalReferencesRun.setBold(true);
externalReferencesRun.setFontSize(12);
document.createParagraph();
wordBuilder.addParagraphContent("Data Repositories", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
if (datasetEntity.getDatasetDataRepositories().size() > 0) {
wordBuilder.addParagraphContent(datasetEntity.getDatasetDataRepositories().stream().map(DatasetDataRepository::getDataRepository).map(DataRepository::getLabel).collect(Collectors.joining(", "))
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
}
wordBuilder.addParagraphContent("External Datasets", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
if (datasetEntity.getDatasetExternalDatasets().size() > 0) {
wordBuilder.addParagraphContent(datasetEntity.getDatasetExternalDatasets().stream().map(DatasetExternalDataset::getExternalDataset).map(ExternalDataset::getLabel).collect(Collectors.joining(", "))
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
}
wordBuilder.addParagraphContent("Registries", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
if (datasetEntity.getRegistries().size() > 0) {
wordBuilder.addParagraphContent(datasetEntity.getRegistries().stream().map(Registry::getLabel).collect(Collectors.joining(", "))
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
}
wordBuilder.addParagraphContent("Services", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
if (datasetEntity.getServices().size() > 0) {
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
}
*//*wordBuilder.addParagraphContent("Tags", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
if (datasetEntity.().size() > 0) {
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
, document, ParagraphStyle.HEADER4, BigInteger.ZERO);
}*/
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
// /*XWPFParagraph externalReferencesParagraph = document.createParagraph();
// externalReferencesParagraph.setStyle("Heading3");
// XWPFRun externalReferencesRun = externalReferencesParagraph.createRun();
// externalReferencesRun.setText("External References");
// externalReferencesRun.setColor("2E75B6");
// externalReferencesRun.setBold(true);
// externalReferencesRun.setFontSize(12);
//
// wordBuilder.addParagraphContent("Data Repositories", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
// if (datasetEntity.getDatasetDataRepositories().size() > 0) {
// wordBuilder.addParagraphContent(datasetEntity.getDatasetDataRepositories().stream().map(DatasetDataRepository::getDataRepository).map(DataRepository::getLabel).collect(Collectors.joining(", "))
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
// }
// wordBuilder.addParagraphContent("External Datasets", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
// if (datasetEntity.getDatasetExternalDatasets().size() > 0) {
// wordBuilder.addParagraphContent(datasetEntity.getDatasetExternalDatasets().stream().map(DatasetExternalDataset::getExternalDataset).map(ExternalDataset::getLabel).collect(Collectors.joining(", "))
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
// }
// wordBuilder.addParagraphContent("Registries", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
// if (datasetEntity.getRegistries().size() > 0) {
// wordBuilder.addParagraphContent(datasetEntity.getRegistries().stream().map(Registry::getLabel).collect(Collectors.joining(", "))
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
// }
// wordBuilder.addParagraphContent("Services", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
// if (datasetEntity.getServices().size() > 0) {
// wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
// }
// *//*wordBuilder.addParagraphContent("Tags", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
// if (datasetEntity.().size() > 0) {
// wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
// , document, ParagraphStyle.HEADER4, BigInteger.ZERO);
// }*/
//
//
// wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
// Dataset Description custom style.
XWPFParagraph datasetDescriptionParagraph = document.createParagraph();
datasetDescriptionParagraph.setStyle("Heading3");
datasetDescriptionParagraph.setSpacingBetween(1.5);
XWPFRun datasetDescriptionRun = datasetDescriptionParagraph.createRun();
datasetDescriptionRun.setText("Dataset Description");
datasetDescriptionRun.setColor("2E75B6");
datasetDescriptionRun.setBold(true);
datasetDescriptionRun.setFontSize(12);
//datasetDescriptionRun.setColor("2E75B6");
//datasetDescriptionRun.setBold(true);
datasetDescriptionRun.setFontSize(15);
PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity);
visibilityRuleService.setProperties(properties);
@ -1329,12 +1337,15 @@ public class DataManagementPlanManager {
}
// Page break at the end of the Dataset.
XWPFParagraph parBreakDataset = document.createParagraph();
parBreakDataset.setPageBreak(true);
});
// Removes the top empty headings.
for (int i = 0; i < 6; i++) {
document.removeBodyElement(0);
}
// // Removes the top empty headings.
// for (int i = 0; i < 6; i++) {
// document.removeBodyElement(0);
// }
wordBuilder.fillFooter(dmpEntity, document);
String fileName = "DMP_" + dmpEntity.getGrant().getLabel();
if (versioned) {

View File

@ -1,7 +1,11 @@
package eu.eudat.logic.utilities.documents.word;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Organisation;
import eu.eudat.data.entities.Researcher;
import eu.eudat.logic.services.forms.VisibilityRuleService;
import eu.eudat.logic.utilities.documents.types.ParagraphStyle;
import eu.eudat.logic.utilities.interfaces.ApplierWithValue;
@ -31,6 +35,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
@ -282,7 +288,7 @@ public class WordBuilder {
boolean hasMultiplicityItems = false;
int paragraphPos = -1;
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
XWPFParagraph paragraph = addParagraphContent(page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId);
XWPFParagraph paragraph = addParagraphContent("\t" + page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
@ -361,6 +367,7 @@ public class WordBuilder {
} else if (field.getViewStyle().getRenderStyle().equals("combobox") && field.getData() instanceof AutoCompleteData) {
format = getCommaSeparatedFormatsFromJson(format, "label");
}
boolean isResearcher = field.getViewStyle().getRenderStyle().equals("researchers");
if(format != null && !format.isEmpty()){
Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete");
boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete;
@ -368,14 +375,36 @@ public class WordBuilder {
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{
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
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) {
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
@ -390,7 +419,7 @@ public class WordBuilder {
}
}
}
if(hasMultiplicityItems){
if(hasMultiplicityItems && format != null){
mainDocumentPart.getLastParagraph().createRun().setText(format);
hasMultiplicityItems = false;
}
@ -600,4 +629,97 @@ public class WordBuilder {
}
return result;
}
public void fillFirstPage(DMP dmpEntity, 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.contains("{ARGOS.DMP.VERSION}")){
text = text.replace("{ARGOS.DMP.VERSION}", "VERSION " + dmpEntity.getVersion());
r.setText(text, 0);
}
else if(text.contains("{ARGOS.DMP.FUNDER}")){
text = text.replace("{ARGOS.DMP.FUNDER}", dmpEntity.getGrant().getFunder().getLabel());
r.setText(text, 0);
}
else if(text.contains("{ARGOS.DMP.GRANT}")){
text = text.replace("{ARGOS.DMP.GRANT}", dmpEntity.getGrant().getLabel());
r.setText(text, 0);
}
}
}
}
}
int researchers = dmpEntity.getResearchers().size();
int organizations = dmpEntity.getOrganisations().size();
if(researchers > 0 || organizations > 0){
XWPFTable tbl = document.getTables().get(0);
for(int i = (Integer.max(researchers, organizations) - 1); i > 0; i--)
tbl.createRow();
Iterator<XWPFTableRow> it = tbl.getRows().iterator();
it.next(); // skip first row
for(Researcher researcher : dmpEntity.getResearchers()){
if(it.hasNext()){
XWPFRun run = it.next().getCell(0).getParagraphs().get(0).createRun();
run.setText(researcher.getLabel());
run.setFontSize(17);
}
}
it = tbl.getRows().iterator();
it.next();
for(Organisation organisation : dmpEntity.getOrganisations()){
if(it.hasNext()){
XWPFParagraph p = it.next().getCell(1).getParagraphs().get(0);
XWPFRun run = p.createRun();
run.setText(organisation.getLabel());
run.setFontSize(17);
p.setAlignment(ParagraphAlignment.RIGHT);
}
}
}
}
public void fillFooter(DMP dmpEntity, XWPFDocument document) {
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);
}
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}")){
String doi = dmpEntity.getDoi();
if(doi != null)
text = text.replace("{ARGOS.DMP.DOI}", doi);
else
text = text.replace("{ARGOS.DMP.DOI}", "-");
r.setText(text, 0);
}
if(text.contains("{ARGOS.DMP.LAST_MODIFIED}")){
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
text = text.replace("{ARGOS.DMP.LAST_MODIFIED}", formatter.format(dmpEntity.getModified()));
r.setText(text, 0);
}
}
}
}
});
}
}