Add more missing field on File Transformer Builder

This commit is contained in:
George Kalampokis 2024-01-11 18:02:38 +02:00
parent 742fa49a7c
commit 3d5be3a00a
3 changed files with 122 additions and 8 deletions

View File

@ -10,10 +10,7 @@ import eu.eudat.convention.ConventionService;
import eu.eudat.depositinterface.enums.FieldType;
import eu.eudat.depositinterface.models.DescriptionFieldDepositModel;
import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
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.*;
import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
@ -23,10 +20,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ -35,6 +29,7 @@ public class DescriptionFieldFileTransformerBuilder extends BaseFileTransformerB
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private DescriptionTemplateFileTransformerModel definition;
private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider;
@Autowired
public DescriptionFieldFileTransformerBuilder(
ConventionService conventionService, FieldDataHelperServiceProvider fieldDataHelperServiceProvider
@ -110,6 +105,10 @@ public class DescriptionFieldFileTransformerBuilder extends BaseFileTransformerB
//models.add(new FileTransformerBuilderItemResponse<>(m, d));
}
for (PageFileTransformerModel page : definition.getDefinition().getPages()) {
page.setSections(calculateSectionVisibility(page.getSections()));
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return List.of(new FileTransformerBuilderItemResponse<>(definition, data.get(0)));
@ -158,4 +157,112 @@ public class DescriptionFieldFileTransformerBuilder extends BaseFileTransformerB
return result;
}
private List<SectionFileTransformerModel> calculateSectionVisibility(List<SectionFileTransformerModel> sections) {
List<SectionFileTransformerModel> result = new ArrayList<>();
for (SectionFileTransformerModel section : sections) {
if (section.getSections() != null && !section.getSections().isEmpty()) {
section.setSections(calculateSectionVisibility(section.getSections()));
}
if (section.getFieldSets() != null && !section.getFieldSets().isEmpty()) {
section.setFieldSets(calculateFieldSetVisibility(section.getFieldSets()));
}
if ((section.getSections() != null && !section.getSections().isEmpty()) || (section.getFieldSets() != null && !section.getFieldSets().isEmpty())) {
result.add(section);
}
}
return result;
}
private List<FieldSetFileTransformerModel> calculateFieldSetVisibility(List<FieldSetFileTransformerModel> fieldSets) {
List<FieldSetFileTransformerModel> result = new ArrayList<>();
for (FieldSetFileTransformerModel fieldSet : fieldSets) {
if (fieldSet.getFields() != null && !fieldSet.getFields().isEmpty()) {
fieldSet.setFields(calculateFieldVisibility(fieldSet.getFields()));
if (fieldSet.getFields() != null && !fieldSet.getFields().isEmpty()) {
result.add(fieldSet);
}
}
}
return result;
}
private List<FieldFileTransformerModel> calculateFieldVisibility(List<FieldFileTransformerModel> fields) {
List<FieldFileTransformerModel> result = new ArrayList<>();
for (FieldFileTransformerModel field : fields) {
if (field.getVisibilityRules() != null && !field.getVisibilityRules().isEmpty()) {
Integer maxChecks = field.getVisibilityRules().size();
Integer successfulChecks = 0;
for (RuleFileTransformerModel rule : field.getVisibilityRules()) {
FieldFileTransformerModel targetField = findFieldByPages(definition.getDefinition().getPages(), rule.getTarget());
if (targetField.getData() != null ) {
successfulChecks = targetField.getData().getValue().equals(rule.getValue()) ? successfulChecks + 1 : successfulChecks;
}
}
if (successfulChecks.equals(maxChecks)) {
result.add(field);
}
} else {
result.add(field);
}
}
return result;
}
private FieldFileTransformerModel findFieldByPages(List<PageFileTransformerModel> pages, String fieldId) {
FieldFileTransformerModel result = null;
for (PageFileTransformerModel page : pages) {
result = findFieldBySections(page.getSections(), fieldId);
if (result != null) {
break;
}
}
return result;
}
private FieldFileTransformerModel findFieldBySections(List<SectionFileTransformerModel> sections, String fieldId) {
FieldFileTransformerModel result = null;
for (SectionFileTransformerModel section : sections) {
if (section.getSections() != null && !section.getSections().isEmpty()) {
result = findFieldBySections(section.getSections(), fieldId);
if (result != null) {
break;
}
}
if (section.getFieldSets() != null && !section.getFieldSets().isEmpty()) {
result = findFieldByFieldSets(section.getFieldSets(), fieldId);
if (result != null) {
break;
}
}
}
return result;
}
private FieldFileTransformerModel findFieldByFieldSets(List<FieldSetFileTransformerModel> fieldSets, String fieldId) {
FieldFileTransformerModel result = null;
for (FieldSetFileTransformerModel fieldSet: fieldSets) {
result = findField(fieldSet.getFields(), fieldId);
if (result != null) {
break;
}
}
return result;
}
private FieldFileTransformerModel findField(List<FieldFileTransformerModel> fields, String fieldId) {
FieldFileTransformerModel result = null;
for (FieldFileTransformerModel field: fields) {
if (field.getId().equals(fieldId)) {
result = field;
break;
}
}
return result;
}
}

View File

@ -92,6 +92,7 @@ public class DmpBlueprintFileTransformerBuilder extends BaseFileTransformerBuild
SectionFileTransformerModel m = new SectionFileTransformerModel();
m.setId(section.getId());
m.setLabel(section.getLabel());
m.setOrdinal(section.getOrdinal());
m.setDescription(section.getDescription());
m.setFields(mapFields(section.getFields()));
m.setHasTemplates(section.getHasTemplates());

View File

@ -12,6 +12,7 @@ import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
import eu.eudat.file.transformer.models.dmp.DmpReferenceFileTransformerModel;
import eu.eudat.file.transformer.models.dmp.DmpUserFileTransformerModel;
import eu.eudat.file.transformer.models.dmpblueprint.DmpBlueprintFileTransformerModel;
import eu.eudat.file.transformer.models.dmpblueprint.definition.SectionFileTransformerModel;
import eu.eudat.file.transformer.models.entitydoi.EntityDoiFileTransformerModel;
import eu.eudat.file.transformer.models.user.UserFileTransformerModel;
import eu.eudat.model.*;
@ -111,6 +112,11 @@ public class DmpFileTransformerBuilder extends BaseFileTransformerBuilder<DmpFil
if (creatorMap != null && !creatorMap.isEmpty() && creatorMap.containsKey(d.getId())) m.setCreator(creatorMap.get(d.getId()));
if (blueprintMap != null && !blueprintMap.isEmpty() && blueprintMap.containsKey(d.getBlueprintId())) m.setBlueprint(blueprintMap.get(d.getBlueprintId()));
SectionFileTransformerModel templateSection = m.getBlueprint().getDefinitionFileTransformerModel().getSections().stream().filter(SectionFileTransformerModel::getHasTemplates).findFirst().orElse(null);
if (templateSection != null && m.getDescriptions() != null && !m.getDescriptions().isEmpty()) {
m.getDescriptions().forEach(description -> description.setSectionId(templateSection.getId()));
}
models.add(new FileTransformerBuilderItemResponse<>(m, d));
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));