mardi 7 juillet 2015

Perform validation on domain model

Our business domain model has complex validation rules, which can only be executed when the model has been updated.

Something like this:

public classs MyDomainModel {
    public DomainValidationContext getValidationContext() {
       ...
    }
}

We don't want to extract these, since:

  1. it would mean duplication of the validation rules.
  2. List item some rules are only "soft-rules" which should result in warning messages without stopping further processing.

We considered duplicating the DomainModel in the Validationr updating the value and checking for validation errors/warnings.

public class SomeValidator implements Validator {
   @Inject
   private DomainEditContext domainEditContext;

   public void validate(final FacesContext context, final UIComponent component, final Object value) {
       MyDomainModel validationModel = domainWorkContext.getDomainModel().clone();
       validationModel.setSomeValue(value);
       DomainValidationContext dvc = validationModel.getValidationContext();
       ...
   }
}

However this is fairly error prone and processing intensive since a full deep copy of the domain model has to be made for every validation.

Is there any better way to perform validations post model update/invoke-application or prior to render-response?

Any other ideas are more than welcome.

Aucun commentaire:

Enregistrer un commentaire