Update compatibility to the latest file transformer base

This commit is contained in:
George Kalampokis 2024-02-02 17:45:11 +02:00
parent 865c1d7e3f
commit 7716345a73
3 changed files with 132 additions and 129 deletions

View File

@ -18,7 +18,7 @@
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.release>21</maven.compiler.release>
<revision>1.0.0-SNAPSHOT</revision>
<transformer-base.version>0.0.3</transformer-base.version>
<transformer-base.version>1.0.0-SNAPSHOT</transformer-base.version>
</properties>
<dependencies>

View File

@ -222,128 +222,128 @@ public class WordFileTransformer implements FileTransformerClient {
runSectionDescriptionText.setColor("116a78");
wordBuilder.addParagraphContent("Section Fields", document, ParagraphStyle.HEADER2, BigInteger.ZERO, 0);
sectionFileTransformerModel.getFields().sort(Comparator.comparingInt(FieldFileTransformerModel::getOrdinal));
for(FieldFileTransformerModel fieldFileTransformerModel : sectionFileTransformerModel.getFields()){
if(fieldFileTransformerModel.getCategory() == DmpBlueprintFieldCategory.System){
SystemFieldFileTransformerModel systemField = (SystemFieldFileTransformerModel) fieldFileTransformerModel;
XWPFParagraph systemFieldParagraph = document.createParagraph();
systemFieldParagraph.setSpacingBetween(1.0);
XWPFRun runSyStemFieldTitle = systemFieldParagraph.createRun();
runSyStemFieldTitle.setText("Title: ");
runSyStemFieldTitle.setColor("000000");
XWPFRun runSystemFieldTitleText = systemFieldParagraph.createRun();
runSystemFieldTitleText.setText(systemField.getLabel());
runSystemFieldTitleText.setColor("116a78");
if(systemField.getDescription() != null && !systemField.getDescription().isEmpty()){
XWPFParagraph systemFieldDescription = document.createParagraph();
systemFieldDescription.setSpacingBetween(1.0);
XWPFRun runSyStemFieldDescription = systemFieldDescription.createRun();
runSyStemFieldDescription.setText("Description: ");
runSyStemFieldDescription.setColor("000000");
XWPFRun runSystemFieldDescriptionText = systemFieldDescription.createRun();
runSystemFieldDescriptionText.setText(systemField.getDescription());
runSystemFieldDescriptionText.setColor("116a78");
}
XWPFParagraph systemFieldInput = document.createParagraph();
systemFieldInput.setSpacingBetween(1.0);
XWPFRun runInput = systemFieldInput.createRun();
runInput.setText("Input: ");
runInput.setColor("000000");
Map<String, Object> dmpProperties = objectMapper.readValue(dmpEntity.getProperties(), HashMap.class);
switch (systemField.getSystemFieldType()) {
case Text:
XWPFRun runTitle = systemFieldInput.createRun();
runTitle.setText(dmpEntity.getLabel());
runTitle.setColor("116a78");
break;
case HtmlText:
XWPFRun runDescription = systemFieldInput.createRun();
runDescription.setText(dmpEntity.getDescription());
runDescription.setColor("116a78");
break;
case Researchers:
for(ReferenceFileTransformerModel researcher: researchers){
XWPFRun runResearcher = systemFieldInput.createRun();
runResearcher.setText("" + researcher.getLabel());
runResearcher.setColor("116a78");
}
break;
case Organizations:
for(ReferenceFileTransformerModel organisation: organizations){
XWPFRun runOrganisation = systemFieldInput.createRun();
runOrganisation.setText("" + organisation.getLabel());
runOrganisation.setColor("116a78");
}
break;
if (sectionFileTransformerModel.getFields() != null) {
sectionFileTransformerModel.getFields().sort(Comparator.comparingInt(FieldFileTransformerModel::getOrdinal));
for (FieldFileTransformerModel fieldFileTransformerModel : sectionFileTransformerModel.getFields()) {
if (fieldFileTransformerModel.getCategory() == DmpBlueprintFieldCategory.System) {
SystemFieldFileTransformerModel systemField = (SystemFieldFileTransformerModel) fieldFileTransformerModel;
XWPFParagraph systemFieldParagraph = document.createParagraph();
systemFieldParagraph.setSpacingBetween(1.0);
XWPFRun runSyStemFieldTitle = systemFieldParagraph.createRun();
runSyStemFieldTitle.setText("Title: ");
runSyStemFieldTitle.setColor("000000");
XWPFRun runSystemFieldTitleText = systemFieldParagraph.createRun();
runSystemFieldTitleText.setText(systemField.getLabel());
runSystemFieldTitleText.setColor("116a78");
if (systemField.getDescription() != null && !systemField.getDescription().isEmpty()) {
XWPFParagraph systemFieldDescription = document.createParagraph();
systemFieldDescription.setSpacingBetween(1.0);
XWPFRun runSyStemFieldDescription = systemFieldDescription.createRun();
runSyStemFieldDescription.setText("Description: ");
runSyStemFieldDescription.setColor("000000");
XWPFRun runSystemFieldDescriptionText = systemFieldDescription.createRun();
runSystemFieldDescriptionText.setText(systemField.getDescription());
runSystemFieldDescriptionText.setColor("116a78");
}
XWPFParagraph systemFieldInput = document.createParagraph();
systemFieldInput.setSpacingBetween(1.0);
XWPFRun runInput = systemFieldInput.createRun();
runInput.setText("Input: ");
runInput.setColor("000000");
Map<String, Object> dmpProperties = objectMapper.readValue(dmpEntity.getProperties(), HashMap.class);
switch (systemField.getSystemFieldType()) {
case Text:
XWPFRun runTitle = systemFieldInput.createRun();
runTitle.setText(dmpEntity.getLabel());
runTitle.setColor("116a78");
break;
case HtmlText:
XWPFRun runDescription = systemFieldInput.createRun();
runDescription.setText(dmpEntity.getDescription());
runDescription.setColor("116a78");
break;
case Researchers:
for (ReferenceFileTransformerModel researcher : researchers) {
XWPFRun runResearcher = systemFieldInput.createRun();
runResearcher.setText("" + researcher.getLabel());
runResearcher.setColor("116a78");
}
break;
case Organizations:
for (ReferenceFileTransformerModel organisation : organizations) {
XWPFRun runOrganisation = systemFieldInput.createRun();
runOrganisation.setText("" + organisation.getLabel());
runOrganisation.setColor("116a78");
}
break;
/* case Language:
XWPFRun runLanguage = systemFieldInput.createRun();
runLanguage.setText(dmpProperties.get("language").toString());
runLanguage.setColor("116a78");
break;*/
case Contact:
XWPFRun runContact = systemFieldInput.createRun();
runContact.setText(dmpEntity.getCreator().getName());
runContact.setColor("116a78");
break;
case Funder:
if (!funders.isEmpty()) {
XWPFRun runFunder = systemFieldInput.createRun();
runFunder.setText(funders.get(0).getLabel());
runFunder.setColor("116a78");
}
break;
case Grant:
if (!grants.isEmpty()) {
XWPFRun runGrant = systemFieldInput.createRun();
runGrant.setText(grants.get(0).getLabel());
runGrant.setColor("116a78");
}
break;
case Project:
if (!projects.isEmpty()) {
XWPFRun runProject = systemFieldInput.createRun();
runProject.setText(projects.get(0).getLabel());
runProject.setColor("116a78");
}
break;
case License:
if (dmpProperties.containsKey("license")) {
XWPFRun runLicense = systemFieldInput.createRun();
runLicense.setText(dmpProperties.get("license").toString());
runLicense.setColor("116a78");
}
break;
case AccessRights:
if (dmpProperties.containsKey("visible")) {
XWPFRun runAccessRights = systemFieldInput.createRun();
runAccessRights.setText(dmpProperties.get("visible").toString());
runAccessRights.setColor("116a78");
}
break;
case Contact:
XWPFRun runContact = systemFieldInput.createRun();
runContact.setText(dmpEntity.getCreator().getName());
runContact.setColor("116a78");
break;
case Funder:
if (!funders.isEmpty()) {
XWPFRun runFunder = systemFieldInput.createRun();
runFunder.setText(funders.get(0).getLabel());
runFunder.setColor("116a78");
}
break;
case Grant:
if (!grants.isEmpty()) {
XWPFRun runGrant = systemFieldInput.createRun();
runGrant.setText(grants.get(0).getLabel());
runGrant.setColor("116a78");
}
break;
case Project:
if (!projects.isEmpty()) {
XWPFRun runProject = systemFieldInput.createRun();
runProject.setText(projects.get(0).getLabel());
runProject.setColor("116a78");
}
break;
case License:
if (dmpProperties.containsKey("license")) {
XWPFRun runLicense = systemFieldInput.createRun();
runLicense.setText(dmpProperties.get("license").toString());
runLicense.setColor("116a78");
}
break;
case AccessRights:
if (dmpProperties.containsKey("visible")) {
XWPFRun runAccessRights = systemFieldInput.createRun();
runAccessRights.setText(dmpProperties.get("visible").toString());
runAccessRights.setColor("116a78");
}
break;
}
document.createParagraph();
} else if (fieldFileTransformerModel.getCategory() == DmpBlueprintFieldCategory.Extra) {
ExtraFieldFileTransformerModelFileTransformerModel extraFieldFileTransformerModel = (ExtraFieldFileTransformerModelFileTransformerModel) fieldFileTransformerModel;
XWPFParagraph extraFieldParagraph = document.createParagraph();
extraFieldParagraph.setSpacingBetween(1.0);
XWPFRun runExtraFieldLabel = extraFieldParagraph.createRun();
runExtraFieldLabel.setText(extraFieldFileTransformerModel.getLabel());
runExtraFieldLabel.setColor("116a78");
if (extraFieldFileTransformerModel.getDescription() != null && !extraFieldFileTransformerModel.getDescription().isEmpty()) {
XWPFRun runExtraFieldDescription = extraFieldParagraph.createRun();
runExtraFieldDescription.setText(extraFieldFileTransformerModel.getDescription());
runExtraFieldDescription.setColor("116a78");
}
XWPFRun runExtraFieldInput = extraFieldParagraph.createRun();
Map dmpProperties = objectMapper.readValue(dmpEntity.getProperties(), HashMap.class);
if (dmpProperties.containsKey(fieldFileTransformerModel.getId()) && dmpProperties.get(fieldFileTransformerModel.getId()) != null) {
runExtraFieldInput.setText((String) dmpProperties.get(fieldFileTransformerModel.getId()));
}
runExtraFieldInput.setColor("116a78");
}
document.createParagraph();
}
else if(fieldFileTransformerModel.getCategory() == DmpBlueprintFieldCategory.Extra){
ExtraFieldFileTransformerModelFileTransformerModel extraFieldFileTransformerModel = (ExtraFieldFileTransformerModelFileTransformerModel) fieldFileTransformerModel;
XWPFParagraph extraFieldParagraph = document.createParagraph();
extraFieldParagraph.setSpacingBetween(1.0);
XWPFRun runExtraFieldLabel = extraFieldParagraph.createRun();
runExtraFieldLabel.setText(extraFieldFileTransformerModel.getLabel());
runExtraFieldLabel.setColor("116a78");
if(extraFieldFileTransformerModel.getDescription() != null && !extraFieldFileTransformerModel.getDescription().isEmpty()){
XWPFRun runExtraFieldDescription = extraFieldParagraph.createRun();
runExtraFieldDescription.setText(extraFieldFileTransformerModel.getDescription());
runExtraFieldDescription.setColor("116a78");
}
XWPFRun runExtraFieldInput = extraFieldParagraph.createRun();
Map dmpProperties = objectMapper.readValue(dmpEntity.getProperties(), HashMap.class);
if (dmpProperties.containsKey(fieldFileTransformerModel.getId()) && dmpProperties.get(fieldFileTransformerModel.getId()) != null) {
runExtraFieldInput.setText((String) dmpProperties.get(fieldFileTransformerModel.getId()));
}
runExtraFieldInput.setColor("116a78");
}
}
final Boolean isFinalized = dmpEntity.getStatus() == DmpStatus.Finalized;
final Boolean isPublic = dmpEntity.getPublicAfter() != null && dmpEntity.getPublicAfter().isAfter(Instant.now());
List<DescriptionFileTransformerModel> descriptions = dmpEntity.getDescriptions().stream()

View File

@ -290,7 +290,7 @@ public class WordBuilder {
}
private void createPages(List<PageFileTransformerModel> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing) {
datasetProfilePages.forEach(item -> {
datasetProfilePages.stream().filter(item -> item.getSections() != null).forEach(item -> {
try {
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, 0, createListing, item.getOrdinal() + 1, null);
} catch (Exception e) {
@ -302,6 +302,7 @@ public class WordBuilder {
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);
boolean hasValue = false;
for (SectionFileTransformerModel section: sections) {
int paragraphPos = -1;
String tempSectionString = sectionString != null ? sectionString + "." + (section.getOrdinal() + 1) : "" + (section.getOrdinal() + 1);
@ -311,7 +312,9 @@ public class WordBuilder {
// number.setVal(BigInteger.valueOf(indent));
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
}
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, indent + 1, createListing, page, tempSectionString);
if (section.getSections() != null) {
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER5, indent + 1, createListing, page, tempSectionString);
}
hasValue = createCompositeFields(section.getFieldSets(), mainDocumentPart, indent + 1, createListing, page, tempSectionString);
if (!hasValue && paragraphPos > -1) {
@ -436,7 +439,7 @@ public class WordBuilder {
cell = row.createCell();
}
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.valueOf("CENTER"));
String label = ((BaseFieldDataFileTransformerModel) field.getData()).getLabel();
String label = field.getData().getLabel();
if (label != null && label != "") {
XWPFParagraph paragraph = cell.getParagraphs().get(0);
paragraph.setIndentationFirstLine(50);
@ -466,9 +469,9 @@ public class WordBuilder {
if (field.getIncludeInExport()) {
if (!createListing) {
try {
if(((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.UPLOAD)){
if(field.getData().getFieldType().equals(FieldType.UPLOAD)){
boolean isImage = false;
for(UploadOptionFileTransformerModel type: ((UploadDataFileTransformerModel)field.getData()).getTypes()){
for(UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel type: ((UploadDataFileTransformerModel)field.getData()).getTypes()){
String fileFormat = type.getValue();
if(IMAGE_TYPE_MAP.containsKey(fileFormat)){
isImage = true;
@ -492,7 +495,7 @@ public class WordBuilder {
String format = this.formatter(field);
if (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.TAGS)) {
format = getCommaSeparatedFormatsFromJson(format, "name");
} else if (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.AUTO_COMPLETE)) {
} else if (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.EXTERNAL_SELECT)) {
format = getCommaSeparatedFormatsFromJson(format, "label");
}
boolean isResearcher = ((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.RESEARCHERS);
@ -613,7 +616,7 @@ public class WordBuilder {
if (field.getData() != null) {
if (field.getData().getFieldType().equals(FieldType.UPLOAD)) {
boolean isImage = false;
for (UploadOptionFileTransformerModel type : ((UploadDataFileTransformerModel) field.getData()).getTypes()) {
for (UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel type : ((UploadDataFileTransformerModel) field.getData()).getTypes()) {
String fileFormat = type.getValue();
if (IMAGE_TYPE_MAP.containsKey(fileFormat)) {
isImage = true;
@ -638,7 +641,7 @@ public class WordBuilder {
String format = this.formatter(field);
if (field.getData().getFieldType().equals(FieldType.TAGS)) {
format = getCommaSeparatedFormatsFromJson(format, "name");
} else if (field.getData().getFieldType().equals(FieldType.AUTO_COMPLETE)) {
} else if (field.getData().getFieldType().equals(FieldType.EXTERNAL_SELECT)) {
format = getCommaSeparatedFormatsFromJson(format, "label");
}
switch (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType()) {
@ -875,7 +878,7 @@ public class WordBuilder {
case SERVICES:
case TAGS:
case CURRENCY:
case AUTO_COMPLETE: {
case EXTERNAL_SELECT: {
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
if (field.getData().getValue() == null) return null;
List<Map<String, Object>> mapList = new ArrayList<>();
@ -904,12 +907,12 @@ public class WordBuilder {
}
return sb.toString();
}
case WORD_LIST: {
WordListDataFileTransformerModel wordListDataEntity = (WordListDataFileTransformerModel) field.getData();
case SELECT: {
SelectDataFileTransformerModel wordListDataEntity = (SelectDataFileTransformerModel) field.getData();
if (field.getData().getValue() != null) {
ComboBoxOptionFileTransformerModel selectedOption = null;
SelectDataFileTransformerModel.OptionFileTransformerModel selectedOption = null;
if (!wordListDataEntity.getOptions().isEmpty()) {
for (ComboBoxOptionFileTransformerModel option : wordListDataEntity.getOptions()) {
for (SelectDataFileTransformerModel.OptionFileTransformerModel option : wordListDataEntity.getOptions()) {
if (option.getValue().equals(field.getData().getValue())) {
selectedOption = option;
}
@ -926,7 +929,7 @@ public class WordBuilder {
case RADIO_BOX:
return field.getData().getValue() != null ? field.getData().getValue().toString() : null;
case CHECK_BOX:
LabelFieldDataFileTransformerModel data = (LabelFieldDataFileTransformerModel) field.getData();
LabelDataFileTransformerModel data = (LabelDataFileTransformerModel) field.getData();
if (field.getData().getValue() == null || field.getData().getValue().equals("false")) return null;
return data.getLabel();
case DATE_PICKER:{