Hi,
previously in CUBA, when I needed to perform entity validation (more complex validation than setting annotations in the entity class) upon a commit action on an ScreenEditor, I was able to annotate the ScreenEditor as
@CicloBean(groups = UiCrossFieldChecks.class)
where CicloBean is the interface that links the class that effectively performed the validation in the following way:
CicloBean.java
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = CicloBeanValidator.class)
public @interface CicloBean {
String message() default "";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
and the class CicloBeanValidator.java
public class CicloBeanValidator implements ConstraintValidator<CicloBean, Ciclo> {
@Override
public boolean isValid(Ciclo value, ConstraintValidatorContext context) {
boolean isvalid = true;
//si el depto tiene un contrato vigente, hay que asociarlo
Departamento d = value.getDepartamento();
ContratoInquilino ci = null;
try{
ci = AppBeans.get(ContratosService.class).devuelveContratoVigenteParaDepartamento(d);
}catch(Exception exc){
//No reporto el fallo de la validacion. No es un error firme, es una incomplecion de datos pero no critica.
}
if (ci!=null){
if (value.getContratoInquilino()==null){
context.buildConstraintViolationWithTemplate("Se ha detectado la existencia de un Contrato Vigente pero el ciclo no tiene Contrato Asociado").addConstraintViolation();
isvalid = false;
}
}
return isvalid;
}
}
Now, this classes in CUBA were located at:
/[PROJECT]/modules/global/src/[company package tree]/validations
note that PROJECT is my project name and ‘company package tree’ is my package structure, and validations is the package where I stored all that logic.
Where should I place this logic in JMIX? In JMIX I don’t see an equivalent project tree structure that clearly points to an analogous location for those files:
/[PROJECT]/src/main/java/[package structure]/
…/entity
…/screen
…/security
I have checked the JMIX internal classes and a class such as UiCrossFieldChecks is located at the package ‘io.jmix.core.validation.group’, so the logic seems to still be there and if no warning against it, I would continue to apply the same logic for entity validation, just don’t know where to place the files.
Many thanks in advance.
Regards,
Carlos.