Search in sources :

Example 1 with DomainObjectValidationException

use of org.jaffa.persistence.exceptions.DomainObjectValidationException in project jaffa-framework by jaffa-projects.

the class PersistentHelper method checkMandatoryFields.

/**
 * This will check all the mandatory fields of the persistent object.
 * It utilises the corresponding Meta class for determining the mandatory fields.
 * @param object The persistent object.
 * @throws ApplicationExceptions Will contain a collection of MandatoryFieldExceptions for the all the mandatory fields which do not have values.
 * @throws FrameworkException If any framework error occurs.
 */
public static void checkMandatoryFields(IPersistent object) throws ApplicationExceptions, FrameworkException {
    try {
        FieldMetaData[] fields = getMandatoryFields(object.getClass().getName());
        if (fields != null && fields.length > 0) {
            ApplicationExceptions appExps = new ApplicationExceptions();
            for (int i = 0; i < fields.length; i++) {
                FieldMetaData fieldMetaData = fields[i];
                Object fieldValue = BeanHelper.getField(object, fieldMetaData.getName());
                if (fieldValue == null || (fieldValue instanceof String && ((String) fieldValue).length() == 0)) {
                    if (log.isDebugEnabled())
                        log.debug("Mandatory validation failed for the field " + fieldMetaData.getName());
                    appExps.add(new MandatoryFieldException(fieldMetaData.getLabelToken()));
                }
            }
            if (appExps.size() > 0)
                throw appExps;
        }
    } catch (ClassNotFoundException e) {
        String str = "Exception thrown while validating the domain object " + object;
        log.error(str, e);
        throw new DomainObjectValidationException(null, e);
    } catch (NoSuchMethodException e) {
        String str = "Exception thrown while validating the domain object " + object;
        log.error(str, e);
        throw new DomainObjectValidationException(null, e);
    } catch (IllegalAccessException e) {
        String str = "Exception thrown while validating the domain object " + object;
        log.error(str, e);
        throw new DomainObjectValidationException(null, e);
    } catch (InvocationTargetException e) {
        String str = "Exception thrown while validating the domain object " + object;
        log.error(str, e);
        throw new DomainObjectValidationException(null, e);
    }
}
Also used : FieldMetaData(org.jaffa.metadata.FieldMetaData) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) MandatoryFieldException(org.jaffa.datatypes.exceptions.MandatoryFieldException) DomainObjectValidationException(org.jaffa.persistence.exceptions.DomainObjectValidationException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MandatoryFieldException (org.jaffa.datatypes.exceptions.MandatoryFieldException)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 FieldMetaData (org.jaffa.metadata.FieldMetaData)1 DomainObjectValidationException (org.jaffa.persistence.exceptions.DomainObjectValidationException)1