rename dmp to plan

This commit is contained in:
amentis 2024-07-05 16:40:36 +03:00
parent 099e8707e3
commit 158764a974
10 changed files with 135 additions and 142 deletions

View File

@ -5,12 +5,12 @@ import gr.cite.tools.logging.EventId;
public class AuditableAction {
public static final EventId FileTransformer_ExportDmp = new EventId(1000, "FileTransformer_ExportDmp");
public static final EventId FileTransformer_ExportPlan = new EventId(1000, "FileTransformer_ExportPlan");
public static final EventId FileTransformer_ExportDescription = new EventId(1001, "FileTransformer_ExportDescription");
public static final EventId FileTransformer_ImportFileToDmp = new EventId(1002, "FileTransformer_ImportFileToDmp");
public static final EventId FileTransformer_ImportFileToPlan = new EventId(1002, "FileTransformer_ImportFileToPlan");
public static final EventId FileTransformer_ImportFileToDescription = new EventId(1003, "FileTransformer_ImportFileToDescription");
public static final EventId FileTransformer_GetSupportedFormats = new EventId(1004, "FileTransformer_GetSupportedFormats");
public static final EventId FileTransformer_PreprocessingDmp = new EventId(1005, "FileTransformer_PreprocessingDmp");
public static final EventId FileTransformer_PreprocessingPlan = new EventId(1005, "FileTransformer_PreprocessingPlan");
public static final EventId FileTransformer_PreprocessingDescription = new EventId(1006, "FileTransformer_PreprocessingDescription");

View File

@ -1,18 +1,16 @@
package org.opencdmp.filetransformer.docx.service.wordfiletransformer;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.commonmodels.enums.*;
import org.opencdmp.commonmodels.models.UserContactInfoModel;
import org.opencdmp.commonmodels.models.dmp.DmpBlueprintValueModel;
import org.opencdmp.commonmodels.models.dmp.DmpContactModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.plan.PlanBlueprintValueModel;
import org.opencdmp.commonmodels.models.plan.PlanContactModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.commonmodels.models.FileEnvelopeModel;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.descriptiotemplate.DescriptionTemplateModel;
import org.opencdmp.commonmodels.models.dmpblueprint.*;
import org.opencdmp.commonmodels.models.dmpreference.DmpReferenceModel;
import org.opencdmp.commonmodels.models.planblueprint.*;
import org.opencdmp.commonmodels.models.planreference.PlanReferenceModel;
import org.opencdmp.commonmodels.models.reference.ReferenceModel;
import org.opencdmp.filetransformerbase.enums.FileTransformerEntityType;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerClient;
@ -29,9 +27,7 @@ import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
@ -56,7 +52,7 @@ public class WordFileTransformerService implements FileTransformerClient {
new FileFormat(FileFormats.DOCX.getValue(), true, "fa-file-word-o"));
private final static List<FileTransformerEntityType> FILE_TRANSFORMER_ENTITY_TYPES = List.of(
FileTransformerEntityType.Dmp, FileTransformerEntityType.Description);
FileTransformerEntityType.Plan, FileTransformerEntityType.Description);
private final WordFileTransformerServiceProperties wordFileTransformerServiceProperties;
private final PdfService pdfService;
@ -75,14 +71,14 @@ public class WordFileTransformerService implements FileTransformerClient {
}
@Override
public FileEnvelopeModel exportDmp(DmpModel dmp, String variant) throws IOException, InvalidApplicationException {
public FileEnvelopeModel exportPlan(PlanModel plan, String variant) throws IOException, InvalidApplicationException {
FileFormats fileFormat = FileFormats.of(variant);
byte[] bytes = this.buildDmpWordDocument(dmp);
byte[] bytes = this.buildPlanWordDocument(plan);
String filename = switch (fileFormat) {
case DOCX -> this.getDmpFileName(dmp, ".docx");
case DOCX -> this.getPlanFileName(plan, ".docx");
case PDF -> {
bytes = this.pdfService.convertToPDF(bytes);
yield this.getDmpFileName(dmp, ".pdf");
yield this.getPlanFileName(plan, ".pdf");
}
default -> throw new MyApplicationException("Invalid type " + fileFormat);
};
@ -124,7 +120,7 @@ public class WordFileTransformerService implements FileTransformerClient {
@Override
public DmpModel importDmp(DmpImportModel dmpImportModel) {
public PlanModel importPlan(PlanImportModel planImportModel) {
throw new MyApplicationException("import not supported");
}
@ -145,7 +141,7 @@ public class WordFileTransformerService implements FileTransformerClient {
}
@Override
public PreprocessingDmpModel preprocessingDmp(FileEnvelopeModel fileEnvelopeModel) {
public PreprocessingPlanModel preprocessingPlan(FileEnvelopeModel fileEnvelopeModel) {
throw new MyApplicationException("preprocessing not supported");
}
@ -154,12 +150,12 @@ public class WordFileTransformerService implements FileTransformerClient {
throw new MyApplicationException("preprocessing not supported");
}
private List<ReferenceModel> getReferenceModelOfTypeCode(DmpModel dmp, String code, UUID blueprintId){
private List<ReferenceModel> getReferenceModelOfTypeCode(PlanModel plan, String code, UUID blueprintId){
List<ReferenceModel> response = new ArrayList<>();
if (dmp.getReferences() == null) return response;
for (DmpReferenceModel dmpReferenceModel : dmp.getReferences()){
if (dmpReferenceModel.getReference() != null && dmpReferenceModel.getReference().getType() != null && dmpReferenceModel.getReference().getType().getCode() != null && dmpReferenceModel.getReference().getType().getCode().equals(code)){
if (blueprintId == null || (dmpReferenceModel.getData() != null && blueprintId.equals(dmpReferenceModel.getData().getBlueprintFieldId()))) response.add(dmpReferenceModel.getReference());
if (plan.getReferences() == null) return response;
for (PlanReferenceModel planReferenceModel : plan.getReferences()){
if (planReferenceModel.getReference() != null && planReferenceModel.getReference().getType() != null && planReferenceModel.getReference().getType().getCode() != null && planReferenceModel.getReference().getType().getCode().equals(code)){
if (blueprintId == null || (planReferenceModel.getData() != null && blueprintId.equals(planReferenceModel.getData().getBlueprintFieldId()))) response.add(planReferenceModel.getReference());
}
}
@ -167,16 +163,16 @@ public class WordFileTransformerService implements FileTransformerClient {
}
private byte[] buildDmpWordDocument(DmpModel dmpEntity) throws IOException, InvalidApplicationException {
if (dmpEntity == null) throw new MyApplicationException("DmpEntity required");
DmpBlueprintModel dmpBlueprintModel = dmpEntity.getDmpBlueprint();
if (dmpBlueprintModel == null) throw new MyApplicationException("DmpBlueprint required");
if (dmpBlueprintModel.getDefinition() == null) throw new MyApplicationException("DmpBlueprint Definition required");
if (dmpBlueprintModel.getDefinition().getSections() == null) throw new MyApplicationException("DmpBlueprint Section required");
private byte[] buildPlanWordDocument(PlanModel planEntity) throws IOException, InvalidApplicationException {
if (planEntity == null) throw new MyApplicationException("planEntity required");
PlanBlueprintModel planBlueprintModel = planEntity.getPlanBlueprint();
if (planBlueprintModel == null) throw new MyApplicationException("PlanBlueprint required");
if (planBlueprintModel.getDefinition() == null) throw new MyApplicationException("PlanBlueprint Definition required");
if (planBlueprintModel.getDefinition().getSections() == null) throw new MyApplicationException("PlanBlueprint Section required");
XWPFDocument document = new XWPFDocument(new FileInputStream(ResourceUtils.getFile(this.wordFileTransformerServiceProperties.getWordDmpTemplate())));
XWPFDocument document = new XWPFDocument(new FileInputStream(ResourceUtils.getFile(this.wordFileTransformerServiceProperties.getWordPlanTemplate())));
this.wordBuilder.fillFirstPage(dmpEntity, null, document, false);
this.wordBuilder.fillFirstPage(planEntity, null, document, false);
int powered_pos = this.wordBuilder.findPosOfPoweredBy(document);
XWPFParagraph powered_par = null;
@ -186,8 +182,8 @@ public class WordFileTransformerService implements FileTransformerClient {
argos_img_par = document.getParagraphArray(powered_pos + 1);
}
for (SectionModel sectionModel : dmpBlueprintModel.getDefinition().getSections()) {
buildDmpSection(dmpEntity, sectionModel, document);
for (SectionModel sectionModel : planBlueprintModel.getDefinition().getSections()) {
buildPlanSection(planEntity, sectionModel, document);
}
if (powered_pos != -1) {
@ -202,7 +198,7 @@ public class WordFileTransformerService implements FileTransformerClient {
document.removeBodyElement(powered_pos + 1);
}
this.wordBuilder.fillFooter(dmpEntity, null, document);
this.wordBuilder.fillFooter(planEntity, null, document);
ByteArrayOutputStream out = new ByteArrayOutputStream();
document.write(out);
@ -212,20 +208,20 @@ public class WordFileTransformerService implements FileTransformerClient {
return bytes;
}
private void buildDmpSection(DmpModel dmpEntity, SectionModel sectionModel, XWPFDocument document) throws InvalidApplicationException {
private void buildPlanSection(PlanModel planEntity, SectionModel sectionModel, XWPFDocument document) throws InvalidApplicationException {
this.wordBuilder.addParagraphContent(sectionModel.getOrdinal() + ". " + sectionModel.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO, 0);
if (sectionModel.getFields() != null) {
sectionModel.getFields().sort(Comparator.comparingInt(FieldModel::getOrdinal));
for (FieldModel fieldModel : sectionModel.getFields()) {
buildDmpSectionField(dmpEntity, document, fieldModel);
buildPlanSectionField(planEntity, document, fieldModel);
}
}
final boolean isFinalized = dmpEntity.getStatus() != null && dmpEntity.getStatus().equals(DmpStatus.Finalized);
final boolean isPublic = dmpEntity.getPublicAfter() != null && dmpEntity.getPublicAfter().isAfter(Instant.now());
final boolean isFinalized = planEntity.getStatus() != null && planEntity.getStatus().equals(PlanStatus.Finalized);
final boolean isPublic = planEntity.getPublicAfter() != null && planEntity.getPublicAfter().isAfter(Instant.now());
List<DescriptionModel> descriptions = dmpEntity.getDescriptions() == null ? new ArrayList<>() : dmpEntity.getDescriptions().stream()
List<DescriptionModel> descriptions = planEntity.getDescriptions() == null ? new ArrayList<>() : planEntity.getDescriptions().stream()
.filter(item -> item.getStatus() != DescriptionStatus.Canceled)
.filter(item -> !isPublic && !isFinalized || item.getStatus() == DescriptionStatus.Finalized)
.filter(item -> item.getSectionId().equals(sectionModel.getId()))
@ -304,24 +300,24 @@ public class WordFileTransformerService implements FileTransformerClient {
}
private void buildDmpSectionField(DmpModel dmpEntity, XWPFDocument document, FieldModel fieldModel) throws InvalidApplicationException {
private void buildPlanSectionField(PlanModel planEntity, XWPFDocument document, FieldModel fieldModel) throws InvalidApplicationException {
if (fieldModel == null) throw new MyApplicationException("Field required");
if (fieldModel.getCategory() == null) throw new MyApplicationException("Field is required" + fieldModel.getId() + " " + fieldModel.getLabel());
switch (fieldModel.getCategory()){
case System -> {
buildDmpSectionSystemField(dmpEntity, document, (SystemFieldModel) fieldModel);
buildPlanSectionSystemField(planEntity, document, (SystemFieldModel) fieldModel);
}
case Extra -> buildDmpSectionExtraField(dmpEntity, document, (ExtraFieldModel) fieldModel);
case Extra -> buildPlanSectionExtraField(planEntity, document, (ExtraFieldModel) fieldModel);
case ReferenceType -> {
buildDmpSectionReferenceTypeField(dmpEntity, document, (ReferenceTypeFieldModel) fieldModel);
buildPlanSectionReferenceTypeField(planEntity, document, (ReferenceTypeFieldModel) fieldModel);
}
default -> throw new MyApplicationException("Invalid type " + fieldModel.getCategory());
}
}
private void buildDmpSectionReferenceTypeField(DmpModel dmpEntity, XWPFDocument document, ReferenceTypeFieldModel referenceField) {
private void buildPlanSectionReferenceTypeField(PlanModel planEntity, XWPFDocument document, ReferenceTypeFieldModel referenceField) {
if (referenceField == null) throw new MyApplicationException("ReferenceField required");
if (dmpEntity == null) throw new MyApplicationException("DmpEntity required");
if (planEntity == null) throw new MyApplicationException("planEntity required");
if (document == null) throw new MyApplicationException("Document required");
if (referenceField.getReferenceType() == null) throw new MyApplicationException("ReferenceField type required");
if (referenceField.getReferenceType().getCode() == null && !referenceField.getReferenceType().getCode().isBlank()) throw new IllegalArgumentException("ReferenceField type code required");
@ -331,7 +327,7 @@ public class WordFileTransformerService implements FileTransformerClient {
runSyStemFieldTitle.setText(this.getReferenceFieldLabel(referenceField) + ": ");
runSyStemFieldTitle.setColor("000000");
List<ReferenceModel> referenceModels = this.getReferenceModelOfTypeCode(dmpEntity, referenceField.getReferenceType().getCode(), referenceField.getId());
List<ReferenceModel> referenceModels = this.getReferenceModelOfTypeCode(planEntity, referenceField.getReferenceType().getCode(), referenceField.getId());
for (ReferenceModel reference : referenceModels) {
XWPFRun runResearcher = systemFieldParagraph.createRun();
if (this.wordFileTransformerServiceProperties.getResearcherReferenceCode().equalsIgnoreCase(referenceField.getReferenceType().getCode()) ||
@ -350,12 +346,12 @@ public class WordFileTransformerService implements FileTransformerClient {
return referenceTypeField.getReferenceType().getName();
}
private void buildDmpSectionSystemField(DmpModel dmpEntity, XWPFDocument document, SystemFieldModel systemField) {
private void buildPlanSectionSystemField(PlanModel planEntity, XWPFDocument document, SystemFieldModel systemField) {
if (systemField == null) throw new MyApplicationException("SystemField required");
if (dmpEntity == null) throw new MyApplicationException("DmpEntity required");
if (planEntity == null) throw new MyApplicationException("planEntity required");
if (document == null) throw new MyApplicationException("Document required");
if (DmpBlueprintSystemFieldType.Language.equals(systemField.getSystemFieldType()) || DmpBlueprintSystemFieldType.User.equals(systemField.getSystemFieldType())) return;
if (PlanBlueprintSystemFieldType.Language.equals(systemField.getSystemFieldType()) || PlanBlueprintSystemFieldType.User.equals(systemField.getSystemFieldType())) return;
XWPFParagraph systemFieldParagraph = document.createParagraph();
@ -366,24 +362,24 @@ public class WordFileTransformerService implements FileTransformerClient {
switch (systemField.getSystemFieldType()) {
case Title:
XWPFRun runTitle = systemFieldParagraph.createRun();
runTitle.setText(dmpEntity.getLabel());
runTitle.setText(planEntity.getLabel());
runTitle.setColor("116a78");
break;
case Description:
wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0);
wordBuilder.addParagraphContent(planEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0);
break;
case AccessRights:
if (dmpEntity.getAccessType() != null) {
if (planEntity.getAccessType() != null) {
XWPFRun runAccessRights = systemFieldParagraph.createRun();
runAccessRights.setText(dmpEntity.getAccessType().equals(DmpAccessType.Public) ? "Public" : "Restricted"); //TODO
runAccessRights.setText(planEntity.getAccessType().equals(PlanAccessType.Public) ? "Public" : "Restricted"); //TODO
runAccessRights.setColor("116a78");
}
break;
case Contact:
List<String> contacts = new ArrayList<>();
if (dmpEntity.getProperties() != null && dmpEntity.getProperties().getContacts() != null && !dmpEntity.getProperties().getContacts().isEmpty()) {
for (DmpContactModel contactModel : dmpEntity.getProperties().getContacts()){
if (planEntity.getProperties() != null && planEntity.getProperties().getContacts() != null && !planEntity.getProperties().getContacts().isEmpty()) {
for (PlanContactModel contactModel : planEntity.getProperties().getContacts()){
String contact;
contact = (contactModel.getLastName() == null ? "" : contactModel.getLastName()) + " " + (contactModel.getFirstName() == null ? "" : contactModel.getFirstName());
if (contactModel.getEmail() != null && !contactModel.getEmail().isEmpty()) contact = contact + " (" + contactModel.getEmail() +")";
@ -420,7 +416,7 @@ public class WordFileTransformerService implements FileTransformerClient {
};
}
private void buildDmpSectionExtraField(DmpModel dmpEntity, XWPFDocument document, ExtraFieldModel extraFieldModel) {
private void buildPlanSectionExtraField(PlanModel planEntity, XWPFDocument document, ExtraFieldModel extraFieldModel) {
if (extraFieldModel == null) throw new MyApplicationException("ExtraFieldModel required");
XWPFParagraph extraFieldParagraph = document.createParagraph();
extraFieldParagraph.setSpacingBetween(1.0);
@ -429,27 +425,27 @@ public class WordFileTransformerService implements FileTransformerClient {
runExtraFieldLabel.setColor("000000");
XWPFRun runExtraFieldInput = extraFieldParagraph.createRun();
DmpBlueprintValueModel dmpBlueprintValueModel = dmpEntity.getProperties() != null && dmpEntity.getProperties().getDmpBlueprintValues() != null ? dmpEntity.getProperties().getDmpBlueprintValues().stream().filter(x -> extraFieldModel.getId().equals(x.getFieldId())).findFirst().orElse(null) : null;
if (dmpBlueprintValueModel != null) {
PlanBlueprintValueModel planBlueprintValueModel = planEntity.getProperties() != null && planEntity.getProperties().getPlanBlueprintValues() != null ? planEntity.getProperties().getPlanBlueprintValues().stream().filter(x -> extraFieldModel.getId().equals(x.getFieldId())).findFirst().orElse(null) : null;
if (planBlueprintValueModel != null) {
switch (extraFieldModel.getDataType()) {
case RichTex:
if(dmpBlueprintValueModel.getValue() != null && !dmpBlueprintValueModel.getValue().isBlank()) wordBuilder.addParagraphContent(dmpBlueprintValueModel.getValue(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0);
if(planBlueprintValueModel.getValue() != null && !planBlueprintValueModel.getValue().isBlank()) wordBuilder.addParagraphContent(planBlueprintValueModel.getValue(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0);
break;
case Number:
if(dmpBlueprintValueModel.getNumberValue() != null) {
runExtraFieldInput.setText(DecimalFormat.getNumberInstance().format(dmpBlueprintValueModel.getNumberValue()));
if(planBlueprintValueModel.getNumberValue() != null) {
runExtraFieldInput.setText(DecimalFormat.getNumberInstance().format(planBlueprintValueModel.getNumberValue()));
runExtraFieldInput.setColor("116a78");
}
break;
case Date:
if(dmpBlueprintValueModel.getDateValue() != null){
runExtraFieldInput.setText(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(dmpBlueprintValueModel.getDateValue()));
if(planBlueprintValueModel.getDateValue() != null){
runExtraFieldInput.setText(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(planBlueprintValueModel.getDateValue()));
runExtraFieldInput.setColor("116a78");
}
break;
case Text:
if(dmpBlueprintValueModel.getValue() != null && !dmpBlueprintValueModel.getValue().isBlank()) {
runExtraFieldInput.setText(dmpBlueprintValueModel.getValue());
if(planBlueprintValueModel.getValue() != null && !planBlueprintValueModel.getValue().isBlank()) {
runExtraFieldInput.setText(planBlueprintValueModel.getValue());
runExtraFieldInput.setColor("116a78");
}
break;
@ -459,17 +455,17 @@ public class WordFileTransformerService implements FileTransformerClient {
}
}
private String getDmpFileName(DmpModel dmpModel, String extension){
if (dmpModel == null) throw new MyApplicationException("DmpEntity required");
private String getPlanFileName(PlanModel planModel, String extension){
if (planModel == null) throw new MyApplicationException("PlanEntity required");
List<ReferenceModel> grants = this.getReferenceModelOfTypeCode(dmpModel, this.wordFileTransformerServiceProperties.getGrantReferenceCode(), null);
List<ReferenceModel> grants = this.getReferenceModelOfTypeCode(planModel, this.wordFileTransformerServiceProperties.getGrantReferenceCode(), null);
String fileName = null;
if (dmpModel.getLabel() != null){
return dmpModel.getLabel() + extension;
if (planModel.getLabel() != null){
return planModel.getLabel() + extension;
}
if (!grants.isEmpty() && grants.getFirst().getLabel() != null) {
fileName = "DMP_" + grants.getFirst().getLabel();
fileName += "_" + dmpModel.getVersion();
fileName = "PLAN_" + grants.getFirst().getLabel();
fileName += "_" + planModel.getVersion();
}
@ -477,13 +473,13 @@ public class WordFileTransformerService implements FileTransformerClient {
}
private byte[] buildDescriptionWordDocument(DescriptionModel descriptionModel) throws IOException {
if (descriptionModel == null) throw new MyApplicationException("DmpEntity required");
DmpModel dmpEntity = descriptionModel.getDmp();
if (dmpEntity == null) throw new MyApplicationException("Dmp is invalid");
if (descriptionModel == null) throw new MyApplicationException("DescriptionEntity required");
PlanModel planEntity = descriptionModel.getPlan();
if (planEntity == null) throw new MyApplicationException("plan is invalid");
XWPFDocument document = new XWPFDocument(new FileInputStream(ResourceUtils.getFile(this.wordFileTransformerServiceProperties.getWordDescriptionTemplate())));
this.wordBuilder.fillFirstPage(dmpEntity, descriptionModel, document, true);
this.wordBuilder.fillFooter(dmpEntity, descriptionModel, document);
this.wordBuilder.fillFirstPage(planEntity, descriptionModel, document, true);
this.wordBuilder.fillFooter(planEntity, descriptionModel, document);
int powered_pos = this.wordBuilder.findPosOfPoweredBy(document);
XWPFParagraph powered_par = null;
@ -516,7 +512,7 @@ public class WordFileTransformerService implements FileTransformerClient {
}
private String getDescriptionFileName(DescriptionModel descriptionModel, String extension){
if (descriptionModel == null) throw new MyApplicationException("DmpEntity required");
if (descriptionModel == null) throw new MyApplicationException("DescriptionEntity required");
String fileName = descriptionModel.getLabel().replaceAll("[^a-zA-Z0-9+ ]", "");
return fileName + extension;

View File

@ -6,7 +6,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class WordFileTransformerServiceProperties {
private String transformerId;
private boolean useSharedStorage;
private String wordDmpTemplate;
private String wordPlanTemplate;
private String pidTemplate;
private String wordDescriptionTemplate;
private String organizationReferenceCode;
@ -90,12 +90,12 @@ public class WordFileTransformerServiceProperties {
this.publicationReferenceCode = publicationReferenceCode;
}
public String getWordDmpTemplate() {
return wordDmpTemplate;
public String getWordPlanTemplate() {
return wordPlanTemplate;
}
public void setWordDmpTemplate(String wordDmpTemplate) {
this.wordDmpTemplate = wordDmpTemplate;
public void setWordPlanTemplate(String wordPlanTemplate) {
this.wordPlanTemplate = wordPlanTemplate;
}
public String getPidTemplate() {

View File

@ -3,7 +3,7 @@ package org.opencdmp.filetransformer.docx.service.wordfiletransformer.word;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.description.PropertyDefinitionModel;
import org.opencdmp.commonmodels.models.descriptiotemplate.DescriptionTemplateModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.filetransformer.docx.model.enums.ParagraphStyle;
import org.opencdmp.filetransformer.docx.service.wordfiletransformer.visibility.VisibilityService;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
@ -19,7 +19,7 @@ public interface WordBuilder {
int findPosOfPoweredBy(XWPFDocument document);
void fillFirstPage(DmpModel dmpEntity, DescriptionModel descriptionModel, XWPFDocument document, boolean isDescription);
void fillFirstPage(PlanModel planEntity, DescriptionModel descriptionModel, XWPFDocument document, boolean isDescription);
void fillFooter(DmpModel dmpEntity, DescriptionModel descriptionModel, XWPFDocument document);
void fillFooter(PlanModel planEntity, DescriptionModel descriptionModel, XWPFDocument document);
}

View File

@ -9,8 +9,8 @@ import org.opencdmp.commonmodels.models.description.PropertyDefinitionFieldSetMo
import org.opencdmp.commonmodels.models.description.PropertyDefinitionModel;
import org.opencdmp.commonmodels.models.descriptiotemplate.*;
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.*;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.dmpreference.DmpReferenceModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.commonmodels.models.planreference.PlanReferenceModel;
import org.opencdmp.commonmodels.models.reference.ReferenceFieldModel;
import org.opencdmp.commonmodels.models.reference.ReferenceModel;
import org.opencdmp.filetransformer.docx.service.storage.FileStorageService;
@ -833,7 +833,7 @@ public class WordBuilderImpl implements WordBuilder {
}
case UPLOAD:
case INTERNAL_ENTRIES_DESCRIPTIONS:
case INTERNAL_ENTRIES_DMPS:
case INTERNAL_ENTRIES_PlANS:
break;
default:
throw new MyApplicationException("Invalid type " + field.getData().getFieldType());
@ -863,34 +863,34 @@ public class WordBuilderImpl implements WordBuilder {
return -1;
}
private List<ReferenceModel> getReferenceModelOfTypeCode(DmpModel dmp, String code) {
private List<ReferenceModel> getReferenceModelOfTypeCode(PlanModel plan, String code) {
List<ReferenceModel> response = new ArrayList<>();
if (dmp.getReferences() == null) return response;
for (DmpReferenceModel dmpReferenceModel : dmp.getReferences()) {
if (dmpReferenceModel.getReference() != null && dmpReferenceModel.getReference().getType() != null && dmpReferenceModel.getReference().getType().getCode() != null && dmpReferenceModel.getReference().getType().getCode().equals(code)) {
response.add(dmpReferenceModel.getReference());
if (plan.getReferences() == null) return response;
for (PlanReferenceModel planReferenceModel : plan.getReferences()) {
if (planReferenceModel.getReference() != null && planReferenceModel.getReference().getType() != null && planReferenceModel.getReference().getType().getCode() != null && planReferenceModel.getReference().getType().getCode().equals(code)) {
response.add(planReferenceModel.getReference());
}
}
return response;
}
@Override
public void fillFirstPage(DmpModel dmpEntity, DescriptionModel descriptionModel, XWPFDocument document, boolean isDescription) {
if (dmpEntity == null) throw new MyApplicationException("DmpEntity required");
public void fillFirstPage(PlanModel planEntity, DescriptionModel descriptionModel, XWPFDocument document, boolean isDescription) {
if (planEntity == null) throw new MyApplicationException("planEntity required");
if (document == null) throw new MyApplicationException("Document required");
int parPos = 0;
int descrParPos = -1;
List<ReferenceModel> grants = this.getReferenceModelOfTypeCode(dmpEntity, this.wordFileTransformerServiceProperties.getGrantReferenceCode());
List<ReferenceModel> researchers = this.getReferenceModelOfTypeCode(dmpEntity, this.wordFileTransformerServiceProperties.getResearcherReferenceCode());
List<ReferenceModel> organizations = this.getReferenceModelOfTypeCode(dmpEntity, this.wordFileTransformerServiceProperties.getOrganizationReferenceCode());
List<ReferenceModel> funders = this.getReferenceModelOfTypeCode(dmpEntity, this.wordFileTransformerServiceProperties.getFunderReferenceCode());
List<ReferenceModel> grants = this.getReferenceModelOfTypeCode(planEntity, this.wordFileTransformerServiceProperties.getGrantReferenceCode());
List<ReferenceModel> researchers = this.getReferenceModelOfTypeCode(planEntity, this.wordFileTransformerServiceProperties.getResearcherReferenceCode());
List<ReferenceModel> organizations = this.getReferenceModelOfTypeCode(planEntity, this.wordFileTransformerServiceProperties.getOrganizationReferenceCode());
List<ReferenceModel> funders = this.getReferenceModelOfTypeCode(planEntity, this.wordFileTransformerServiceProperties.getFunderReferenceCode());
XWPFParagraph descrPar = null;
for (XWPFParagraph p : document.getParagraphs()) {
this.replaceTextSegment(p, "'{ARGOS.DMP.TITLE}'", dmpEntity.getLabel());
this.replaceTextSegment(p, "'{ARGOS.DMP.VERSION}'", "Version " + dmpEntity.getVersion());
this.replaceTextSegment(p, "'{ARGOS.PLAN.TITLE}'", planEntity.getLabel());
this.replaceTextSegment(p, "'{ARGOS.PLAN.VERSION}'", "Version " + planEntity.getVersion());
if (descriptionModel != null) {
this.replaceTextSegment(p, "'{ARGOS.DATASET.TITLE}'", descriptionModel.getLabel());
}
@ -901,7 +901,7 @@ public class WordBuilderImpl implements WordBuilder {
i++;
researchersNames.append(researcher.getLabel()).append(i < researchers.size() ? ", " : "");
}
this.replaceTextSegment(p, "'{ARGOS.DMP.RESEARCHERS}'", researchersNames.toString(), 15);
this.replaceTextSegment(p, "'{ARGOS.PLAN.RESEARCHERS}'", researchersNames.toString(), 15);
StringBuilder organisationsNames = new StringBuilder();
i = 0;
@ -909,12 +909,12 @@ public class WordBuilderImpl implements WordBuilder {
i++;
organisationsNames.append(organisation.getLabel()).append(i < organizations.size() ? ", " : "");
}
this.replaceTextSegment(p, "'{ARGOS.DMP.ORGANIZATIONS}'", organisationsNames.toString(), 15);
this.replaceTextSegment(p, "'{ARGOS.PLAN.ORGANIZATIONS}'", organisationsNames.toString(), 15);
if (this.textSegmentExists(p, "'{ARGOS.DMP.DESCRIPTION}'")) {
if (this.textSegmentExists(p, "'{ARGOS.PLAN.DESCRIPTION}'")) {
descrParPos = parPos;
descrPar = p;
this.replaceTextSegment(p, "'{ARGOS.DMP.DESCRIPTION}'", "");
this.replaceTextSegment(p, "'{ARGOS.PLAN.DESCRIPTION}'", "");
}
if (this.textSegmentExists(p, "'{ARGOS.DATASET.DESCRIPTION}'")) {
descrParPos = parPos;
@ -922,10 +922,10 @@ public class WordBuilderImpl implements WordBuilder {
this.replaceTextSegment(p, "'{ARGOS.DATASET.DESCRIPTION}'", "");
}
}
if ((descrParPos != -1) && (dmpEntity.getDescription() != null) && !isDescription) {
if ((descrParPos != -1) && (planEntity.getDescription() != null) && !isDescription) {
XmlCursor cursor = descrPar.getCTP().newCursor();
cursor.toNextSibling();
Document htmlDoc = Jsoup.parse((dmpEntity.getDescription()).replaceAll("\n", "<br>"));
Document htmlDoc = Jsoup.parse((planEntity.getDescription()).replaceAll("\n", "<br>"));
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(descrPar, 0, cursor);
NodeTraversor.traverse(htmlToWorldBuilder, htmlDoc);
}
@ -1083,29 +1083,29 @@ public class WordBuilderImpl implements WordBuilder {
}
@Override
public void fillFooter(DmpModel dmpEntity, DescriptionModel descriptionModel, XWPFDocument document) {
if (dmpEntity == null) throw new MyApplicationException("DmpEntity required");
public void fillFooter(PlanModel planEntity, DescriptionModel descriptionModel, XWPFDocument document) {
if (planEntity == null) throw new MyApplicationException("planEntity required");
List<ReferenceModel> licences = this.getReferenceModelOfTypeCode(dmpEntity, this.wordFileTransformerServiceProperties.getLicenceReferenceCode());
List<ReferenceModel> licences = this.getReferenceModelOfTypeCode(planEntity, this.wordFileTransformerServiceProperties.getLicenceReferenceCode());
document.getFooterList().forEach(xwpfFooter -> {
for (XWPFParagraph p : xwpfFooter.getParagraphs()) {
if (p != null) {
this.replaceTextSegment(p, "'{ARGOS.DMP.TITLE}'", dmpEntity.getLabel());
this.replaceTextSegment(p, "'{ARGOS.PLAN.TITLE}'", planEntity.getLabel());
if (descriptionModel != null) {
this.replaceTextSegment(p, "'{ARGOS.DATASET.TITLE}'", descriptionModel.getLabel());
}
if (!licences.isEmpty() && licences.getFirst().getReference() != null && !licences.getFirst().getReference().isBlank()) {
this.replaceTextSegment(p, "'{ARGOS.DMP.LICENSE}'", licences.getFirst().getReference());
this.replaceTextSegment(p, "'{ARGOS.PLAN.LICENSE}'", licences.getFirst().getReference());
} else {
this.replaceTextSegment(p, "'{ARGOS.DMP.LICENSE}'", "License: -");
this.replaceTextSegment(p, "'{ARGOS.PLAN.LICENSE}'", "License: -");
}
if (dmpEntity.getEntityDois() != null && !dmpEntity.getEntityDois().isEmpty()) {
this.replaceTextSegment(p, "'{ARGOS.DMP.DOI}'", dmpEntity.getEntityDois().getFirst().getDoi());
if (planEntity.getEntityDois() != null && !planEntity.getEntityDois().isEmpty()) {
this.replaceTextSegment(p, "'{ARGOS.PLAN.DOI}'", planEntity.getEntityDois().getFirst().getDoi());
} else {
this.replaceTextSegment(p, "'{ARGOS.DMP.DOI}'", "-");
this.replaceTextSegment(p, "'{ARGOS.PLAN.DOI}'", "-");
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy").withZone(ZoneId.systemDefault());
this.replaceTextSegment(p, "'{ARGOS.DMP.LAST_MODIFIED}'", formatter.format(dmpEntity.getUpdatedAt()));
this.replaceTextSegment(p, "'{ARGOS.PLAN.LAST_MODIFIED}'", formatter.format(planEntity.getUpdatedAt()));
}
}
});

View File

@ -27,7 +27,7 @@
<dependency>
<groupId>org.opencdmp</groupId>
<artifactId>file-transformer-base</artifactId>
<version>0.0.23</version>
<version>0.0.24</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>

View File

@ -5,15 +5,14 @@ import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.commonmodels.models.FileEnvelopeModel;
import org.opencdmp.commonmodels.models.description.DescriptionModel;
import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.plan.PlanModel;
import org.opencdmp.filetransformer.docx.audit.AuditableAction;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerClient;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerConfiguration;
import org.opencdmp.filetransformer.docx.service.wordfiletransformer.WordFileTransformerService;
import org.opencdmp.filetransformerbase.models.misc.DescriptionImportModel;
import org.opencdmp.filetransformerbase.models.misc.DmpImportModel;
import org.opencdmp.filetransformerbase.models.misc.PlanImportModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingDescriptionModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingDmpModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingPlanModel;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -36,13 +35,13 @@ public class FileTransformerController implements org.opencdmp.filetransformerba
this.auditService = auditService;
}
public FileEnvelopeModel exportDmp(@RequestBody DmpModel dmpDepositModel, @RequestParam(value = "format",required = false)String format) throws Exception {
logger.debug(new MapLogEntry("exportDmp " + DmpModel.class.getSimpleName()).And("dmpDepositModel", dmpDepositModel).And("format", format));
public FileEnvelopeModel exportPlan(@RequestBody PlanModel planDepositModel, @RequestParam(value = "format",required = false)String format) throws Exception {
logger.debug(new MapLogEntry("exportPlan " + PlanModel.class.getSimpleName()).And("planDepositModel", planDepositModel).And("format", format));
FileEnvelopeModel model = fileTransformerExecutor.exportDmp(dmpDepositModel, format);
FileEnvelopeModel model = fileTransformerExecutor.exportPlan(planDepositModel, format);
this.auditService.track(AuditableAction.FileTransformer_ExportDmp, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("dmpDepositModel", dmpDepositModel),
this.auditService.track(AuditableAction.FileTransformer_ExportPlan, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("planDepositModel", planDepositModel),
new AbstractMap.SimpleEntry<String, Object>("format", format)
));
return model;
@ -60,14 +59,14 @@ public class FileTransformerController implements org.opencdmp.filetransformerba
return model;
}
public DmpModel importFileToDmp(@RequestBody DmpImportModel dmpImportModel) {
public PlanModel importFileToPlan(@RequestBody PlanImportModel planImportModel) {
logger.debug(new MapLogEntry("importFileToDmp " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", dmpImportModel.getFile()));
logger.debug(new MapLogEntry("importFileToPlan " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", planImportModel.getFile()));
DmpModel model = fileTransformerExecutor.importDmp(dmpImportModel);
PlanModel model = fileTransformerExecutor.importPlan(planImportModel);
this.auditService.track(AuditableAction.FileTransformer_ImportFileToDmp, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("fileEnvelope", dmpImportModel.getFile())
this.auditService.track(AuditableAction.FileTransformer_ImportFileToPlan, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("fileEnvelope", planImportModel.getFile())
));
return model;
}
@ -83,13 +82,13 @@ public class FileTransformerController implements org.opencdmp.filetransformerba
return model;
}
public PreprocessingDmpModel preprocessingDmp(FileEnvelopeModel fileEnvelopeModel) {
logger.debug(new MapLogEntry("PreprocessingDmpModel " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", fileEnvelopeModel));
public PreprocessingPlanModel preprocessingPlan(FileEnvelopeModel fileEnvelopeModel) {
logger.debug(new MapLogEntry("PreprocessingPlanModel " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", fileEnvelopeModel));
PreprocessingDmpModel model = fileTransformerExecutor.preprocessingDmp(fileEnvelopeModel);
PreprocessingPlanModel model = fileTransformerExecutor.preprocessingPlan(fileEnvelopeModel);
this.auditService.track(AuditableAction.FileTransformer_PreprocessingDmp, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("importFileToDescription ", fileEnvelopeModel)
this.auditService.track(AuditableAction.FileTransformer_PreprocessingPlan, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("importFileToPlan ", fileEnvelopeModel)
));
return model;
}

View File

@ -1,5 +1,5 @@
word-file-transformer:
word-dmp-template: classpath:documents/h2020.docx
word-plan-template: classpath:documents/h2020.docx
pid-template: classpath:pidLinks.json
word-description-template: classpath:documents/h2020_dataset.docx
useSharedStorage: false

View File

@ -14,7 +14,6 @@ Validation.LessThenEqual= value {0} must be equal or less than {1}
Validation.LargerThenEqual= value {0} must be equal or larger than {1}
Validation.MissingFields= missing fields: {0}
Validation.InvalidDescriptionTemplateMultiplicity= {0} can not be used
Validation.InvalidDescriptionTemplateMultiplicityOnDMP= Description Templates has multiplicity errors
Validation_UrlRequired={0} is not valid url
SystemField_Title_Label=Title

View File

@ -14,5 +14,4 @@ Validation.LessThenEqual= value {0} must be equal or less than {1}
Validation.LargerThenEqual= value {0} must be equal or larger than {1}
Validation.MissingFields= missing fields: {0}
Validation.InvalidDescriptionTemplateMultiplicity= {0} can not be used
Validation.InvalidDescriptionTemplateMultiplicityOnDMP= Description Templates has multiplicity errors
Validation_UrlRequired={0} is not valid url