Class StandardRelationCountEntityValidator

java.lang.Object
ch.tocco.nice2.persist.core.api.validation.AbstractEntityValidator
ch.tocco.nice2.persist.core.impl.validation.StandardRelationCountEntityValidator
All Implemented Interfaces:
EntitiesValidator, EntityValidator

public class StandardRelationCountEntityValidator extends AbstractEntityValidator
validate the number of relations. the relation to validate and the maximum relation size can be defined in the contribution.

 @Bean
 public StandardRelationCountEntityValidatorContribution consultingStandardRelationCountEntityValidatorContribution() {
     StandardRelationCountEntityValidatorContribution contribution = new StandardRelationCountEntityValidatorContribution();
     contribution.setEntityName("Consulting");
     contribution.setRelation("relConsulting_content");
     contribution.setErrorMessage("validation.message.numberOfConsultingContent");
     contribution.setNumberOfAllowedRelations(3);
     return contribution;
 }
 
  • Constructor Details

    • StandardRelationCountEntityValidator

      public StandardRelationCountEntityValidator()
  • Method Details

    • validate

      public void validate(Entity entity, EntityValidationResult validationResult) throws PersistException
      Description copied from interface: EntityValidator
      Validate the entity at hand.
      Parameters:
      entity - the entity to be validated
      validationResult - the EntityValidationResult to write the result of the validation to. EntityValidationResult for more details on how to construct the EntityValidationResult.
      Throws:
      PersistException
    • addMyself

      public boolean addMyself(EntityModel model)
      Description copied from interface: EntitiesValidator
      Implement this method to return true if the Validator should add itself to the EntityModel at hand. This method can be useful, if a validator is being used for all models meeting a certain requirement (e.g. model has a field of type X, entity is a lookup entity, etc.). The method is called for each entity model at application startup when building the entity model.
      Specified by:
      addMyself in interface EntitiesValidator
      Overrides:
      addMyself in class AbstractEntityValidator
      Parameters:
      model - the EntityModel
      Returns:
      true to add the Validator to the EntityModel at hand
    • setRelationCount

      @Autowired(required=false) public void setRelationCount(List<StandardRelationCountEntityValidatorContribution> relationsToCount)