Adds "External References" on DMP and Dataset docx export and "Funder" and "Grand" on DMP docx export.
This commit is contained in:
parent
389502ea3c
commit
5cd8b391a7
|
@ -187,12 +187,6 @@ public class DataManagementPlanManager {
|
|||
if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
|
||||
throw new UnauthorisedException();
|
||||
|
||||
// Space above DMP title.
|
||||
/* XWPFParagraph parAboveDmpTitle = document.createParagraph();
|
||||
XWPFParagraph parAboveDmpTitle1 = document.createParagraph();
|
||||
XWPFParagraph parAboveDmpTitle2 = document.createParagraph();
|
||||
XWPFParagraph parAboveDmpTitle3 = document.createParagraph();*/
|
||||
|
||||
// DMP title custom style.
|
||||
wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||
|
||||
|
@ -201,6 +195,13 @@ public class DataManagementPlanManager {
|
|||
|
||||
wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
|
||||
wordBuilder.addParagraphContent("Funder", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
if (dmpEntity.getGrant().getFunder() != null)
|
||||
wordBuilder.addParagraphContent(dmpEntity.getGrant().getFunder().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
|
||||
wordBuilder.addParagraphContent("Grant", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
wordBuilder.addParagraphContent(dmpEntity.getGrant().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
|
||||
wordBuilder.addParagraphContent("Organisations", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
if (dmpEntity.getOrganisations().size() > 0) {
|
||||
wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(Organisation::getLabel).collect(Collectors.joining(", "))
|
||||
|
@ -227,58 +228,91 @@ public class DataManagementPlanManager {
|
|||
.filter(item -> item.getStatus() != Dataset.Status.CANCELED.getValue())
|
||||
.filter(item -> item.getStatus() != Dataset.Status.DELETED.getValue())
|
||||
.forEach(datasetEntity -> {
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
if (datasetEntity.getProperties() != null) {
|
||||
JSONObject jobject = new JSONObject(datasetEntity.getProperties());
|
||||
properties = jobject.toMap();
|
||||
}
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
if (datasetEntity.getProperties() != null) {
|
||||
JSONObject jObject = new JSONObject(datasetEntity.getProperties());
|
||||
properties = jObject.toMap();
|
||||
}
|
||||
|
||||
// Custom style for the Dataset title.
|
||||
//wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||
XWPFParagraph datasetLabelParagraph = document.createParagraph();
|
||||
datasetLabelParagraph.setStyle("Heading1");
|
||||
XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun();
|
||||
runDatasetTitle1.setText("Title: ");
|
||||
runDatasetTitle1.setBold(true);
|
||||
runDatasetTitle1.setFontSize(12);
|
||||
XWPFRun runDatasetTitle = datasetLabelParagraph.createRun();
|
||||
runDatasetTitle.setText(datasetEntity.getLabel());
|
||||
runDatasetTitle.setColor("2E75B6");
|
||||
runDatasetTitle.setBold(true);
|
||||
runDatasetTitle.setFontSize(12);
|
||||
// Custom style for the Dataset title.
|
||||
//wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||
XWPFParagraph datasetLabelParagraph = document.createParagraph();
|
||||
datasetLabelParagraph.setStyle("Heading1");
|
||||
XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun();
|
||||
runDatasetTitle1.setText("Title: ");
|
||||
runDatasetTitle1.setBold(true);
|
||||
runDatasetTitle1.setFontSize(12);
|
||||
XWPFRun runDatasetTitle = datasetLabelParagraph.createRun();
|
||||
runDatasetTitle.setText(datasetEntity.getLabel());
|
||||
runDatasetTitle.setColor("2E75B6");
|
||||
runDatasetTitle.setBold(true);
|
||||
runDatasetTitle.setFontSize(12);
|
||||
|
||||
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
||||
datasetTemplateParagraph.setStyle("Heading2");
|
||||
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
||||
runDatasetTemplate1.setText("Template: ");
|
||||
runDatasetTemplate1.setBold(true);
|
||||
runDatasetTemplate1.setFontSize(12);
|
||||
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
|
||||
runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
|
||||
runDatasetTemplate.setColor("2E75B6");
|
||||
runDatasetTemplate.setBold(true);
|
||||
runDatasetTemplate.setFontSize(12);
|
||||
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
||||
datasetTemplateParagraph.setStyle("Heading2");
|
||||
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
||||
runDatasetTemplate1.setText("Template: ");
|
||||
runDatasetTemplate1.setBold(true);
|
||||
runDatasetTemplate1.setFontSize(12);
|
||||
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
|
||||
runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
|
||||
runDatasetTemplate.setColor("2E75B6");
|
||||
runDatasetTemplate.setBold(true);
|
||||
runDatasetTemplate.setFontSize(12);
|
||||
|
||||
wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity);
|
||||
visibilityRuleService.setProperties(properties);
|
||||
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
||||
try {
|
||||
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Page break at the end of the Dataset.
|
||||
XWPFParagraph parBreakDataset = document.createParagraph();
|
||||
});
|
||||
XWPFParagraph externalReferencesParagraph = document.createParagraph();
|
||||
externalReferencesParagraph.setStyle("Heading2");
|
||||
XWPFRun externalReferencesRun = externalReferencesParagraph.createRun();
|
||||
externalReferencesRun.setText("External References");
|
||||
externalReferencesRun.setColor("2E75B6");
|
||||
externalReferencesRun.setBold(true);
|
||||
externalReferencesRun.setFontSize(12);
|
||||
|
||||
wordBuilder.addParagraphContent("Data Repositories", document, ParagraphStyle.HEADER3, 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.HEADER3, 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.HEADER3, 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.HEADER3, 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.TEXT, BigInteger.ZERO);
|
||||
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity);
|
||||
visibilityRuleService.setProperties(properties);
|
||||
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
||||
try {
|
||||
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Page break at the end of the Dataset.
|
||||
XWPFParagraph parBreakDataset = document.createParagraph();
|
||||
});
|
||||
|
||||
// Removes the top empty headings.
|
||||
document.removeBodyElement(0);
|
||||
document.removeBodyElement(0);
|
||||
document.removeBodyElement(0);
|
||||
document.removeBodyElement(0);
|
||||
document.removeBodyElement(0);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
document.removeBodyElement(0);
|
||||
}
|
||||
|
||||
String fileName = dmpEntity.getLabel();
|
||||
fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
||||
|
|
|
@ -32,6 +32,8 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
|||
import eu.eudat.queryable.QueryableList;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
@ -252,11 +254,63 @@ public class DatasetManager {
|
|||
XWPFDocument document = new XWPFDocument(is);
|
||||
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
||||
wordBuilder.addParagraphContent(datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||
|
||||
// Space below Dataset title.
|
||||
XWPFParagraph parBreakDataset = document.createParagraph();
|
||||
|
||||
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
||||
datasetTemplateParagraph.setStyle("Heading2");
|
||||
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
||||
runDatasetTemplate1.setText("Template: ");
|
||||
runDatasetTemplate1.setBold(true);
|
||||
runDatasetTemplate1.setFontSize(12);
|
||||
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
|
||||
runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
|
||||
runDatasetTemplate.setColor("2E75B6");
|
||||
runDatasetTemplate.setBold(true);
|
||||
runDatasetTemplate.setFontSize(12);
|
||||
|
||||
XWPFParagraph externalReferencesParagraph = document.createParagraph();
|
||||
externalReferencesParagraph.setStyle("Heading2");
|
||||
XWPFRun externalReferencesRun = externalReferencesParagraph.createRun();
|
||||
externalReferencesRun.setText("External References");
|
||||
externalReferencesRun.setColor("2E75B6");
|
||||
externalReferencesRun.setBold(true);
|
||||
externalReferencesRun.setFontSize(12);
|
||||
|
||||
wordBuilder.addParagraphContent("Data Repositories", document, ParagraphStyle.HEADER3, 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.HEADER3, 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.HEADER3, 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.HEADER3, 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);
|
||||
}*/
|
||||
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
if (datasetEntity.getProperties() != null) {
|
||||
JSONObject jObject = new JSONObject(datasetEntity.getProperties());
|
||||
properties = jObject.toMap();
|
||||
}
|
||||
|
||||
wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity);
|
||||
visibilityRuleService.setProperties(properties);
|
||||
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
||||
|
@ -265,11 +319,9 @@ public class DatasetManager {
|
|||
File exportFile = new File(label + ".docx");
|
||||
|
||||
// Removes the top empty headings.
|
||||
document.removeBodyElement(0);
|
||||
document.removeBodyElement(0);
|
||||
document.removeBodyElement(0);
|
||||
document.removeBodyElement(0);
|
||||
document.removeBodyElement(0);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
document.removeBodyElement(0);
|
||||
}
|
||||
|
||||
FileOutputStream out = new FileOutputStream(exportFile);
|
||||
document.write(out);
|
||||
|
|
|
@ -27,9 +27,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/26/2018.
|
||||
*/
|
||||
public class WordBuilder {
|
||||
|
||||
private Map<ParagraphStyle, ApplierWithValue<XWPFDocument, String, XWPFParagraph>> options = new HashMap<>();
|
||||
|
@ -47,7 +44,7 @@ public class WordBuilder {
|
|||
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
||||
XWPFRun run = paragraph.createRun();
|
||||
if (item != null)
|
||||
run.setText(item);
|
||||
run.setText(" " + item);
|
||||
run.setFontSize(11);
|
||||
return paragraph;
|
||||
});
|
||||
|
@ -75,7 +72,7 @@ public class WordBuilder {
|
|||
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
||||
paragraph.setStyle("Heading2");
|
||||
XWPFRun run = paragraph.createRun();
|
||||
run.setText(item);
|
||||
run.setText(" " + item);
|
||||
// run.setBold(true);
|
||||
// run.setFontSize(12);
|
||||
return paragraph;
|
||||
|
@ -84,7 +81,7 @@ public class WordBuilder {
|
|||
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
||||
paragraph.setStyle("Heading3");
|
||||
XWPFRun run = paragraph.createRun();
|
||||
run.setText(item);
|
||||
run.setText(" " + item);
|
||||
// run.setBold(true);
|
||||
// run.setFontSize(11);
|
||||
return paragraph;
|
||||
|
@ -100,7 +97,7 @@ public class WordBuilder {
|
|||
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
||||
paragraph.setStyle("Heading5");
|
||||
XWPFRun run = paragraph.createRun();
|
||||
run.setText(item);
|
||||
run.setText(" " + item);
|
||||
return paragraph;
|
||||
});
|
||||
this.options.put(ParagraphStyle.FOOTER, (mainDocumentPart, item) -> {
|
||||
|
|
Loading…
Reference in New Issue