Search in sources :

Example 1 with InvalidForeignKeyException

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

the class ForeignKeyFieldValidator method validate.

/**
 * The RulesEngine will invoke this method to perform the field validation.
 * @throws ValidationException if any validation rule fails.
 * @throws FrameworkException if any framework error occurs.
 */
public void validate() throws ValidationException, FrameworkException {
    if (getValue() != null) {
        UOW uow = getUow();
        boolean localUow = (uow == null);
        try {
            if (localUow)
                uow = new UOW();
            Criteria c = new Criteria();
            c.setTable(getDomainClass());
            c.addCriteria(getProperty(), getValue());
            Collection col = uow.query(c);
            if (col.size() == 0) {
                String str = "ForeignKey validation failed for the value '" + getValue() + "' against the domainClass/field - " + getDomainClass() + '/' + getProperty();
                log.error(str);
                throw new InvalidForeignKeyException(getLabelToken(), new Object[] { getLabelToken(getDomainClass()), getLabelToken(getDomainClass(), getProperty()) });
            }
        } finally {
            if (localUow && uow != null)
                uow.rollback();
        }
    }
}
Also used : InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) Collection(java.util.Collection) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 2 with InvalidForeignKeyException

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

the class Asset method findPartObject.

/**
 * Finds the related foreign Part 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 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(AssetMeta.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 3 with InvalidForeignKeyException

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

the class Item method findConditionObject.

/**
 * Finds the related foreign Condition 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 findConditionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_conditionObject == null && getCondition() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(ConditionMeta.getName());
            criteria.addCriteria(ConditionMeta.CONDITION, getCondition());
            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_conditionObject = (Condition) itr.next();
            }
            if (m_conditionObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(ItemMeta.META_CONDITION.getLabelToken(), new Object[] { ConditionMeta.getLabelToken(), ConditionMeta.META_CONDITION.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : Condition(org.jaffa.persistence.domainobjects.Condition) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Example 4 with InvalidForeignKeyException

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

the class PartRemarks 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(PartRemarksMeta.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 5 with InvalidForeignKeyException

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

the class AuditTransactionObject method findAuditTransactionObject.

/**
 * Finds the related foreign AuditTransaction 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 findAuditTransactionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_auditTransactionObject == null && getTransactionId() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(AuditTransactionMeta.getName());
            criteria.addCriteria(AuditTransactionMeta.TRANSACTION_ID, getTransactionId());
            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_auditTransactionObject = (AuditTransaction) itr.next();
            }
            if (m_auditTransactionObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(AuditTransactionObjectMeta.META_TRANSACTION_ID.getLabelToken(), new Object[] { AuditTransactionMeta.getLabelToken(), AuditTransactionMeta.META_TRANSACTION_ID.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) AuditTransaction(org.jaffa.components.audit.domain.AuditTransaction)

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