@@ -0,0 +1,2751 @@
+package org.jpos.qi.util;%0A%0Aimport com.vaadin.data.ValidationResult;%0Aimport com.vaadin.data.Validator;%0Aimport com.vaadin.data.ValueContext;%0Aimport org.jpos.ee.DB;%0Aimport org.jpos.ee.DBManager;%0Aimport org.jpos.qi.QIHelper;%0A%0Aimport java.beans.IntrospectionException;%0Aimport java.beans.Introspector;%0Aimport java.beans.PropertyDescriptor;%0Aimport java.lang.reflect.Method;%0A%0Apublic class UniqueValidator%3CT, FieldType%3E implements Validator%3CFieldType%3E %7B%0A    protected QIHelper helper;%0A    Class%3CT%3E clazz;%0A    Method idGetter;%0A    Method fieldGetter;%0A    String field;%0A    String errorMessageCode;%0A%0A    public UniqueValidator(QIHelper helper, Class%3CT%3E clazz, String field)%0A            throws IntrospectionException%0A    %7B%0A        this(helper, clazz, field, %22errorMessage.%22 + field + %22AlreadyExists%22);%0A    %7D%0A%0A    public UniqueValidator(QIHelper helper, Class%3CT%3E clazz, String field, String errorMessageCode)%0A            throws IntrospectionException%0A    %7B%0A        this(helper, clazz, field, errorMessageCode, %22id%22);%0A    %7D%0A%0A    public UniqueValidator(QIHelper helper, Class%3CT%3E clazz, String field, String errorMessageCode, String idField)%0A            throws IntrospectionException%0A    %7B%0A        this.helper = helper;%0A        this.clazz = clazz;%0A        this.field = field;%0A        this.errorMessageCode = errorMessageCode;%0A        for (PropertyDescriptor property : Introspector.getBeanInfo(clazz).getPropertyDescriptors()) %7B%0A            if (property.getName().equals(field)) fieldGetter = property.getReadMethod();%0A            else if (property.getName().equals(idField)) idGetter = property.getReadMethod();%0A        %7D%0A    %7D%0A%0A%0A    /**%0A     * Validates the given value. Returns a %7B@code ValidationResult%7D instance%0A     * representing the outcome of the validation.%0A     *%0A     * @param value   the input value to validate%0A     * @param context the value context for validation%0A     * @return the validation result%0A     */%0A    @Override%0A    public ValidationResult apply(FieldType value, ValueContext context) %7B%0A        @SuppressWarnings(%22unchecked%22)%0A        T originalEntity = (T) helper.getOriginalEntity();%0A        try %7B%0A            T found = DB.exec(db -%3E new DBManager%3C%3E(db, clazz).getItemByParam(field, value));%0A            if (found == null %7C%7C%0A                    originalEntity != null && idGetter.invoke(found).equals(idGetter.invoke(originalEntity)))%0A            %7B%0A                return ValidationResult.ok();%0A            %7D else %7B%0A                return ValidationResult.error(helper.getApp().getMessage(errorMessageCode, value));%0A            %7D%0A        %7D catch (Exception e) %7B%0A            helper.getApp().getLog().error(e);%0A            return ValidationResult.error(helper.getApp().getMessage(e.getClass().getName(), e.getMessage()));%0A        %7D%0A%0A    %7D%0A%7D%0A

Add generic unique QI validator for entities by field