WIP for new base

This commit is contained in:
Diamantis Tziotzios 2024-01-25 10:17:44 +02:00
parent 654d4ef5c8
commit bf2520c6b4
18 changed files with 253 additions and 746 deletions

View File

@ -4,21 +4,25 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.file.transformer.configuration.FilePathProperties; import eu.eudat.file.transformer.configuration.FilePathProperties;
import eu.eudat.file.transformer.configuration.FileStorageProperties; import eu.eudat.file.transformer.configuration.FileStorageProperties;
import eu.eudat.file.transformer.configuration.PdfProperties; import eu.eudat.file.transformer.configuration.PdfProperties;
import eu.eudat.file.transformer.entities.user.composite.PagedDatasetProfile; import eu.eudat.file.transformer.enums.DescriptionStatus;
import eu.eudat.file.transformer.enums.*; import eu.eudat.file.transformer.enums.DmpBlueprintFieldCategory;
import eu.eudat.file.transformer.enums.DmpStatus;
import eu.eudat.file.transformer.enums.ReferenceType; import eu.eudat.file.transformer.enums.ReferenceType;
import eu.eudat.file.transformer.model.*; import eu.eudat.file.transformer.interfaces.FileTransformerClient;
import eu.eudat.file.transformer.model.dmpblueprintdefinition.ExtraField; import eu.eudat.file.transformer.interfaces.FileTransformerConfiguration;
import eu.eudat.file.transformer.model.dmpblueprintdefinition.Field; import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel;
import eu.eudat.file.transformer.model.dmpblueprintdefinition.Section; import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
import eu.eudat.file.transformer.model.dmpblueprintdefinition.SystemField; import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
import eu.eudat.file.transformer.models.dmp.DmpReferenceFileTransformerModel;
import eu.eudat.file.transformer.models.dmpblueprint.DmpBlueprintFileTransformerModel;
import eu.eudat.file.transformer.models.dmpblueprint.definition.ExtraFieldFileTransformerModelFileTransformerModel;
import eu.eudat.file.transformer.models.dmpblueprint.definition.FieldFileTransformerModel;
import eu.eudat.file.transformer.models.dmpblueprint.definition.SectionFileTransformerModel;
import eu.eudat.file.transformer.models.dmpblueprint.definition.SystemFieldFileTransformerModel;
import eu.eudat.file.transformer.model.enums.FileFormats; import eu.eudat.file.transformer.model.enums.FileFormats;
import eu.eudat.file.transformer.model.file.FileEnvelope; import eu.eudat.file.transformer.models.misc.FileEnvelope;
import eu.eudat.file.transformer.model.file.FileEnvelopeInternal; import eu.eudat.file.transformer.model.file.FileEnvelopeInternal;
import eu.eudat.file.transformer.model.file.FileFormat; import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel;\
import eu.eudat.file.transformer.services.visibility.VisibilityRuleService;
import eu.eudat.file.transformer.services.visibility.VisibilityRuleServiceImpl;
import eu.eudat.file.transformer.utils.descriptionTemplate.DescriptionTemplateService;
import eu.eudat.file.transformer.utils.pdf.PDFUtils; import eu.eudat.file.transformer.utils.pdf.PDFUtils;
import eu.eudat.file.transformer.utils.types.ParagraphStyle; import eu.eudat.file.transformer.utils.types.ParagraphStyle;
import eu.eudat.file.transformer.utils.word.WordBuilder; import eu.eudat.file.transformer.utils.word.WordBuilder;
@ -41,13 +45,8 @@ import java.math.BigInteger;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
@Component @Component
public class WordFileTransformer implements FileTransformerExecutor { public class WordFileTransformer implements FileTransformerClient {
private final static Logger logger = LoggerFactory.getLogger(WordFileTransformer.class); private final static Logger logger = LoggerFactory.getLogger(WordFileTransformer.class);
private final static List<FileFormat> FILE_FORMATS = List.of(
new FileFormat(FileFormats.PDF.getValue(), "PDF", "fa-file-pdf-o"),
new FileFormat(FileFormats.DOCX.getValue(), "Document", "fa-file-word-o"));
private final FilePathProperties fileTemplateProperties; private final FilePathProperties fileTemplateProperties;
private final FileStorageProperties fileStorageProperties; private final FileStorageProperties fileStorageProperties;
private final PdfProperties pdfProperties; private final PdfProperties pdfProperties;
@ -64,8 +63,8 @@ public class WordFileTransformer implements FileTransformerExecutor {
} }
@Override @Override
public FileEnvelope exportDmp(DmpFileTransformerModel dmp, ExtraPropertiesModel properties) throws IOException { public FileEnvelope exportDmp(DmpFileTransformerModel dmp) throws IOException {
FileFormats fileFormat = FileFormats.of(properties.getFormat()); FileFormats fileFormat = FileFormats.of(dmp.getVariant());
return switch (fileFormat) { return switch (fileFormat) {
case DOCX -> getWordDocument(dmp); case DOCX -> getWordDocument(dmp);
case PDF -> { case PDF -> {
@ -76,7 +75,13 @@ public class WordFileTransformer implements FileTransformerExecutor {
} }
@Override @Override
public FileEnvelope exportDescription(DescriptionFileTransformerModel descriptionFileTransformerModel, ExtraPropertiesModel properties) throws InvalidApplicationException, IOException { public DmpFileTransformerModel importDmp(FileEnvelope file) {
//Nothing to do here
return null;
}
@Override
public FileEnvelope exportDescription(DescriptionFileTransformerModel descriptionFileTransformerModel) throws InvalidApplicationException, IOException {
FileFormats fileFormat = FileFormats.of(properties.getFormat()); FileFormats fileFormat = FileFormats.of(properties.getFormat());
return switch (fileFormat) { return switch (fileFormat) {
case DOCX -> getDescriptionWordDocument(descriptionFileTransformerModel); case DOCX -> getDescriptionWordDocument(descriptionFileTransformerModel);
@ -86,22 +91,17 @@ public class WordFileTransformer implements FileTransformerExecutor {
} }
}; };
} }
@Override @Override
public DmpFileTransformerModel importFileToDmp(FileEnvelope envelope) { public DescriptionFileTransformerModel importDescription(FileEnvelope file) {
//Nothing to do here
return null; return null;
} }
@Override @Override
public DescriptionFileTransformerModel importFileToDescription(FileEnvelope envelope) { public FileTransformerConfiguration getConfiguration() {
return null; return null; //TODO
} // return this.zenodoProperties.getDepositConfiguration();
@Override
public List<FileFormat> getSupportedFileFormats() {
return FILE_FORMATS;
} }
private FileEnvelope getPdfDocument(FileEnvelopeInternal wordFile) throws IOException { private FileEnvelope getPdfDocument(FileEnvelopeInternal wordFile) throws IOException {
@ -126,22 +126,21 @@ public class WordFileTransformer implements FileTransformerExecutor {
private FileEnvelopeInternal getWordDocument(DmpFileTransformerModel dmpEntity, Boolean versioned) throws IOException { private FileEnvelopeInternal getWordDocument(DmpFileTransformerModel dmpEntity, Boolean versioned) throws IOException {
WordBuilder wordBuilder = new WordBuilder(fileTemplateProperties, fileStorageProperties); WordBuilder wordBuilder = new WordBuilder(fileTemplateProperties, fileStorageProperties);
VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl(); \ XWPFDocument document = new XWPFDocument(new FileInputStream(ResourceUtils.getFile(fileTemplateProperties.getWordTemplate())));
XWPFDocument document = new XWPFDocument(new FileInputStream(ResourceUtils.getFile(fileTemplateProperties.getWordTemplate())));
wordBuilder.fillFirstPage(dmpEntity, null, document, false); wordBuilder.fillFirstPage(dmpEntity, null, document, false);
List<Reference> grants = new ArrayList<>(); List<ReferenceFileTransformerModel> grants = new ArrayList<>();
List<Reference> researchers = new ArrayList<>(); List<ReferenceFileTransformerModel> researchers = new ArrayList<>();
List<Reference> organizations = new ArrayList<>(); List<ReferenceFileTransformerModel> organizations = new ArrayList<>();
List<Reference> funders = new ArrayList<>(); List<ReferenceFileTransformerModel> funders = new ArrayList<>();
List<Reference> projects = new ArrayList<>(); List<ReferenceFileTransformerModel> projects = new ArrayList<>();
if (dmpEntity.getDmpReferences() != null) { if (dmpEntity.getDmpReferences() != null) {
grants = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Grants) && referenceFileModel.getIsActive().equals(IsActive.Active)).toList(); grants = dmpEntity.getDmpReferences().stream().map(DmpReferenceFileTransformerModel::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Grants)).toList();
researchers = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(reference -> reference.getType().equals(ReferenceType.Researcher)).toList(); researchers = dmpEntity.getDmpReferences().stream().map(DmpReferenceFileTransformerModel::getReference).filter(reference -> reference.getType().equals(ReferenceType.Researcher)).toList();
organizations = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Organizations)).toList(); organizations = dmpEntity.getDmpReferences().stream().map(DmpReferenceFileTransformerModel::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Organizations)).toList();
funders = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Funder) && referenceFileModel.getIsActive().equals(IsActive.Active)).toList(); funders = dmpEntity.getDmpReferences().stream().map(DmpReferenceFileTransformerModel::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Funder)).toList();
projects = dmpEntity.getDmpReferences().stream().filter(referenceFileModel -> referenceFileModel.getReference().getType().equals(ReferenceType.Project) && referenceFileModel.getReference().getIsActive().equals(IsActive.Active)).map(DmpReference::getReference).toList(); projects = dmpEntity.getDmpReferences().stream().filter(referenceFileModel -> referenceFileModel.getReference().getType().equals(ReferenceType.Project)).map(DmpReferenceFileTransformerModel::getReference).toList();
} }
// int powered_pos = document.getParagraphs().size() - 3; // int powered_pos = document.getParagraphs().size() - 3;
@ -192,30 +191,30 @@ public class WordFileTransformer implements FileTransformerExecutor {
// // Space below Datasets. // // Space below Datasets.
// XWPFParagraph parBreakDatasets = document.createParagraph(); // XWPFParagraph parBreakDatasets = document.createParagraph();
DmpBlueprint dmpBlueprint = dmpEntity.getBlueprint(); DmpBlueprintFileTransformerModel dmpBlueprintFileTransformerModel = dmpEntity.getBlueprint();
for(Section section: dmpBlueprint.getDefinition().getSections()){ for(SectionFileTransformerModel sectionFileTransformerModel : dmpBlueprintFileTransformerModel.getDefinitionFileTransformerModel().getSections()){
wordBuilder.addParagraphContent("Section " + section.getOrdinal(), document, ParagraphStyle.HEADER1, BigInteger.ZERO, 0); wordBuilder.addParagraphContent("Section " + sectionFileTransformerModel.getOrdinal(), document, ParagraphStyle.HEADER1, BigInteger.ZERO, 0);
XWPFParagraph sectionInfoParagraph = document.createParagraph(); XWPFParagraph sectionInfoParagraph = document.createParagraph();
sectionInfoParagraph.setSpacingBetween(1.0); sectionInfoParagraph.setSpacingBetween(1.0);
XWPFRun runSectionTitle = sectionInfoParagraph.createRun(); XWPFRun runSectionTitle = sectionInfoParagraph.createRun();
runSectionTitle.setText("Title: "); runSectionTitle.setText("Title: ");
runSectionTitle.setColor("000000"); runSectionTitle.setColor("000000");
XWPFRun runSectionTitleText = sectionInfoParagraph.createRun(); XWPFRun runSectionTitleText = sectionInfoParagraph.createRun();
runSectionTitleText.setText(section.getLabel()); runSectionTitleText.setText(sectionFileTransformerModel.getLabel());
runSectionTitleText.setColor("116a78"); runSectionTitleText.setColor("116a78");
XWPFParagraph sectionDescriptionParagraph = document.createParagraph(); XWPFParagraph sectionDescriptionParagraph = document.createParagraph();
XWPFRun runSectionDescription = sectionDescriptionParagraph.createRun(); XWPFRun runSectionDescription = sectionDescriptionParagraph.createRun();
runSectionDescription.setText("Description: "); runSectionDescription.setText("Description: ");
runSectionDescription.setColor("000000"); runSectionDescription.setColor("000000");
XWPFRun runSectionDescriptionText = sectionDescriptionParagraph.createRun(); XWPFRun runSectionDescriptionText = sectionDescriptionParagraph.createRun();
runSectionDescriptionText.setText(section.getDescription()); runSectionDescriptionText.setText(sectionFileTransformerModel.getDescription());
runSectionDescriptionText.setColor("116a78"); runSectionDescriptionText.setColor("116a78");
wordBuilder.addParagraphContent("Section Fields", document, ParagraphStyle.HEADER2, BigInteger.ZERO, 0); wordBuilder.addParagraphContent("Section Fields", document, ParagraphStyle.HEADER2, BigInteger.ZERO, 0);
section.getFields().sort(Comparator.comparingInt(Field::getOrdinal)); sectionFileTransformerModel.getFields().sort(Comparator.comparingInt(FieldFileTransformerModel::getOrdinal));
for(Field field: section.getFields()){ for(FieldFileTransformerModel fieldFileTransformerModel : sectionFileTransformerModel.getFields()){
if(field.getCategory() == DmpBlueprintFieldCategory.System){ if(fieldFileTransformerModel.getCategory() == DmpBlueprintFieldCategory.System){
SystemField systemField = (SystemField) field; SystemFieldFileTransformerModel systemField = (SystemFieldFileTransformerModel) fieldFileTransformerModel;
XWPFParagraph systemFieldParagraph = document.createParagraph(); XWPFParagraph systemFieldParagraph = document.createParagraph();
systemFieldParagraph.setSpacingBetween(1.0); systemFieldParagraph.setSpacingBetween(1.0);
XWPFRun runSyStemFieldTitle = systemFieldParagraph.createRun(); XWPFRun runSyStemFieldTitle = systemFieldParagraph.createRun();
@ -252,14 +251,14 @@ public class WordFileTransformer implements FileTransformerExecutor {
runDescription.setColor("116a78"); runDescription.setColor("116a78");
break; break;
case Researchers: case Researchers:
for(Reference researcher: researchers){ for(ReferenceFileTransformerModel researcher: researchers){
XWPFRun runResearcher = systemFieldInput.createRun(); XWPFRun runResearcher = systemFieldInput.createRun();
runResearcher.setText("" + researcher.getLabel()); runResearcher.setText("" + researcher.getLabel());
runResearcher.setColor("116a78"); runResearcher.setColor("116a78");
} }
break; break;
case Organizations: case Organizations:
for(Reference organisation: organizations){ for(ReferenceFileTransformerModel organisation: organizations){
XWPFRun runOrganisation = systemFieldInput.createRun(); XWPFRun runOrganisation = systemFieldInput.createRun();
runOrganisation.setText("" + organisation.getLabel()); runOrganisation.setText("" + organisation.getLabel());
runOrganisation.setColor("116a78"); runOrganisation.setColor("116a78");
@ -313,22 +312,22 @@ public class WordFileTransformer implements FileTransformerExecutor {
} }
document.createParagraph(); document.createParagraph();
} }
else if(field.getCategory() == DmpBlueprintFieldCategory.Extra){ else if(fieldFileTransformerModel.getCategory() == DmpBlueprintFieldCategory.Extra){
ExtraField extraField = (ExtraField) field; ExtraFieldFileTransformerModelFileTransformerModel extraFieldFileTransformerModel = (ExtraFieldFileTransformerModelFileTransformerModel) fieldFileTransformerModel;
XWPFParagraph extraFieldParagraph = document.createParagraph(); XWPFParagraph extraFieldParagraph = document.createParagraph();
extraFieldParagraph.setSpacingBetween(1.0); extraFieldParagraph.setSpacingBetween(1.0);
XWPFRun runExtraFieldLabel = extraFieldParagraph.createRun(); XWPFRun runExtraFieldLabel = extraFieldParagraph.createRun();
runExtraFieldLabel.setText(extraField.getLabel()); runExtraFieldLabel.setText(extraFieldFileTransformerModel.getLabel());
runExtraFieldLabel.setColor("116a78"); runExtraFieldLabel.setColor("116a78");
if(extraField.getDescription() != null && !extraField.getDescription().isEmpty()){ if(extraFieldFileTransformerModel.getDescription() != null && !extraFieldFileTransformerModel.getDescription().isEmpty()){
XWPFRun runExtraFieldDescription = extraFieldParagraph.createRun(); XWPFRun runExtraFieldDescription = extraFieldParagraph.createRun();
runExtraFieldDescription.setText(extraField.getDescription()); runExtraFieldDescription.setText(extraFieldFileTransformerModel.getDescription());
runExtraFieldDescription.setColor("116a78"); runExtraFieldDescription.setColor("116a78");
} }
XWPFRun runExtraFieldInput = extraFieldParagraph.createRun(); XWPFRun runExtraFieldInput = extraFieldParagraph.createRun();
Map dmpProperties = objectMapper.readValue(dmpEntity.getProperties(), HashMap.class); Map dmpProperties = objectMapper.readValue(dmpEntity.getProperties(), HashMap.class);
if (dmpProperties.containsKey(field.getId()) && dmpProperties.get(field.getId()) != null) { if (dmpProperties.containsKey(fieldFileTransformerModel.getId()) && dmpProperties.get(fieldFileTransformerModel.getId()) != null) {
runExtraFieldInput.setText((String) dmpProperties.get(field.getId())); runExtraFieldInput.setText((String) dmpProperties.get(fieldFileTransformerModel.getId()));
} }
runExtraFieldInput.setColor("116a78"); runExtraFieldInput.setColor("116a78");
} }
@ -338,26 +337,25 @@ public class WordFileTransformer implements FileTransformerExecutor {
final Boolean isPublic = dmpEntity.getPublicAfter() != null && dmpEntity.getPublicAfter().isAfter(Instant.now()); final Boolean isPublic = dmpEntity.getPublicAfter() != null && dmpEntity.getPublicAfter().isAfter(Instant.now());
List<DescriptionFileTransformerModel> descriptions = dmpEntity.getDescriptions().stream() List<DescriptionFileTransformerModel> descriptions = dmpEntity.getDescriptions().stream()
.filter(item -> item.getStatus() != DescriptionStatus.Canceled) .filter(item -> item.getStatus() != DescriptionStatus.Canceled)
.filter(item -> item.getIsActive() != IsActive.Inactive)
.filter(item -> !isPublic && !isFinalized || item.getStatus() == DescriptionStatus.Finalized) .filter(item -> !isPublic && !isFinalized || item.getStatus() == DescriptionStatus.Finalized)
.filter(item -> item.getDmpDescriptionTemplate().getSectionId().equals(section.getId())) //TODO .filter(item -> item.getSectionId().equals(sectionFileTransformerModel.getId())) //TODO
.sorted(Comparator.comparing(DescriptionFileTransformerModel::getCreatedAt)).toList(); .sorted(Comparator.comparing(DescriptionFileTransformerModel::getCreatedAt)).toList();
List<eu.eudat.file.transformer.model.DescriptionTemplate> descriptionTemplates = descriptions.stream().map(DescriptionFileTransformerModel::getDescriptionTemplate).toList(); List<DescriptionTemplateFileTransformerModel> descriptionTemplateFileTransformerModels = descriptions.stream().map(DescriptionFileTransformerModel::getDescriptionTemplate).toList();
if(!descriptionTemplates.isEmpty()){ if(!descriptionTemplateFileTransformerModels.isEmpty()){
wordBuilder.addParagraphContent("Section descriptions", document, ParagraphStyle.HEADER2, BigInteger.ZERO, 0); wordBuilder.addParagraphContent("Section descriptions", document, ParagraphStyle.HEADER2, BigInteger.ZERO, 0);
wordBuilder.addParagraphContent("Description Templates", document, ParagraphStyle.HEADER4, BigInteger.ZERO, 0); wordBuilder.addParagraphContent("Description Templates", document, ParagraphStyle.HEADER4, BigInteger.ZERO, 0);
for(DescriptionTemplate descriptionTemplateEntity : descriptionTemplates){ for(DescriptionTemplateFileTransformerModel descriptionTemplateFileTransformerModelEntity : descriptionTemplateFileTransformerModels){
XWPFParagraph templateParagraph = document.createParagraph(); XWPFParagraph templateParagraph = document.createParagraph();
XWPFRun runTemplateLabel = templateParagraph.createRun(); XWPFRun runTemplateLabel = templateParagraph.createRun();
runTemplateLabel.setText("" + descriptionTemplateEntity.getLabel()); runTemplateLabel.setText("" + descriptionTemplateFileTransformerModelEntity.getLabel());
runTemplateLabel.setColor("116a78"); runTemplateLabel.setColor("116a78");
} }
descriptions descriptions
.forEach(datasetEntity -> { .forEach(datasetEntity -> {
eu.eudat.file.transformer.model.DescriptionTemplate descriptionTemplateFileModel = datasetEntity.getDescriptionTemplate(); DescriptionTemplateFileTransformerModel descriptionTemplateFileTransformerModelFileModel = datasetEntity.getDescriptionTemplate();
// Dataset Description custom style. // Dataset Description custom style.
XWPFParagraph datasetDescriptionParagraph = document.createParagraph(); XWPFParagraph datasetDescriptionParagraph = document.createParagraph();
@ -394,7 +392,7 @@ public class WordFileTransformer implements FileTransformerExecutor {
//runDatasetTemplate1.setBold(true); //runDatasetTemplate1.setBold(true);
//runDatasetTemplate1.setFontSize(12); //runDatasetTemplate1.setFontSize(12);
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun(); XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
runDatasetTemplate.setText(descriptionTemplateFileModel.getLabel()); runDatasetTemplate.setText(descriptionTemplateFileTransformerModelFileModel.getLabel());
runDatasetTemplate.setColor("116a78"); runDatasetTemplate.setColor("116a78");
//runDatasetTemplate.setBold(true); //runDatasetTemplate.setBold(true);
//runDatasetTemplate.setFontSize(12); //runDatasetTemplate.setFontSize(12);
@ -440,7 +438,7 @@ public class WordFileTransformer implements FileTransformerExecutor {
runDatasetDescription1.setText("Description: "); runDatasetDescription1.setText("Description: ");
runDatasetDescription1.setColor("000000"); runDatasetDescription1.setColor("000000");
XWPFRun runDatasetDescription = datasetDescParagraph.createRun(); XWPFRun runDatasetDescription = datasetDescParagraph.createRun();
runDatasetDescription.setText(descriptionTemplateFileModel.getLabel()); runDatasetDescription.setText(descriptionTemplateFileTransformerModelFileModel.getLabel());
runDatasetDescription.setColor("116a78"); runDatasetDescription.setColor("116a78");
//wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0); //wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0);
@ -448,13 +446,7 @@ public class WordFileTransformer implements FileTransformerExecutor {
try { try {
PagedDatasetProfile pagedDatasetProfile = DescriptionTemplateService.getPagedProfile(datasetEntity); wordBuilder.build(document, datasetEntity.getDescriptionTemplate());
visibilityRuleService.setProperties(datasetEntity.getProperties());
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
//pagedDatasetProfile = this.objectMapper.readValue(this.objectMapper.writeValueAsString(pagedDatasetProfile), eu.eudat.file.transformer.model.descriptiontemplatedefinition.Definition.class);
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
@ -525,7 +517,6 @@ public class WordFileTransformer implements FileTransformerExecutor {
throw new IllegalArgumentException("Dmp is invalid"); throw new IllegalArgumentException("Dmp is invalid");
} }
XWPFDocument document = new XWPFDocument(new FileInputStream(ResourceUtils.getFile(fileTemplateProperties.getWordDescriptionTemplate()))); XWPFDocument document = new XWPFDocument(new FileInputStream(ResourceUtils.getFile(fileTemplateProperties.getWordDescriptionTemplate())));
VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl();
wordBuilder.fillFirstPage(dmpEntity, descriptionFileTransformerModelEntityEntity, document, true); wordBuilder.fillFirstPage(dmpEntity, descriptionFileTransformerModelEntityEntity, document, true);
wordBuilder.fillFooter(dmpEntity, descriptionFileTransformerModelEntityEntity, document, true); wordBuilder.fillFooter(dmpEntity, descriptionFileTransformerModelEntityEntity, document, true);
@ -592,10 +583,7 @@ public class WordFileTransformer implements FileTransformerExecutor {
}*/ }*/
// wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO); // wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
PagedDatasetProfile pagedDatasetProfile = DescriptionTemplateService.getPagedProfile(descriptionFileTransformerModelEntityEntity); wordBuilder.build(document, descriptionFileTransformerModelEntityEntity.getDescriptionTemplate());
visibilityRuleService.setProperties(descriptionFileTransformerModelEntityEntity.getProperties());
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
String label = descriptionFileTransformerModelEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", ""); String label = descriptionFileTransformerModelEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", "");
// File exportFile = new File(label + ".docx"); // File exportFile = new File(label + ".docx");

View File

@ -2,8 +2,8 @@ package eu.eudat.file.transformer.model.enums;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.annotation.JsonValue;
import eu.eudat.file.transformer.entities.descriptiontemplate.fielddata.AutoCompleteDataEntity;
import eu.eudat.file.transformer.enums.DatabaseEnum; import eu.eudat.file.transformer.enums.DatabaseEnum;
import eu.eudat.file.transformer.enums.DmpVersionStatus;
import eu.eudat.file.transformer.enums.EnumUtils; import eu.eudat.file.transformer.enums.EnumUtils;
import java.util.Map; import java.util.Map;

View File

@ -1,40 +0,0 @@
package eu.eudat.file.transformer.model.visibility;
public class Rule {
private String sourceField;
private String targetField;
private String requiredValue;
private String type;
public String getSourceField() {
return sourceField;
}
public void setSourceField(String sourceField) {
this.sourceField = sourceField;
}
public String getTargetField() {
return targetField;
}
public void setTargetField(String targetField) {
this.targetField = targetField;
}
public String getRequiredValue() {
return requiredValue;
}
public void setRequiredValue(String requiredValue) {
this.requiredValue = requiredValue;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

View File

@ -1,53 +0,0 @@
package eu.eudat.file.transformer.model.visibility;
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.Definition;
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.Field;
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.FieldSet;
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.Section;
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.fielddata.BaseFieldData;
import java.util.ArrayList;
import java.util.List;
public class RuleMapper {
public static List<Rule> mapRulesFromDefinition(Definition definitionFileModel) {
return definitionFileModel.getSections().stream().flatMap(section -> mapRulesFromSection(section).stream()).toList();
}
private static List<Rule> mapRulesFromSection(Section section) {
List<Rule> rules = new ArrayList<>();
if (!section.getSections().isEmpty()) {
rules.addAll(section.getSections().stream().flatMap(section1 -> mapRulesFromSection(section1).stream()).toList());
}
if (!section.getFieldSets().isEmpty()) {
rules.addAll(section.getFieldSets().stream().flatMap(fieldSet -> mapRuleFromFieldSet(fieldSet).stream()).toList());
}
return rules;
}
private static List<Rule> mapRuleFromFieldSet(FieldSet fieldSet) {
List<Rule> rules = new ArrayList<>();
if (!fieldSet.getFields().isEmpty()) {
rules.addAll(fieldSet.getFields().stream().flatMap(field -> mapRules(field).stream()).toList());
}
return rules;
}
private static List<Rule> mapRules(Field field) {
List<Rule> rules = new ArrayList<>();
BaseFieldData data = field.getData();
field.getVisibilityRules().forEach(visibilityRule -> {
Rule rule = new Rule();
rule.setSourceField(field.getId());
rule.setType(data.getFieldType().getValue());
rule.setRequiredValue(visibilityRule.getValue());
rule.setTargetField(visibilityRule.getTarget());
rules.add(rule);
});
return rules;
}
}

View File

@ -1,44 +0,0 @@
package eu.eudat.file.transformer.services.visibility;
import eu.eudat.file.transformer.entities.user.components.commons.Rule;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
/**
* Created by ikalyvas on 3/5/2018.
*/
public class VisibilityContext {
private List<VisibilityRule> visibilityRules = new LinkedList<>();
public List<VisibilityRule> getVisibilityRules() {
return visibilityRules;
}
public VisibilityRule get(String id) {
Optional<VisibilityRule> rule = visibilityRules.stream().filter(item -> item.getVisibilityRuleTargetId().equals(id)).findFirst();
if (rule.isPresent()) return rule.get();
return null;
}
public void buildVisibilityContext(List<Rule> sources) {
sources.forEach(this::addToVisibilityRulesContext);
}
private void addToVisibilityRulesContext(Rule item) {
VisibilityRuleSource source = new VisibilityRuleSource();
source.setVisibilityRuleSourceId(item.getSourceField());
source.setVisibilityRuleSourceValue(item.getRequiredValue());
Optional<VisibilityRule> visibilityRuleOptional = visibilityRules.stream().filter(rule -> rule.getVisibilityRuleTargetId().equals(item.getTargetField())).findFirst();
if (visibilityRuleOptional.isPresent()) visibilityRuleOptional.get().getVisibilityRuleSources().add(source);
else {
List<VisibilityRuleSource> sources = new LinkedList<>();
sources.add(source);
VisibilityRule visibilityRule = new VisibilityRule();
visibilityRule.setVisibilityRuleTargetId(item.getTargetField());
visibilityRule.setVisibilityRuleSources(sources);
this.visibilityRules.add(visibilityRule);
}
}
}

View File

@ -1,27 +0,0 @@
package eu.eudat.file.transformer.services.visibility;
import java.util.List;
/**
* Created by ikalyvas on 3/5/2018.
*/
public class VisibilityRule {
private String visibilityRuleTargetId;
private List<VisibilityRuleSource> visibilityRuleSources;
public String getVisibilityRuleTargetId() {
return visibilityRuleTargetId;
}
public void setVisibilityRuleTargetId(String visibilityRuleTargetId) {
this.visibilityRuleTargetId = visibilityRuleTargetId;
}
public List<VisibilityRuleSource> getVisibilityRuleSources() {
return visibilityRuleSources;
}
public void setVisibilityRuleSources(List<VisibilityRuleSource> visibilityRuleSources) {
this.visibilityRuleSources = visibilityRuleSources;
}
}

View File

@ -1,17 +0,0 @@
package eu.eudat.file.transformer.services.visibility;
import eu.eudat.file.transformer.entities.user.components.commons.Rule;
import eu.eudat.file.transformer.model.descriptionproperties.PropertyDefinition;
import java.util.List;
/**
* Created by ikalyvas on 3/5/2018.
*/
public interface VisibilityRuleService {
boolean isElementVisible(String id);
void buildVisibilityContext(List<Rule> sources);
void setProperties(PropertyDefinition properties);
}

View File

@ -1,73 +0,0 @@
package eu.eudat.file.transformer.services.visibility;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.file.transformer.entities.user.components.commons.Rule;
import eu.eudat.file.transformer.model.descriptionproperties.Field;
import eu.eudat.file.transformer.model.descriptionproperties.PropertyDefinition;
import java.util.*;
/**
* Created by ikalyvas on 3/5/2018.
*/
public class VisibilityRuleServiceImpl implements VisibilityRuleService {
private final Map<String, Boolean> elementVisibility = new HashMap<>();
private PropertyDefinition properties;
private ObjectMapper mapper;
public VisibilityRuleServiceImpl() {
this.mapper = new ObjectMapper();
}
public boolean isElementVisible(String id) {
return !this.elementVisibility.containsKey(id) || this.elementVisibility.get(id);
}
public void setProperties(PropertyDefinition properties) {
this.properties = properties;
/*this.properties.entrySet().stream()
.filter(stringObjectEntry -> stringObjectEntry.getValue() instanceof String && ((String) stringObjectEntry.getValue()).startsWith("[")
&& ((String) stringObjectEntry.getValue()).endsWith("]"))
.forEach(stringObjectEntry -> stringObjectEntry.setValue(parseArray((String) stringObjectEntry.getValue())));*/
}
private List<String> parseArray(String original) {
String parsed = original.replace("[", "").replace("\"", "").replace("]", "");
return Arrays.asList(parsed.split(","));
}
public void buildVisibilityContext(List<Rule> sources) {
VisibilityContext visibilityContext = new VisibilityContext();
visibilityContext.buildVisibilityContext(sources);
visibilityContext.getVisibilityRules().forEach(this::evaluateVisibility);
}
private void evaluateVisibility(VisibilityRule rule) {
List<VisibilityRuleSource> sources = rule.getVisibilityRuleSources();
for(VisibilityRuleSource source: sources){
Field fieldFileModel = properties.getFields().stream().filter(fieldFileModel1 -> fieldFileModel1.getKey().equals(source.getVisibilityRuleSourceId())).findFirst().orElse(null);
if (fieldFileModel != null
&& isContained(fieldFileModel, source.getVisibilityRuleSourceValue())) {
this.elementVisibility.put(rule.getVisibilityRuleTargetId(), true);
} else {
this.elementVisibility.put(rule.getVisibilityRuleTargetId(),
this.elementVisibility.getOrDefault(rule.getVisibilityRuleTargetId(), false));
}
}
}
private Boolean isContained(Field values, String source) {
try {
Object value = mapper.readValue(values.getValue(), Object.class);
if (value instanceof Collection) {
return ((Collection<?>) value).contains(source);
} else {
if (value != null) {
return value.toString().equals(source);
}
return false;
}
} catch (JsonProcessingException e) {
return false;
}
}
}

View File

@ -1,25 +0,0 @@
package eu.eudat.file.transformer.services.visibility;
/**
* Created by ikalyvas on 3/5/2018.
*/
public class VisibilityRuleSource {
private String visibilityRuleSourceId;
private String visibilityRuleSourceValue;
public String getVisibilityRuleSourceId() {
return visibilityRuleSourceId;
}
public void setVisibilityRuleSourceId(String visibilityRuleSourceId) {
this.visibilityRuleSourceId = visibilityRuleSourceId;
}
public String getVisibilityRuleSourceValue() {
return visibilityRuleSourceValue;
}
public void setVisibilityRuleSourceValue(String visibilityRuleSourceValue) {
this.visibilityRuleSourceValue = visibilityRuleSourceValue;
}
}

View File

@ -1,31 +0,0 @@
package eu.eudat.file.transformer.utils.descriptionTemplate;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.file.transformer.entities.descriptiontemplate.DefinitionEntity;
import eu.eudat.file.transformer.entities.user.composite.DatasetProfile;
import eu.eudat.file.transformer.entities.user.composite.PagedDatasetProfile;
import eu.eudat.file.transformer.model.DescriptionFileTransformerModel;
import eu.eudat.file.transformer.model.DescriptionTemplate;
public class DescriptionTemplateService {
public static PagedDatasetProfile getPagedProfile(DescriptionFileTransformerModel dataset) throws JsonProcessingException {
DatasetProfile datasetprofile = generateDatasetProfileModel(dataset.getDescriptionTemplate());
datasetprofile.setStatus(dataset.getStatus().getValue());
if (dataset.getProperties() != null) {
datasetprofile.fromJsonObject(dataset.getProperties().getFields());
}
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile);
return pagedDatasetProfile;
}
public static DatasetProfile generateDatasetProfileModel(DescriptionTemplate profile) {
DefinitionEntity viewstyle = new DefinitionEntity().fromDefinition(profile.getDefinition());
DatasetProfile datasetprofile = new DatasetProfile();
datasetprofile.buildProfile(viewstyle);
return datasetprofile;
}
}

View File

@ -1,8 +0,0 @@
package eu.eudat.file.transformer.utils.interfaces;
/**
* Created by ikalyvas on 3/1/2018.
*/
public interface Applier<A, V> {
void apply(A applier, V value);
}

View File

@ -1,8 +0,0 @@
package eu.eudat.file.transformer.utils.interfaces;
/**
* Created by ikalyvas on 2/5/2018.
*/
public interface Cloneable<T> {
T clone();
}

View File

@ -1,8 +0,0 @@
package eu.eudat.file.transformer.utils.interfaces;
import eu.eudat.file.transformer.entities.common.DatabaseModelDefinition;
public interface ModelSerializer<T, U extends DatabaseModelDefinition> {
void fromDatabaseDefinition(T viewStyle, U model);
}

View File

@ -1,13 +0,0 @@
package eu.eudat.file.transformer.utils.json;
public class JavaToJson {
public static String objectStringToJson(String object) {
String result = object.replaceAll("=", "\":\"")
.replaceAll("\\{", "{\"")
.replaceAll(", ", "\", \"")
.replaceAll("}", "\"}" )
.replaceAll("}\", \"\\{", "}, {");
return result;
}
}

View File

@ -1,81 +0,0 @@
package eu.eudat.file.transformer.utils.json;
import com.fasterxml.jackson.databind.JsonNode;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class JsonSearcher {
public static List<JsonNode> findNodes(JsonNode root, String key, String value) {
return findNodes(root, key, value, false);
}
public static List<JsonNode> findNodes(JsonNode root, String key, String value, boolean parent) {
List<JsonNode> nodes = new ArrayList<>();
for (Iterator<JsonNode> it = root.elements(); it.hasNext(); ) {
JsonNode node = it.next();
int found = 0;
for (Iterator<String> iter = node.fieldNames(); iter.hasNext(); ) {
String fieldName = iter.next();
if (fieldName.equals(key)) {
if (node.get(fieldName).asText().equals(value) || node.get(fieldName).asText().startsWith(value)) {
if (parent) {
nodes.add(root);
} else {
nodes.add(node);
}
found++;
}
else if(node.get(fieldName).isArray()){
for(JsonNode item: node.get(fieldName)){
if(item.asText().equals(value) || item.asText().startsWith(value)){
if (parent) {
nodes.add(root);
} else {
nodes.add(node);
}
found++;
}
}
}
}
}
if (found == 0) {
nodes.addAll(findNodes(node, key, value, parent));
}
}
return nodes;
}
public static List<String> getParentValues(JsonNode root, String childValue, String key) {
List<String> values = new LinkedList<>();
for (Iterator<JsonNode> it = root.elements(); it.hasNext(); ) {
JsonNode node = it.next();
int found = 0;
for (Iterator<String> iter = node.fieldNames(); iter.hasNext(); ) {
String fieldName = iter.next();
if (fieldName.equals(key)) {
if (node.get(fieldName).asText().equals(childValue) || node.get(fieldName).asText().startsWith(childValue)) {
values.add(childValue);
found++;
}
}
}
if (found == 0) {
values.addAll(getParentValues(node, childValue, key));
if (!values.isEmpty() && node.has(key)) {
values.add(node.get(key).asText());
values.remove(childValue);
}
}
}
return values;
}
}

View File

@ -1,41 +0,0 @@
package eu.eudat.file.transformer.utils.json;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
public class MultiDateDeserializer extends StdDeserializer<Date> {
private static final List<String> DATE_FORMATS = Arrays.asList("yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ss.S");
public MultiDateDeserializer() {
super(Date.class);
}
protected MultiDateDeserializer(Class<?> vc) {
super(vc);
}
@Override
public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
String text = p.getText();
for (String dateFormat: DATE_FORMATS) {
try {
return new SimpleDateFormat(dateFormat).parse(text);
} catch (ParseException ignored) {
}
}
throw new JsonParseException(p, "No supported Date format");
}
}

View File

@ -5,18 +5,19 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.file.transformer.configuration.FilePathProperties; import eu.eudat.file.transformer.configuration.FilePathProperties;
import eu.eudat.file.transformer.configuration.FileStorageProperties; import eu.eudat.file.transformer.configuration.FileStorageProperties;
import eu.eudat.file.transformer.entities.descriptiontemplate.fielddata.*;
import eu.eudat.file.transformer.entities.user.components.datasetprofile.Field;
import eu.eudat.file.transformer.entities.user.components.datasetprofile.FieldSet;
import eu.eudat.file.transformer.entities.user.components.datasetprofile.Section;
import eu.eudat.file.transformer.entities.user.composite.DatasetProfilePage;
import eu.eudat.file.transformer.entities.user.composite.PagedDatasetProfile;
import eu.eudat.file.transformer.enums.FieldDataComboBoxType;
import eu.eudat.file.transformer.enums.FieldType; import eu.eudat.file.transformer.enums.FieldType;
import eu.eudat.file.transformer.enums.IsActive;
import eu.eudat.file.transformer.enums.ReferenceType; import eu.eudat.file.transformer.enums.ReferenceType;
import eu.eudat.file.transformer.model.*; import eu.eudat.file.transformer.model.*;
import eu.eudat.file.transformer.services.visibility.VisibilityRuleService; import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel;
import eu.eudat.file.transformer.models.descriptiontemplate.definition.FieldFileTransformerModel;
import eu.eudat.file.transformer.models.descriptiontemplate.definition.FieldSetFileTransformerModel;
import eu.eudat.file.transformer.models.descriptiontemplate.definition.PageFileTransformerModel;
import eu.eudat.file.transformer.models.descriptiontemplate.definition.SectionFileTransformerModel;
import eu.eudat.file.transformer.models.descriptiontemplate.definition.fielddata.*;
import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
import eu.eudat.file.transformer.models.dmp.DmpReferenceFileTransformerModel;
import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel;
import eu.eudat.file.transformer.utils.interfaces.ApplierWithValue; import eu.eudat.file.transformer.utils.interfaces.ApplierWithValue;
import eu.eudat.file.transformer.utils.pid.PidLoader; import eu.eudat.file.transformer.utils.pid.PidLoader;
import eu.eudat.file.transformer.utils.types.ParagraphStyle; import eu.eudat.file.transformer.utils.types.ParagraphStyle;
@ -269,7 +270,7 @@ public class WordBuilder {
}); });
} }
public XWPFDocument build(XWPFDocument document, PagedDatasetProfile pagedDatasetProfile, VisibilityRuleService visibilityRuleService) throws IOException { public XWPFDocument build(XWPFDocument document, DescriptionTemplateFileTransformerModel descriptionTemplate) throws IOException {
// createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService); // createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService);
// XWPFNumbering numbering = document.createNumbering(); // XWPFNumbering numbering = document.createNumbering();
// BigInteger tempNumId = BigInteger.ONE; // BigInteger tempNumId = BigInteger.ONE;
@ -284,50 +285,47 @@ public class WordBuilder {
// BigInteger abstractNumID = numbering.addAbstractNum(abstractNum); // BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
// this.numId = numbering.addNum(abstractNumID); // this.numId = numbering.addNum(abstractNumID);
createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService); createPages(descriptionTemplate.getDefinition().getPages(), document, false);
return document; return document;
} }
private void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing, VisibilityRuleService visibilityRuleService) { private void createPages(List<PageFileTransformerModel> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing) {
datasetProfilePages.forEach(item -> { datasetProfilePages.forEach(item -> {
try { try {
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, 0, createListing, visibilityRuleService, item.getOrdinal() + 1, null); createSections(item.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, 0, createListing, item.getOrdinal() + 1, null);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
}); });
} }
private void createSections(List<Section> sections, XWPFDocument mainDocumentPart, ParagraphStyle style, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService, Integer page, String sectionString) { private void createSections(List<SectionFileTransformerModel> sections, XWPFDocument mainDocumentPart, ParagraphStyle style, Integer indent, Boolean createListing, Integer page, String sectionString) {
if (createListing) this.addListing(mainDocumentPart, indent, false, true); if (createListing) this.addListing(mainDocumentPart, indent, false, true);
boolean hasValue = false; boolean hasValue = false;
for (Section section: sections) { for (SectionFileTransformerModel section: sections) {
int paragraphPos = -1; int paragraphPos = -1;
String tempSectionString = sectionString != null ? sectionString + "." + (section.getOrdinal() + 1) : "" + (section.getOrdinal() + 1); String tempSectionString = sectionString != null ? sectionString + "." + (section.getOrdinal() + 1) : "" + (section.getOrdinal() + 1);
if (visibilityRuleService.isElementVisible(section.getId())) { if (!createListing) {
if (!createListing) { XWPFParagraph paragraph = addParagraphContent(page + "." + tempSectionString + " " + section.getTitle(), mainDocumentPart, style, numId, indent);
XWPFParagraph paragraph = addParagraphContent(page + "." + tempSectionString + " " + section.getTitle(), mainDocumentPart, style, numId, indent);
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); // CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
// number.setVal(BigInteger.valueOf(indent)); // number.setVal(BigInteger.valueOf(indent));
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph); paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
} }
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, indent+1, createListing, visibilityRuleService, page, tempSectionString); createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, indent + 1, createListing, page, tempSectionString);
hasValue = createCompositeFields(section.getCompositeFields(), mainDocumentPart, indent+1, createListing, visibilityRuleService, page, tempSectionString); hasValue = createCompositeFields(section.getFieldSets(), mainDocumentPart, indent + 1, createListing, page, tempSectionString);
if (!hasValue && paragraphPos > -1) { if (!hasValue && paragraphPos > -1) {
mainDocumentPart.removeBodyElement(paragraphPos); mainDocumentPart.removeBodyElement(paragraphPos);
}
} }
} }
} }
private Boolean createCompositeFields(List<FieldSet> compositeFields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService, Integer page, String section) { private Boolean createCompositeFields(List<FieldSetFileTransformerModel> compositeFields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, Integer page, String section) {
if (createListing) this.addListing(mainDocumentPart, indent, true, true); if (createListing) this.addListing(mainDocumentPart, indent, true, true);
boolean hasValue = false; boolean hasValue = false;
boolean returnedValue = false; boolean returnedValue = false;
for (FieldSet compositeField: compositeFields) { for (FieldSetFileTransformerModel compositeField: compositeFields) {
if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) {
char c = 'a'; char c = 'a';
int multiplicityItems = 0; int multiplicityItems = 0;
boolean hasMultiplicityItems = false; boolean hasMultiplicityItems = false;
@ -338,12 +336,13 @@ public class WordBuilder {
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); // CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
// number.setVal(BigInteger.valueOf(indent)); // number.setVal(BigInteger.valueOf(indent));
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph); paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
if(compositeField.getMultiplicity() != null && !compositeField.getMultiplicity().getTableView() && compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()){ //TODO: dtziotzios implement multiplicity
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId, indent); // if(compositeField.getMultiplicity() != null && !compositeField.getMultiplicity().getTableView() && compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()){
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner); // XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId, indent);
hasMultiplicityItems = true; // paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
multiplicityItems++; // hasMultiplicityItems = true;
} // multiplicityItems++;
// }
} }
XWPFTable tbl = null; XWPFTable tbl = null;
XWPFTableRow row = null; XWPFTableRow row = null;
@ -352,15 +351,15 @@ public class WordBuilder {
tbl = mainDocumentPart.createTable(); tbl = mainDocumentPart.createTable();
tbl.setTableAlignment(TableRowAlign.CENTER); tbl.setTableAlignment(TableRowAlign.CENTER);
mainDocumentPart.createParagraph(); mainDocumentPart.createParagraph();
createHeadersInTable(compositeField.getFields(), tbl, visibilityRuleService); createHeadersInTable(compositeField.getFields(), tbl);
numOfRows = tbl.getRows().size(); numOfRows = tbl.getRows().size();
row = tbl.createRow(); row = tbl.createRow();
} }
if(compositeField.getMultiplicity() != null && compositeField.getMultiplicity().getTableView()) { if(compositeField.getMultiplicity() != null && compositeField.getMultiplicity().getTableView()) {
hasValue = createFieldsInTable(compositeField.getFields(), row, indent, createListing, visibilityRuleService, hasMultiplicityItems, numOfRows); hasValue = createFieldsInTable(compositeField.getFields(), row, indent, createListing, hasMultiplicityItems, numOfRows);
numOfRows++; numOfRows++;
} else { } else {
hasValue = createFields(compositeField.getFields(), mainDocumentPart, indent, createListing, visibilityRuleService, hasMultiplicityItems); hasValue = createFields(compositeField.getFields(), mainDocumentPart, indent, createListing, hasMultiplicityItems);
} }
if(hasValue){ if(hasValue){
returnedValue = true; returnedValue = true;
@ -370,44 +369,45 @@ public class WordBuilder {
multiplicityItems--; multiplicityItems--;
} }
//TODO: Multiplicity Items??? //TODO: Multiplicity Items???
if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) { //TODO: dtziotzios implement multiplicity
List<FieldSet> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList()); // if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) {
for (FieldSet multiplicityFieldset : list) { // List<FieldSetFileTransformerModel> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSetFileTransformerModel::getOrdinal)).collect(Collectors.toList());
paragraphPosInner = -1; // for (FieldSetFileTransformerModel multiplicityFieldset : list) {
if(!compositeField.getMultiplicity().getTableView() && !createListing){ // paragraphPosInner = -1;
c++; // if(!compositeField.getMultiplicity().getTableView() && !createListing){
// addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId); // c++;
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId, indent); //// addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner); // XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId, indent);
hasMultiplicityItems = true; // paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
multiplicityItems++; // hasMultiplicityItems = true;
} // multiplicityItems++;
// hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems); // }
boolean hasValueInner = false; //// hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
if(compositeField.getMultiplicity().getTableView()) { // boolean hasValueInner = false;
row = tbl.createRow(); // if(compositeField.getMultiplicity().getTableView()) {
hasValueInner = createFieldsInTable(multiplicityFieldset.getFields(), row, indent, createListing, visibilityRuleService, hasMultiplicityItems, numOfRows); // row = tbl.createRow();
numOfRows++; // hasValueInner = createFieldsInTable(multiplicityFieldset.getFields(), row, indent, createListing, visibilityRuleService, hasMultiplicityItems, numOfRows);
} else { // numOfRows++;
hasValueInner = createFields(multiplicityFieldset.getFields(), mainDocumentPart, indent, createListing, visibilityRuleService, hasMultiplicityItems); // } else {
} // hasValueInner = createFields(multiplicityFieldset.getFields(), mainDocumentPart, indent, createListing, visibilityRuleService, hasMultiplicityItems);
// if(hasValue){ // }
if(hasValueInner){ //// if(hasValue){
hasValue = true; // if(hasValueInner){
returnedValue = true; // hasValue = true;
} else if(paragraphPosInner > -1){ // returnedValue = true;
mainDocumentPart.removeBodyElement(paragraphPosInner); // } else if(paragraphPosInner > -1){
c--; // mainDocumentPart.removeBodyElement(paragraphPosInner);
multiplicityItems--; // c--;
} // multiplicityItems--;
} // }
if(multiplicityItems == 1) { // }
String text = mainDocumentPart.getLastParagraph().getRuns().get(0).getText(0); // if(multiplicityItems == 1) {
if(text.equals("a. ")) { // String text = mainDocumentPart.getLastParagraph().getRuns().get(0).getText(0);
mainDocumentPart.getLastParagraph().removeRun(0); // if(text.equals("a. ")) {
} // mainDocumentPart.getLastParagraph().removeRun(0);
} // }
} // }
// }
//TODO: Dataset Profile //TODO: Dataset Profile
// if (hasValue && compositeField.getHasCommentField() && compositeField.getCommentFieldValue() != null && !compositeField.getCommentFieldValue().isEmpty() && !createListing) { // 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); // XWPFParagraph paragraph = addParagraphContent("<i>Comment:</i>\n"+compositeField.getCommentFieldValue(), mainDocumentPart, ParagraphStyle.HTML, numId, indent);
@ -417,28 +417,27 @@ public class WordBuilder {
if (!hasValue && paragraphPos > -1) { if (!hasValue && paragraphPos > -1) {
mainDocumentPart.removeBodyElement(paragraphPos); mainDocumentPart.removeBodyElement(paragraphPos);
} }
}
} }
return returnedValue; return returnedValue;
} }
private void createHeadersInTable(List<Field> fields, XWPFTable table, VisibilityRuleService visibilityRuleService) { private void createHeadersInTable(List<FieldFileTransformerModel> fields, XWPFTable table) {
boolean atLeastOneHeader = false; boolean atLeastOneHeader = false;
List<Field> tempFields = fields.stream().sorted(Comparator.comparingInt(Field::getOrdinal)).collect(Collectors.toList()); List<FieldFileTransformerModel> tempFields = fields.stream().sorted(Comparator.comparingInt(FieldFileTransformerModel::getOrdinal)).collect(Collectors.toList());
int index = 0; int index = 0;
XWPFTableRow row = table.getRow(0); XWPFTableRow row = table.getRow(0);
for (Field field: tempFields) { for (FieldFileTransformerModel field: tempFields) {
if (visibilityRuleService.isElementVisible(field.getId()) && field.getExport()) { if (field.getIncludeInExport()) {
XWPFTableCell cell; XWPFTableCell cell;
if(index == 0) { if (index == 0) {
cell = row.getCell(0); cell = row.getCell(0);
} else { } else {
cell = row.createCell(); cell = row.createCell();
} }
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.valueOf("CENTER")); cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.valueOf("CENTER"));
String label = ((BaseFieldDataEntity) field.getData()).getLabel(); String label = ((BaseFieldDataFileTransformerModel) field.getData()).getLabel();
if(label != null && label != "") { if (label != null && label != "") {
XWPFParagraph paragraph = cell.getParagraphs().get(0); XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setIndentationFirstLine(50); paragraph.setIndentationFirstLine(50);
XWPFRun run = paragraph.createRun(); XWPFRun run = paragraph.createRun();
@ -459,17 +458,17 @@ public class WordBuilder {
} }
} }
private Boolean createFieldsInTable(List<Field> fields, XWPFTableRow mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService, boolean hasMultiplicityItems, int numOfRows) { private Boolean createFieldsInTable(List<FieldFileTransformerModel> fields, XWPFTableRow mainDocumentPart, Integer indent, Boolean createListing, boolean hasMultiplicityItems, int numOfRows) {
int numOfCells = 0; int numOfCells = 0;
boolean hasValue = false; boolean hasValue = false;
List<Field> tempFields = fields.stream().sorted(Comparator.comparingInt(Field::getOrdinal)).collect(Collectors.toList()); List<FieldFileTransformerModel> tempFields = fields.stream().sorted(Comparator.comparingInt(FieldFileTransformerModel::getOrdinal)).collect(Collectors.toList());
for (Field field: tempFields) { for (FieldFileTransformerModel field: tempFields) {
if (visibilityRuleService.isElementVisible(field.getId()) && field.getExport()) { if (field.getIncludeInExport()) {
if (!createListing) { if (!createListing) {
try { try {
if(((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.UPLOAD)){ if(((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.UPLOAD)){
boolean isImage = false; boolean isImage = false;
for(UploadDataEntity.Option type: ((UploadDataEntity)field.getData()).getTypes()){ for(UploadOptionFileTransformerModel type: ((UploadDataFileTransformerModel)field.getData()).getTypes()){
String fileFormat = type.getValue(); String fileFormat = type.getValue();
if(IMAGE_TYPE_MAP.containsKey(fileFormat)){ if(IMAGE_TYPE_MAP.containsKey(fileFormat)){
isImage = true; isImage = true;
@ -477,8 +476,8 @@ public class WordBuilder {
} }
} }
if(isImage){ if(isImage){
if (field.getValue() != null && !field.getValue().toString().isEmpty()) { if (field.getData().getValue() != null && !field.getData().getValue().toString().isEmpty()) {
XWPFParagraph paragraph = addCellContent(mapper.convertValue(field.getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId, 0, numOfRows, numOfCells, 0); XWPFParagraph paragraph = addCellContent(mapper.convertValue(field.getData().getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId, 0, numOfRows, numOfCells, 0);
if (paragraph != null) { if (paragraph != null) {
hasValue = true; hasValue = true;
} }
@ -488,15 +487,15 @@ public class WordBuilder {
} }
} }
} }
else if (field.getValue() != null && !field.getValue().toString().isEmpty()) { else if (field.getData().getValue() != null && !field.getData().getValue().toString().isEmpty()) {
this.indent = indent; this.indent = indent;
String format = this.formatter(field); String format = this.formatter(field);
if (((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.TAGS)) { if (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.TAGS)) {
format = getCommaSeparatedFormatsFromJson(format, "name"); format = getCommaSeparatedFormatsFromJson(format, "name");
} else if (((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.COMBO_BOX) && field.getData() instanceof AutoCompleteDataEntity) { } else if (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.AUTO_COMPLETE)) {
format = getCommaSeparatedFormatsFromJson(format, "label"); format = getCommaSeparatedFormatsFromJson(format, "label");
} }
boolean isResearcher = ((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.RESEARCHERS); boolean isResearcher = ((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.RESEARCHERS);
if(format != null && !format.isEmpty()){ if(format != null && !format.isEmpty()){
Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete"); Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete");
boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete; boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete;
@ -528,7 +527,7 @@ public class WordBuilder {
hasMultiplicityItems = false; hasMultiplicityItems = false;
} }
else{ else{
XWPFParagraph paragraph = addCellContent(format, mainDocumentPart, ((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent, numOfRows, numOfCells, numOfValuesInCell); XWPFParagraph paragraph = addCellContent(format, mainDocumentPart, ((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent, numOfRows, numOfCells, numOfValuesInCell);
numOfValuesInCell++; numOfValuesInCell++;
if(orcidResearcher){ if(orcidResearcher){
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId); XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
@ -556,7 +555,7 @@ public class WordBuilder {
hasValue = true; hasValue = true;
} }
else{ else{
XWPFParagraph paragraph = addCellContent(format, mainDocumentPart, ((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent, numOfRows, numOfCells, 0); XWPFParagraph paragraph = addCellContent(format, mainDocumentPart, ((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent, numOfRows, numOfCells, 0);
if (paragraph != null) { if (paragraph != null) {
hasValue = true; hasValue = true;
} }
@ -603,17 +602,17 @@ public class WordBuilder {
} }
} }
private Boolean createFields(List<Field> fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService, boolean hasMultiplicityItems) { private Boolean createFields(List<FieldFileTransformerModel> fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, boolean hasMultiplicityItems) {
if (createListing) this.addListing(mainDocumentPart, indent, false, false); if (createListing) this.addListing(mainDocumentPart, indent, false, false);
boolean hasValue = false; boolean hasValue = false;
List<Field> tempFields = fields.stream().sorted(Comparator.comparingInt(Field::getOrdinal)).collect(Collectors.toList()); List<FieldFileTransformerModel> tempFields = fields.stream().sorted(Comparator.comparingInt(FieldFileTransformerModel::getOrdinal)).collect(Collectors.toList());
for (Field field: tempFields) { for (FieldFileTransformerModel field: tempFields) {
if (visibilityRuleService.isElementVisible(field.getId()) && field.getExport()) { if (field.getIncludeInExport()) {
if (!createListing) { if (!createListing) {
try { try {
if(((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.UPLOAD)){ if(((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.UPLOAD)){
boolean isImage = false; boolean isImage = false;
for(UploadDataEntity.Option type: ((UploadDataEntity)field.getData()).getTypes()){ for(UploadOptionFileTransformerModel type: ((UploadDataFileTransformerModel)field.getData()).getTypes()){
String fileFormat = type.getValue(); String fileFormat = type.getValue();
if(IMAGE_TYPE_MAP.containsKey(fileFormat)){ if(IMAGE_TYPE_MAP.containsKey(fileFormat)){
isImage = true; isImage = true;
@ -621,8 +620,8 @@ public class WordBuilder {
} }
} }
if(isImage){ if(isImage){
if (field.getValue() != null && !field.getValue().toString().isEmpty()) { if (field.getData().getValue() != null && !field.getData().getValue().toString().isEmpty()) {
XWPFParagraph paragraph = addParagraphContent(mapper.convertValue(field.getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId, 0); XWPFParagraph paragraph = addParagraphContent(mapper.convertValue(field.getData().getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId, 0);
if (paragraph != null) { if (paragraph != null) {
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); // CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
// number.setVal(BigInteger.valueOf(indent)); // number.setVal(BigInteger.valueOf(indent));
@ -634,15 +633,15 @@ public class WordBuilder {
} }
} }
} }
else if (field.getValue() != null && !field.getValue().toString().isEmpty()) { else if (field.getData().getValue() != null && !field.getData().getValue().toString().isEmpty()) {
this.indent = indent; this.indent = indent;
String format = this.formatter(field); String format = this.formatter(field);
if (((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.TAGS)) { if (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.TAGS)) {
format = getCommaSeparatedFormatsFromJson(format, "name"); format = getCommaSeparatedFormatsFromJson(format, "name");
} else if (((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.COMBO_BOX) && field.getData() instanceof AutoCompleteDataEntity) { } else if (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.AUTO_COMPLETE)) {
format = getCommaSeparatedFormatsFromJson(format, "label"); format = getCommaSeparatedFormatsFromJson(format, "label");
} }
switch (((BaseFieldDataEntity) field.getData()).getFieldType()) { switch (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType()) {
case ORGANIZATIONS: case ORGANIZATIONS:
case EXTERNAL_DATASETS: case EXTERNAL_DATASETS:
case PUBLICATIONS: case PUBLICATIONS:
@ -650,7 +649,7 @@ public class WordBuilder {
Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete"); Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete");
boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete; boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete;
if(!isMultiAutoComplete){ if(!isMultiAutoComplete){
Map<String, String> value = mapper.readValue((String)field.getValue(), Map.class); Map<String, String> value = mapper.readValue((String)field.getData().getValue(), Map.class);
if(hasMultiplicityItems){ if(hasMultiplicityItems){
createHypeLink(mainDocumentPart, format, value.get("pidTypeField"), value.get("pid"), true, false); createHypeLink(mainDocumentPart, format, value.get("pidTypeField"), value.get("pid"), true, false);
hasMultiplicityItems = false; hasMultiplicityItems = false;
@ -663,11 +662,11 @@ public class WordBuilder {
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
List<Map<String, Object>> values = new ArrayList<>(); List<Map<String, Object>> values = new ArrayList<>();
try { try {
values = Arrays.asList(mapper.readValue(field.getValue().toString(), HashMap[].class)); values = Arrays.asList(mapper.readValue(field.getData().getValue().toString(), HashMap[].class));
} }
catch (Exception e) { catch (Exception e) {
Map <String, Object> map = new HashMap<>(); Map <String, Object> map = new HashMap<>();
map.put("label", field.getValue()); map.put("label", field.getData().getValue());
values.add(map); values.add(map);
} }
if (values.size() > 1) { if (values.size() > 1) {
@ -695,7 +694,7 @@ public class WordBuilder {
} }
break; break;
default: default:
boolean isResearcher = ((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.RESEARCHERS); boolean isResearcher = ((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.RESEARCHERS);
if(format != null && !format.isEmpty()){ if(format != null && !format.isEmpty()){
Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete"); Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete");
boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete; boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete;
@ -725,7 +724,7 @@ public class WordBuilder {
hasMultiplicityItems = false; hasMultiplicityItems = false;
} }
else{ else{
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, ((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent); XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, ((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
if(orcidResearcher){ if(orcidResearcher){
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId); XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
run.setText(orcId); run.setText(orcId);
@ -754,7 +753,7 @@ public class WordBuilder {
hasValue = true; hasValue = true;
} }
else { else {
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, ((BaseFieldDataEntity) field.getData()).getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent); XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, ((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
if (paragraph != null) { if (paragraph != null) {
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); // CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
// number.setVal(BigInteger.valueOf(indent)); // number.setVal(BigInteger.valueOf(indent));
@ -865,12 +864,11 @@ public class WordBuilder {
} }
} }
private String formatter(Field field) throws IOException { private String formatter(FieldFileTransformerModel field) throws IOException {
FieldDataComboBoxType comboboxType = null; if (field.getData().getValue() == null) {
if (field.getValue() == null) {
return null; return null;
} }
switch (((BaseFieldDataEntity) field.getData()).getFieldType()) { switch (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType()) {
case RESEARCHERS: case RESEARCHERS:
// case "projects": //TODO: Description Templatedefinition // case "projects": //TODO: Description Templatedefinition
case ORGANIZATIONS: case ORGANIZATIONS:
@ -885,91 +883,86 @@ public class WordBuilder {
case SERVICES: case SERVICES:
case TAGS: case TAGS:
case CURRENCY: case CURRENCY:
comboboxType = FieldDataComboBoxType.Autocomplete; case AUTO_COMPLETE: {
case COMBO_BOX: { mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
if (comboboxType == null) { if (field.getData().getValue() == null) return null;
comboboxType = ((ComboBoxDataEntity) field.getData()).getFieldSubType(); List<Map<String, Object>> mapList = new ArrayList<>();
if (!field.getData().getValue().equals("") && field.getData().getValue().toString() != null) {
try {
mapList = Arrays.asList(mapper.readValue(field.getData().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.getData().getValue().toString());
mapList.add(map);
}
} }
if (comboboxType.equals(FieldDataComboBoxType.Autocomplete)) { StringBuilder sb = new StringBuilder();
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); int index = 0;
if (field.getValue() == null) return null; for (Map<String, Object> map : mapList) {
List<Map<String, Object>> mapList = new ArrayList<>(); for (Map.Entry<String, Object> entry : map.entrySet()) {
if (!field.getValue().equals("") && field.getValue().toString() != null) { if (entry.getValue() != null && (entry.getKey().equals("label") || entry.getKey().equals("description") || entry.getKey().equals("name"))) {
try { sb.append(entry.getValue());
mapList = Arrays.asList(mapper.readValue(field.getValue().toString(), HashMap[].class)); break;
}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(); if (index != mapList.size() - 1) sb.append(", ");
int index = 0; index++;
for (Map<String, Object> map: mapList) { }
for (Map.Entry<String, Object> entry : map.entrySet()) { return sb.toString();
if (entry.getValue() != null && (entry.getKey().equals("label") || entry.getKey().equals("description") || entry.getKey().equals("name"))) { }
sb.append(entry.getValue()); case WORD_LIST: {
break; WordListDataFileTransformerModel wordListDataEntity = (WordListDataFileTransformerModel) field.getData();
if (field.getData().getValue() != null) {
ComboBoxOptionFileTransformerModel selectedOption = null;
if (!wordListDataEntity.getOptions().isEmpty()) {
for (ComboBoxOptionFileTransformerModel option : wordListDataEntity.getOptions()) {
if (option.getValue().equals(field.getData().getValue())) {
selectedOption = option;
} }
} }
if (index != mapList.size() - 1) sb.append(", ");
index++;
} }
return sb.toString(); return selectedOption != null ? selectedOption.getLabel() : field.getData().getValue().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 "";
} }
return "";
} }
case BOOLEAN_DECISION: case BOOLEAN_DECISION:
if (field.getValue() != null && field.getValue().equals("true")) return "Yes"; if (field.getData().getValue() != null && field.getData().getValue().equals("true")) return "Yes";
if (field.getValue() != null && field.getValue().equals("false")) return "No"; if (field.getData().getValue() != null && field.getData().getValue().equals("false")) return "No";
return null; return null;
case RADIO_BOX: case RADIO_BOX:
return field.getValue() != null ? field.getValue().toString() : null; return field.getData().getValue() != null ? field.getData().getValue().toString() : null;
case CHECK_BOX: case CHECK_BOX:
CheckBoxDataEntity data = (CheckBoxDataEntity) field.getData(); LabelFieldDataFileTransformerModel data = (LabelFieldDataFileTransformerModel) field.getData();
if (field.getValue() == null || field.getValue().equals("false")) return null; if (field.getData().getValue() == null || field.getData().getValue().equals("false")) return null;
return data.getLabel(); return data.getLabel();
case DATE_PICKER:{ case DATE_PICKER:{
Instant instant; Instant instant;
if (!((String)field.getValue()).isEmpty()) { if (!((String)field.getData().getValue()).isEmpty()) {
try { try {
instant = Instant.parse((String) field.getValue()); instant = Instant.parse((String) field.getData().getValue());
} catch (DateTimeParseException ex) { } catch (DateTimeParseException ex) {
instant = LocalDate.parse((String) field.getValue()).atStartOfDay().toInstant(ZoneOffset.UTC); instant = LocalDate.parse((String) field.getData().getValue()).atStartOfDay().toInstant(ZoneOffset.UTC);
} }
return field.getValue() != null ? DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(instant) : ""; return field.getData().getValue() != null ? DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(instant) : "";
} }
return (String) field.getValue(); return (String) field.getData().getValue();
} }
case FREE_TEXT: case FREE_TEXT:
case TEXT_AREA: case TEXT_AREA:
case RICH_TEXT_AREA: case RICH_TEXT_AREA:
return field.getValue() != null ? field.getValue().toString(): ""; return field.getData().getValue() != null ? field.getData().getValue().toString(): "";
case DATASET_IDENTIFIER: case DATASET_IDENTIFIER:
case VALIDATION: case VALIDATION:
if (field.getValue() != null && !field.getValue().toString().isEmpty()) { if (field.getData().getValue() != null && !field.getData().getValue().toString().isEmpty()) {
Map<String, String> identifierData; Map<String, String> identifierData;
try { try {
identifierData = mapper.readValue(field.getValue().toString(), HashMap.class); identifierData = mapper.readValue(field.getData().getValue().toString(), HashMap.class);
} catch (Exception ex) { } catch (Exception ex) {
// logger.warn(ex.getLocalizedMessage(), ex); // logger.warn(ex.getLocalizedMessage(), ex);
// logger.info("Reverting to custom parsing"); // logger.info("Reverting to custom parsing");
identifierData = customParse(field.getValue().toString()); identifierData = customParse(field.getData().getValue().toString());
} }
return "id: " + identifierData.get("identifier") + ", Type: " + identifierData.get("type"); return "id: " + identifierData.get("identifier") + ", Type: " + identifierData.get("type");
} }
@ -978,10 +971,6 @@ public class WordBuilder {
return null; return null;
} }
private boolean hasVisibleFields(FieldSet compositeFields, VisibilityRuleService visibilityRuleService) {
return compositeFields.getFields().stream().anyMatch(field -> visibilityRuleService.isElementVisible(field.getId()) && field.getExport());
}
private Map<String, String> customParse(String value) { private Map<String, String> customParse(String value) {
Map<String, String> result = new LinkedHashMap<>(); Map<String, String> result = new LinkedHashMap<>();
String parsedValue = value.replaceAll("[^a-zA-Z0-9\\s:=,]", ""); String parsedValue = value.replaceAll("[^a-zA-Z0-9\\s:=,]", "");
@ -1016,15 +1005,15 @@ public class WordBuilder {
int parPos = 0; int parPos = 0;
int descrParPos = -1; int descrParPos = -1;
XWPFParagraph descrPar = null; XWPFParagraph descrPar = null;
List<Reference> grants = new ArrayList<>(); List<ReferenceFileTransformerModel> grants = new ArrayList<>();
List<Reference> researchers = new ArrayList<>(); List<ReferenceFileTransformerModel> researchers = new ArrayList<>();
List<Reference> organizations = new ArrayList<>(); List<ReferenceFileTransformerModel> organizations = new ArrayList<>();
List<Reference> funders = new ArrayList<>(); List<ReferenceFileTransformerModel> funders = new ArrayList<>();
if (dmpEntity.getDmpReferences() != null) { if (dmpEntity.getDmpReferences() != null) {
grants = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Grants) && referenceFileModel.getIsActive().equals(IsActive.Active)).toList(); grants = dmpEntity.getDmpReferences().stream().map(DmpReferenceFileTransformerModel::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Grants)).toList();
researchers = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(reference -> reference.getType().equals(ReferenceType.Researcher)).toList(); researchers = dmpEntity.getDmpReferences().stream().map(DmpReferenceFileTransformerModel::getReference).filter(reference -> reference.getType().equals(ReferenceType.Researcher)).toList();
organizations = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Organizations)).toList(); organizations = dmpEntity.getDmpReferences().stream().map(DmpReferenceFileTransformerModel::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Organizations)).toList();
funders = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Funder) && referenceFileModel.getIsActive().equals(IsActive.Active)).toList(); funders = dmpEntity.getDmpReferences().stream().map(DmpReferenceFileTransformerModel::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Funder)).toList();
} }
for(XWPFParagraph p: document.getParagraphs()){ for(XWPFParagraph p: document.getParagraphs()){
List<XWPFRun> runs = p.getRuns(); List<XWPFRun> runs = p.getRuns();
@ -1055,7 +1044,7 @@ public class WordBuilder {
} else if(text.equals("{ARGOS.DMP.RESEARCHERS}")) { } else if(text.equals("{ARGOS.DMP.RESEARCHERS}")) {
String researchersNames = ""; String researchersNames = "";
int i = 0; int i = 0;
for(Reference researcher : researchers){ for(ReferenceFileTransformerModel researcher : researchers){
i++; i++;
researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : ""); researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : "");
} }
@ -1065,7 +1054,7 @@ public class WordBuilder {
} else if(text.equals("{ARGOS.DMP.ORGANIZATIONS}")) { } else if(text.equals("{ARGOS.DMP.ORGANIZATIONS}")) {
String organisationsNames = ""; String organisationsNames = "";
int i = 0; int i = 0;
for(Reference organisation : organizations){ for(ReferenceFileTransformerModel organisation : organizations){
i++; i++;
organisationsNames += organisation.getLabel() + (i < organizations.size() ? ", " : ""); organisationsNames += organisation.getLabel() + (i < organizations.size() ? ", " : "");
} }

View File

@ -1,11 +1,10 @@
package eu.eudat.file.transformer.controller; package eu.eudat.file.transformer.controller;
import eu.eudat.file.transformer.executor.FileTransformerExecutor; import eu.eudat.file.transformer.executor.FileTransformerExecutor;
import eu.eudat.file.transformer.model.DescriptionFileTransformerModel; import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel;
import eu.eudat.file.transformer.model.DmpFileTransformerModel; import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
import eu.eudat.file.transformer.model.ExtraPropertiesModel; import eu.eudat.file.transformer.models.misc.FileEnvelope;
import eu.eudat.file.transformer.model.file.FileEnvelope; import eu.eudat.file.transformer.model.file.FileVariant;
import eu.eudat.file.transformer.model.file.FileFormat;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -47,7 +46,7 @@ public class FileTransformerController {
} }
@GetMapping("/formats") @GetMapping("/formats")
public List<FileFormat> getSupportedFormats() { public List<FileVariant> getSupportedFormats() {
return fileTransformerExecutor.getSupportedFileFormats(); return fileTransformerExecutor.getSupportedFileFormats();
} }
} }