Resolving some validations applying based on status 'Finalized'

This commit is contained in:
Thomas Georgios Giannos 2024-01-05 17:10:13 +02:00
parent 34df0b640c
commit e8553b1605
6 changed files with 11 additions and 13 deletions

View File

@ -220,7 +220,7 @@ public class DescriptionPersist {
.must(() -> !this.isNull(item.getReferences())) .must(() -> !this.isNull(item.getReferences()))
.failOn(DescriptionPersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._references}, LocaleContextHolder.getLocale())), .failOn(DescriptionPersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._references}, LocaleContextHolder.getLocale())),
this.navSpec() this.navSpec()
.iff(() -> item.getStatus() == DescriptionStatus.Finalized && !this.isNull(item.getReferences())) .iff(() -> !this.isNull(item.getReferences()))
.on(DescriptionPersist._references) .on(DescriptionPersist._references)
.over(item.getReferences()) .over(item.getReferences())
.using(() -> this.validatorFactory.validator(DescriptionReferencePersist.DescriptionReferencePersistValidator.class)) .using(() -> this.validatorFactory.validator(DescriptionReferencePersist.DescriptionReferencePersistValidator.class))

View File

@ -166,12 +166,15 @@ public class DescriptionTemplatePersist {
.must(() -> this.lessEqualLength(item.getLabel(), DescriptionTemplateEntity._labelLength)) .must(() -> this.lessEqualLength(item.getLabel(), DescriptionTemplateEntity._labelLength))
.failOn(DescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())), .failOn(DescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> item.getStatus() == DescriptionTemplateStatus.Finalized)
.must(() -> !this.isEmpty(item.getDescription())) .must(() -> !this.isEmpty(item.getDescription()))
.failOn(DescriptionTemplatePersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._description}, LocaleContextHolder.getLocale())), .failOn(DescriptionTemplatePersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._description}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> item.getStatus() == DescriptionTemplateStatus.Finalized)
.must(() -> !this.isEmpty(item.getLanguage())) .must(() -> !this.isEmpty(item.getLanguage()))
.failOn(DescriptionTemplatePersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._language}, LocaleContextHolder.getLocale())), .failOn(DescriptionTemplatePersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._language}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> item.getStatus() == DescriptionTemplateStatus.Finalized)
.must(() -> this.isValidGuid(item.getType())) .must(() -> this.isValidGuid(item.getType()))
.failOn(DescriptionTemplatePersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._type}, LocaleContextHolder.getLocale())), .failOn(DescriptionTemplatePersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._type}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
@ -179,6 +182,7 @@ public class DescriptionTemplatePersist {
.failOn(DescriptionTemplatePersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._status}, LocaleContextHolder.getLocale())), .failOn(DescriptionTemplatePersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._status}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> item.getStatus() == DescriptionTemplateStatus.Finalized)
.must(() -> !this.isNull(item.getDefinition())) .must(() -> !this.isNull(item.getDefinition()))
.failOn(DescriptionTemplatePersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._definition}, LocaleContextHolder.getLocale())), .failOn(DescriptionTemplatePersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._definition}, LocaleContextHolder.getLocale())),
this.refSpec() this.refSpec()
@ -187,6 +191,7 @@ public class DescriptionTemplatePersist {
.over(item.getDefinition()) .over(item.getDefinition())
.using(() -> this.validatorFactory.validator(DefinitionPersist.DefinitionPersistValidator.class)), .using(() -> this.validatorFactory.validator(DefinitionPersist.DefinitionPersistValidator.class)),
this.spec() this.spec()
.iff(() -> item.getStatus() == DescriptionTemplateStatus.Finalized)
.must(() -> !this.isNull(item.getUsers())) .must(() -> !this.isNull(item.getUsers()))
.failOn(DescriptionTemplatePersist._users).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._users}, LocaleContextHolder.getLocale())), .failOn(DescriptionTemplatePersist._users).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._users}, LocaleContextHolder.getLocale())),
this.navSpec() this.navSpec()

View File

@ -127,6 +127,7 @@ public class DmpBlueprintPersist {
.failOn(DmpBlueprintPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintPersist._status}, LocaleContextHolder.getLocale())), .failOn(DmpBlueprintPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintPersist._status}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> item.getStatus() == DmpBlueprintStatus.Finalized)
.must(() -> !this.isNull(item.getDefinition())) .must(() -> !this.isNull(item.getDefinition()))
.failOn(DmpBlueprintPersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintPersist._definition}, LocaleContextHolder.getLocale())), .failOn(DmpBlueprintPersist._definition).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintPersist._definition}, LocaleContextHolder.getLocale())),
this.refSpec() this.refSpec()

