description validation small fixes

This commit is contained in:
amentis 2024-04-24 14:28:12 +03:00
parent 6eca4c4628
commit 5a618168dd
2 changed files with 25 additions and 8 deletions

View File

@ -97,6 +97,7 @@ public class FieldPersist {
private FieldEntity fieldEntity; private FieldEntity fieldEntity;
private DescriptionStatus status; private DescriptionStatus status;
private List<List<RuleEntity>> rules; private List<List<RuleEntity>> rules;
private Boolean fieldSetIsRuleTarget;
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) { protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
super(conventionService, errors); super(conventionService, errors);
@ -116,31 +117,31 @@ public class FieldPersist {
boolean isRuleTarget = this.checkIfFieldIsRuleTarget(); boolean isRuleTarget = this.checkIfFieldIsRuleTarget();
return Arrays.asList( return Arrays.asList(
this.spec() this.spec()
.iff(()-> FieldType.isTextType(fieldType) && !fieldType.equals(FieldType.CHECK_BOX) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && required) .iff(()-> FieldType.isTextType(fieldType) && !fieldType.equals(FieldType.CHECK_BOX) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required)
.must(() -> !this.isEmpty(item.getTextValue())) .must(() -> !this.isEmpty(item.getTextValue()))
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), .failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(()-> FieldType.isDateType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && required) .iff(()-> FieldType.isDateType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required)
.must(() -> !this.isNull(item.getDateValue())) .must(() -> !this.isNull(item.getDateValue()))
.failOn(FieldPersist._dateValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dateValue}, LocaleContextHolder.getLocale())), .failOn(FieldPersist._dateValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dateValue}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(()-> FieldType.isExternalIdentifierType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && required) .iff(()-> FieldType.isExternalIdentifierType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required)
.must(() -> !this.isNull(item.getExternalIdentifier())) .must(() -> !this.isNull(item.getExternalIdentifier()))
.failOn(FieldPersist._externalIdentifier).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._externalIdentifier}, LocaleContextHolder.getLocale())), .failOn(FieldPersist._externalIdentifier).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._externalIdentifier}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(()-> FieldType.isTextListType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && required && !fieldType.equals(FieldType.TAGS)) .iff(()-> FieldType.isTextListType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required && !fieldType.equals(FieldType.TAGS))
.must(() -> !this.isListNullOrEmpty(item.getTextListValue()) || !this.isEmpty(item.getTextValue())) .must(() -> !this.isListNullOrEmpty(item.getTextListValue()) || !this.isEmpty(item.getTextValue()))
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(()-> fieldType.equals(FieldType.TAGS) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && required) .iff(()-> fieldType.equals(FieldType.TAGS) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required)
.must(() -> !this.isListNullOrEmpty(item.getTextListValue())) .must(() -> !this.isListNullOrEmpty(item.getTextListValue()))
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(()-> FieldType.isReferenceType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && required) .iff(()-> FieldType.isReferenceType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required)
.must(() -> !this.isListNullOrEmpty(item.getReferences()) || !this.isNull(item.getReference())) .must(() -> !this.isListNullOrEmpty(item.getReferences()) || !this.isNull(item.getReference()))
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(()-> !this.isEmpty(item.getTextValue()) && (fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.BOOLEAN_DECISION)) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget) .iff(()-> !this.isEmpty(item.getTextValue()) && (fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.BOOLEAN_DECISION)) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget)
.must(() -> this.isBoolean(item.getTextValue())) .must(() -> this.isBoolean(item.getTextValue()))
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), .failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
@ -180,6 +181,10 @@ public class FieldPersist {
return this; return this;
} }
public PersistValidator ifFieldSetIsRuleTarget(Boolean fieldSetIsRuleTarget){
this.fieldSetIsRuleTarget = fieldSetIsRuleTarget;
return this;
}
private boolean checkIfFieldIsRuleTarget(){ private boolean checkIfFieldIsRuleTarget(){
if (this.isListNullOrEmpty(rules)) return false; if (this.isListNullOrEmpty(rules)) return false;
for (List<RuleEntity> rulesBySection: rules) { for (List<RuleEntity> rulesBySection: rules) {

View File

@ -88,7 +88,7 @@ public class PropertyDefinitionFieldSetItemPersist {
.using((itm) -> .using((itm) ->
{ {
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById((String)itm.getKey()).stream().findFirst().orElse(null) : null; FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById((String)itm.getKey()).stream().findFirst().orElse(null) : null;
return this.validatorFactory.validator(FieldPersist.PersistValidator.class).withFieldEntity(fieldEntity).withRules(rules).setStatus(this.status); return this.validatorFactory.validator(FieldPersist.PersistValidator.class).withFieldEntity(fieldEntity).withRules(rules).ifFieldSetIsRuleTarget(this.checkIfFieldSetIsRuleTarget()).setStatus(this.status);
}) })
); );
@ -108,6 +108,18 @@ public class PropertyDefinitionFieldSetItemPersist {
this.status = status; this.status = status;
return this; return this;
} }
private Boolean checkIfFieldSetIsRuleTarget(){
if (this.isListNullOrEmpty(rules)) return false;
for (List<RuleEntity> rulesBySection: rules) {
if (!this.isListNullOrEmpty(rulesBySection)){
for (RuleEntity rule :rulesBySection) {
if (rule.getTarget().equals(this.fieldSetEntity.getId())) return true;
}
}
}
return false;
}
} }
} }