Search in sources :

Example 21 with InvalidForeignKeyException

use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.

the class PartAdditional method findPartObject.

/**
 * Finds the related Part object.
 * If checkExistenceOnly is false, then the related object will be fetched and assigned to the corresponding member variable of this class.
 * If checkExistenceOnly is true, then a mere existence check is performed for the related object, as oppposed to fetching all the values for that object.
 */
private void findPartObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_partObject == null && getPart() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(PartMeta.getName());
            criteria.addCriteria(PartMeta.PART, getPart());
            if (checkExistenceOnly)
                criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
            Number count = null;
            if (uow == null || !uow.isActive()) {
                uow = new UOW();
                localUow = true;
            }
            Iterator itr = uow.query(criteria).iterator();
            if (itr.hasNext()) {
                if (checkExistenceOnly)
                    count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
                else
                    m_partObject = (Part) itr.next();
            }
            if (m_partObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(PartAdditionalMeta.META_PART.getLabelToken(), new Object[] { PartMeta.getLabelToken(), PartMeta.META_PART.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : Part(org.jaffa.persistence.domainobjects.Part) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Example 22 with InvalidForeignKeyException

use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.

the class PartPicture method findPartObject.

/**
 * Finds the related Part object.
 * If checkExistenceOnly is false, then the related object will be fetched and assigned to the corresponding member variable of this class.
 * If checkExistenceOnly is true, then a mere existence check is performed for the related object, as oppposed to fetching all the values for that object.
 */
private void findPartObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_partObject == null && getPart() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(PartMeta.getName());
            criteria.addCriteria(PartMeta.PART, getPart());
            if (checkExistenceOnly)
                criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
            Number count = null;
            if (uow == null || !uow.isActive()) {
                uow = new UOW();
                localUow = true;
            }
            Iterator itr = uow.query(criteria).iterator();
            if (itr.hasNext()) {
                if (checkExistenceOnly)
                    count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
                else
                    m_partObject = (Part) itr.next();
            }
            if (m_partObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(PartPictureMeta.META_PART.getLabelToken(), new Object[] { PartMeta.getLabelToken(), PartMeta.META_PART.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : Part(org.jaffa.persistence.domainobjects.Part) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Example 23 with InvalidForeignKeyException

use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.

the class PartRemarksPicture method findPartObject.

/**
 * Finds the related Part object.
 * If checkExistenceOnly is false, then the related object will be fetched and assigned to the corresponding member variable of this class.
 * If checkExistenceOnly is true, then a mere existence check is performed for the related object, as oppposed to fetching all the values for that object.
 */
private void findPartObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_partObject == null && getPart() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(PartMeta.getName());
            criteria.addCriteria(PartMeta.PART, getPart());
            if (checkExistenceOnly)
                criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
            Number count = null;
            if (uow == null || !uow.isActive()) {
                uow = new UOW();
                localUow = true;
            }
            Iterator itr = uow.query(criteria).iterator();
            if (itr.hasNext()) {
                if (checkExistenceOnly)
                    count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
                else
                    m_partObject = (Part) itr.next();
            }
            if (m_partObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(PartRemarksPictureMeta.META_PART.getLabelToken(), new Object[] { PartMeta.getLabelToken(), PartMeta.META_PART.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : Part(org.jaffa.persistence.domainobjects.Part) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Example 24 with InvalidForeignKeyException

use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.

the class PartialForeignKeyValidator method validateProperty.

/**
 * {@inheritDoc}
 */
@Override
protected void validateProperty(T targetObject, String targetPropertyName, Object targetPropertyValue, List<RuleMetaData> rules, UOW uow) throws ApplicationException, FrameworkException {
    if (targetPropertyValue != null) {
        for (RuleMetaData rule : rules) {
            if (log.isDebugEnabled()) {
                log.debug("Applying " + rule + " on " + targetPropertyValue);
            }
            String domainName = rule.getParameter(PARAMETER_DOMAIN_NAME);
            String propName = rule.getParameter(PARAMETER_PROPERTY_NAME);
            if (propName == null) {
                propName = targetPropertyName;
            }
            propName = StringHelper.getUpper1(propName);
            Criteria c = new Criteria();
            c.setTable(domainName);
            c.addCriteria(propName, targetPropertyValue);
            if (!uow.query(c).iterator().hasNext()) {
                String className;
                try {
                    className = Class.forName(domainName).getName();
                } catch (ClassNotFoundException e) {
                    throw new JaffaRulesFrameworkException(e.getMessage(), null, e);
                }
                // Invalid value. Display the list of valid values in the error message
                // It is valid for multiple row to be returned so we don't check for that here
                String domainLabel = getObjectLabel(className, null);
                String fkLabel = getPropertyLabel(targetObject, targetPropertyName);
                String primaryKeyLabel = getPrimaryKeyLabel(className, null);
                if (primaryKeyLabel == null) {
                    primaryKeyLabel = fkLabel.toString();
                }
                if (log.isDebugEnabled()) {
                    log.debug("PartialForeignKey validation for the value '" + targetPropertyValue + "' of '" + targetPropertyName + "' failed against the domainObject '" + domainName + '\'');
                }
                String errorCode = getErrorCode(primaryKeyLabel, rule);
                Object[] arguments = getErrorArgumentArray(targetObject, rule);
                if (arguments == null) {
                    arguments = new Object[] { domainLabel, primaryKeyLabel };
                }
                throw wrapException(new InvalidForeignKeyException(errorCode, arguments), targetObject, rule);
            }
        }
    }
}
Also used : InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) RuleMetaData(org.jaffa.rules.meta.RuleMetaData) Criteria(org.jaffa.persistence.Criteria) JaffaRulesFrameworkException(org.jaffa.rules.JaffaRulesFrameworkException)

Example 25 with InvalidForeignKeyException

use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.

the class FormDefinition method findFormGroupObject.

/**
 * Finds the related foreign FormGroup object.
 * If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
 * If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
 */
private void findFormGroupObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_formGroupObject == null && getFormName() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(FormGroupMeta.getName());
            criteria.addCriteria(FormGroupMeta.FORM_NAME, getFormName());
            if (checkExistenceOnly)
                criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
            Number count = null;
            if (uow == null || !uow.isActive()) {
                uow = new UOW();
                localUow = true;
            }
            Iterator itr = uow.query(criteria).iterator();
            if (itr.hasNext()) {
                if (checkExistenceOnly)
                    count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
                else
                    m_formGroupObject = (FormGroup) itr.next();
            }
            if (m_formGroupObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(FormDefinitionMeta.META_FORM_NAME.getLabelToken(), new Object[] { FormGroupMeta.getLabelToken(), FormGroupMeta.META_FORM_NAME.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : FormGroup(org.jaffa.modules.printing.domain.FormGroup) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Aggregations

InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)30 Part (org.jaffa.persistence.domainobjects.Part)6 Method (java.lang.reflect.Method)3 PrinterOutputType (org.jaffa.modules.printing.domain.PrinterOutputType)3 Transaction (org.jaffa.transaction.domain.Transaction)3 PropertyDescriptor (java.beans.PropertyDescriptor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Set (java.util.Set)2 ApplicationException (org.jaffa.exceptions.ApplicationException)2 FrameworkException (org.jaffa.exceptions.FrameworkException)2 FormGroup (org.jaffa.modules.printing.domain.FormGroup)2 Criteria (org.jaffa.persistence.Criteria)2 IPersistent (org.jaffa.persistence.IPersistent)2 Condition (org.jaffa.persistence.domainobjects.Condition)2 JaffaRulesFrameworkException (org.jaffa.rules.JaffaRulesFrameworkException)2 Extension1 (org.jaffa.rules.testmodels.Extension1)2 AccessibleObject (java.lang.reflect.AccessibleObject)1