description validation small fixes
This commit is contained in:
parent
6eca4c4628
commit
5a618168dd
|
@ -97,6 +97,7 @@ public class FieldPersist {
|
|||
private FieldEntity fieldEntity;
|
||||
private DescriptionStatus status;
|
||||
private List<List<RuleEntity>> rules;
|
||||
private Boolean fieldSetIsRuleTarget;
|
||||
|
||||
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
|
||||
super(conventionService, errors);
|
||||
|
@ -116,31 +117,31 @@ public class FieldPersist {
|
|||
boolean isRuleTarget = this.checkIfFieldIsRuleTarget();
|
||||
return Arrays.asList(
|
||||
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()))
|
||||
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
||||
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()))
|
||||
.failOn(FieldPersist._dateValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dateValue}, LocaleContextHolder.getLocale())),
|
||||
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()))
|
||||
.failOn(FieldPersist._externalIdentifier).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._externalIdentifier}, LocaleContextHolder.getLocale())),
|
||||
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()))
|
||||
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
|
||||
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()))
|
||||
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
|
||||
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()))
|
||||
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
|
||||
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()))
|
||||
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
|
@ -180,6 +181,10 @@ public class FieldPersist {
|
|||
return this;
|
||||
}
|
||||
|
||||
public PersistValidator ifFieldSetIsRuleTarget(Boolean fieldSetIsRuleTarget){
|
||||
this.fieldSetIsRuleTarget = fieldSetIsRuleTarget;
|
||||
return this;
|
||||
}
|
||||
private boolean checkIfFieldIsRuleTarget(){
|
||||
if (this.isListNullOrEmpty(rules)) return false;
|
||||
for (List<RuleEntity> rulesBySection: rules) {
|
||||
|
|
|
@ -88,7 +88,7 @@ public class PropertyDefinitionFieldSetItemPersist {
|
|||
.using((itm) ->
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue