Search in sources :

Example 26 with InvalidForeignKeyException

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

the class FormTemplate method findFormDefinitionObject.

/**
 * Finds the related FormDefinition 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 findFormDefinitionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_formDefinitionObject == null && getFormId() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(FormDefinitionMeta.getName());
            criteria.addCriteria(FormDefinitionMeta.FORM_ID, getFormId());
            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_formDefinitionObject = (FormDefinition) itr.next();
            }
            if (m_formDefinitionObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(FormTemplateMeta.META_FORM_ID.getLabelToken(), new Object[] { FormDefinitionMeta.getLabelToken(), FormDefinitionMeta.META_FORM_ID.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) FormDefinition(org.jaffa.modules.printing.domain.FormDefinition)

Example 27 with InvalidForeignKeyException

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

the class FormUsage 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(FormUsageMeta.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)

Example 28 with InvalidForeignKeyException

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

the class SOAEventParam method findSOAEventObject.

/**
 * Finds the related foreign SOAEvent 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 findSOAEventObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    UOW uow = getUOW();
    boolean localUow = false;
    try {
        if (m_sOAEventObject == null && getEventId() != null) {
            Criteria criteria = new Criteria();
            criteria.setTable(SOAEventMeta.getName());
            criteria.addCriteria(SOAEventMeta.EVENT_ID, getEventId());
            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_sOAEventObject = (SOAEvent) itr.next();
            }
            if (m_sOAEventObject == null && (count == null || count.intValue() <= 0))
                throw new InvalidForeignKeyException(SOAEventParamMeta.META_EVENT_ID.getLabelToken(), new Object[] { SOAEventMeta.getLabelToken(), SOAEventMeta.META_EVENT_ID.getLabelToken() });
        }
    } finally {
        if (localUow && uow != null)
            uow.rollback();
    }
}
Also used : InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) SOAEvent(org.jaffa.soa.domain.SOAEvent)

Example 29 with InvalidForeignKeyException

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

the class ExtensionTest method testCompositeForeignKey.

public void testCompositeForeignKey() {
    try {
        Extension1 obj = createExtension1();
        try {
            obj.setField10("KEY1");
            obj.setField5(4L);
            obj.validate();
        } catch (Exception e) {
            InvalidForeignKeyException appExp = (InvalidForeignKeyException) ExceptionHelper.extractException(e, InvalidForeignKeyException.class);
            if (appExp != null) {
                Object[] arguments = appExp.getArguments();
                assertNotNull("The InvalidForeignKeyException should have arguments", arguments);
                assertTrue("The InvalidForeignKeyException should have arguments", arguments.length > 0);
                assertEquals("The InvalidForeignKeyException should have been created for field10,field5", "field10,field5", arguments[0]);
            } else {
                throw e;
            }
        }
        // The following is a valid foreign-key and should work
        obj.setField10("KEY1");
        obj.setField5(3L);
        obj.validate();
    } catch (Exception e) {
        e.printStackTrace(System.err);
        fail();
    }
}
Also used : InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) Extension1(org.jaffa.rules.testmodels.Extension1) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Example 30 with InvalidForeignKeyException

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

the class TransactionDependency method findDependsOnTransactionObject.

/**
 * Finds the related foreign Transaction 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 findDependsOnTransactionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
    // TODO this is generated code...
    if (m_dependsOnTransactionObject == null && getDependsOnId() != null) {
        Transaction transaction = getTransactionDAO().getTransaction(getDependsOnId());
        Number count = null;
        if (checkExistenceOnly) {
            if (transaction != null) {
                count = 1;
            }
        } else {
            m_dependsOnTransactionObject = transaction;
        }
        if ((m_dependsOnTransactionObject == null) && ((count == null) || (count.intValue() <= 0))) {
            throw new InvalidForeignKeyException(TransactionDependencyMeta.META_DEPENDS_ON_ID.getLabelToken(), new Object[] { TransactionMeta.getLabelToken(), TransactionMeta.META_ID.getLabelToken() });
        }
    }
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) 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