View File

@ -5,7 +5,6 @@ import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.specification.Specification; import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.validation.StatusAware;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@ -44,7 +43,7 @@ public class DmpDescriptionTemplatePersist {
@Component(DmpDescriptionTemplatePersistValidator.ValidatorName) @Component(DmpDescriptionTemplatePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DmpDescriptionTemplatePersistValidator extends BaseValidator<DmpDescriptionTemplatePersist> implements StatusAware<DmpStatus> { public static class DmpDescriptionTemplatePersistValidator extends BaseValidator<DmpDescriptionTemplatePersist> {
public static final String ValidatorName = "DmpDescriptionTemplatePersistValidator"; public static final String ValidatorName = "DmpDescriptionTemplatePersistValidator";
@ -66,21 +65,14 @@ public class DmpDescriptionTemplatePersist {
protected List<Specification> specifications(DmpDescriptionTemplatePersist item) { protected List<Specification> specifications(DmpDescriptionTemplatePersist item) {
return Arrays.asList( return Arrays.asList(
this.spec() this.spec()
.iff(() -> this.status == DmpStatus.Finalized)
.must(() -> this.isValidGuid(item.getDescriptionTemplateGroupId())) .must(() -> this.isValidGuid(item.getDescriptionTemplateGroupId()))
.failOn(DmpDescriptionTemplatePersist._descriptionTemplateGroupId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpDescriptionTemplatePersist._descriptionTemplateGroupId}, LocaleContextHolder.getLocale())), .failOn(DmpDescriptionTemplatePersist._descriptionTemplateGroupId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpDescriptionTemplatePersist._descriptionTemplateGroupId}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.iff(() -> this.status == DmpStatus.Finalized)
.must(() -> this.isValidGuid(item.getSectionId())) .must(() -> this.isValidGuid(item.getSectionId()))
.failOn(DmpDescriptionTemplatePersist._sectionId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpDescriptionTemplatePersist._sectionId}, LocaleContextHolder.getLocale())) .failOn(DmpDescriptionTemplatePersist._sectionId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpDescriptionTemplatePersist._sectionId}, LocaleContextHolder.getLocale()))
); );
} }
@Override
public DmpDescriptionTemplatePersistValidator setStatus(DmpStatus status) {
this.status = status;
return this;
}
} }
} }

View File

@ -206,7 +206,7 @@ public class DmpPersist {
.must(() -> !this.isNull(item.getReferences())) .must(() -> !this.isNull(item.getReferences()))
.failOn(DmpPersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._references}, LocaleContextHolder.getLocale())), .failOn(DmpPersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._references}, LocaleContextHolder.getLocale())),
this.navSpec() this.navSpec()
.iff(() -> item.getStatus() == DmpStatus.Finalized && !this.isNull(item.getReferences())) .iff(() -> !this.isNull(item.getReferences()))
.on(DmpPersist._references) .on(DmpPersist._references)
.over(item.getReferences()) .over(item.getReferences())
.using(() -> this.validatorFactory.validator(DmpReferencePersist.DmpReferencePersistValidator.class)), .using(() -> this.validatorFactory.validator(DmpReferencePersist.DmpReferencePersistValidator.class)),
@ -218,7 +218,7 @@ public class DmpPersist {
.iff(() -> !this.isNull(item.getDescriptionTemplates())) .iff(() -> !this.isNull(item.getDescriptionTemplates()))
.on(DmpPersist._descriptionTemplates) .on(DmpPersist._descriptionTemplates)
.over(item.getDescriptionTemplates()) .over(item.getDescriptionTemplates())
.using(() -> this.validatorFactory.validator(DmpDescriptionTemplatePersist.DmpDescriptionTemplatePersistValidator.class).setStatus(item.getStatus())) .using(() -> this.validatorFactory.validator(DmpDescriptionTemplatePersist.DmpDescriptionTemplatePersistValidator.class))
); );
} }
} }

View File

@ -61,7 +61,7 @@ public class PropertyDefinitionPersist {
.must(() -> !this.isNull(item.getFields())) .must(() -> !this.isNull(item.getFields()))
.failOn(PropertyDefinitionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fields}, LocaleContextHolder.getLocale())), .failOn(PropertyDefinitionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fields}, LocaleContextHolder.getLocale())),
this.navSpec() this.navSpec()
.iff(() -> this.status == DescriptionStatus.Finalized && !this.isNull(item.getFields())) .iff(() -> !this.isNull(item.getFields()))
.on(PropertyDefinitionPersist._fields) .on(PropertyDefinitionPersist._fields)
.over(item.getFields()) .over(item.getFields())
.using(() -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class)) .using(() -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class))