Search in sources :

Example 96 with ApplicationExceptions

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

the class CallBackDropdownHelper method getOptions.

public CodeHelperOutElementDto getOptions(HttpServletRequest request, String returnField, String descField, String domainName, CriteriaElementDto[] criteriaFields) throws ApplicationExceptions, FrameworkException {
    CodeHelperOutElementDto m_dropDownCodes = null;
    ApplicationExceptions appExps = null;
    CodeHelperInDto input = null;
    System.out.println("Still alive1");
    if (m_codeHelperTx == null)
        m_codeHelperTx = (ICodeHelper) Factory.createObject(ICodeHelper.class);
    if (m_dropDownCodes == null) {
        if (input == null)
            input = new CodeHelperInDto();
        CodeHelperInElementDto codeHelperInElementDto = new CodeHelperInElementDto();
        codeHelperInElementDto.setCode("sort");
        codeHelperInElementDto.setDomainClassName(domainName);
        codeHelperInElementDto.setCodeFieldName(returnField);
        codeHelperInElementDto.setDescriptionFieldName(descField);
        for (int i = 0; i < criteriaFields.length; i++) {
            CriteriaElementDto criteriaField = criteriaFields[i];
            codeHelperInElementDto.addCriteriaField(criteriaField);
        }
        input.addCodeHelperInElementDto(codeHelperInElementDto);
    }
    // throw ApplicationExceptions, if any parsing errors occured
    if (appExps != null && appExps.size() > 0)
        throw appExps;
    // Get the Codes and populate the respective fields
    if (input != null) {
        System.out.println("Still alive2");
        input.setHeaderDto(getHeaderDto(request));
        System.out.println("Still alive3");
        CodeHelperOutDto output = m_codeHelperTx.getCodes(input);
        if (output != null && output.getCodeHelperOutElementDtoCount() > 0) {
            CodeHelperOutElementDto[] codeHelperOutElementDtos = output.getCodeHelperOutElementDtos();
            for (int i = 0; i < codeHelperOutElementDtos.length; i++) {
                CodeHelperOutElementDto codeHelperOutElementDto = codeHelperOutElementDtos[i];
                String code = codeHelperOutElementDto.getCode();
                if (code.equals("sort"))
                    m_dropDownCodes = codeHelperOutElementDto;
            }
        }
    }
    System.out.println("Still alive4");
    return m_dropDownCodes;
}
Also used : CodeHelperInDto(org.jaffa.components.codehelper.dto.CodeHelperInDto) ICodeHelper(org.jaffa.components.codehelper.ICodeHelper) CodeHelperInElementDto(org.jaffa.components.codehelper.dto.CodeHelperInElementDto) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) CriteriaElementDto(org.jaffa.components.codehelper.dto.CriteriaElementDto) CodeHelperOutDto(org.jaffa.components.codehelper.dto.CodeHelperOutDto) CodeHelperOutElementDto(org.jaffa.components.codehelper.dto.CodeHelperOutElementDto)

Example 97 with ApplicationExceptions

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

the class ExceptionHelper method throwAF.

/**
 * This method will loop through the input exception and its cause, looking for an instance of ApplicationException or ApplicationExceptions or FrameworkException.
 * If ApplicationException is found, it'll be thrown wrapped inside a new ApplicationExceptions instance.
 * If ApplicationExceptions is found, it'll be thrown as is.
 * If FrameworkException is found, it'll be thrown as is.
 * Else the input exception will be returned.
 * @param exception The input.
 * @throws ApplicationExceptions if found in the cause stack of the input exception.
 * @throws FrameworkException if found in the cause stack of the input exception.
 * @return the input exception if neither ApplicationException nor ApplicationExceptions nor FrameworkException are found in the cause stack of the input exception.
 */
public static Throwable throwAF(Throwable exception) throws ApplicationExceptions, FrameworkException {
    ApplicationExceptions appExps = extractApplicationExceptions(exception);
    if (appExps != null)
        throw appExps;
    FrameworkException fe = extractFrameworkException(exception);
    if (fe != null)
        throw fe;
    return exception;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) FrameworkException(org.jaffa.exceptions.FrameworkException)

Example 98 with ApplicationExceptions

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

the class ExceptionHelper method extractApplicationExceptionsFromSQLException.

/**
 * This method will loop through the input exception and its cause, looking for an instance of ApplicationException or ApplicationExceptions.
 * If ApplicationException is found, it'll be returned wrapped inside a new ApplicationExceptions instance.
 * If ApplicationExceptions is found, it'll be returned as is.
 * It will return an instance of LockedApplicationException wrapped inside a new ApplicationExceptions instance if any lockign errors had occured.
 * It will then loop through the cause of the input exception, looking for an instance of SQLException
 * If the error code for the SQLException falls in the range specified by the global-rule 'jaffa.persistence.jdbcengine.customSqlErrorCodeRange',
 * an instance of SQLApplicationException will be returned wrapped inside a new ApplicationExceptions instance.
 * Else a null will be returned.
 *
 * @param exception The input exception.
 * @return an instance of ApplicationExceptions if found in the cause stack of the input exception.
 */
public static ApplicationExceptions extractApplicationExceptionsFromSQLException(SQLException exception) {
    ApplicationExceptions appExps = null;
    // Check for SQLException
    SQLException sqlException = (SQLException) ExceptionHelper.extractException(exception, SQLException.class);
    if (sqlException != null) {
        if ("40001".equals(sqlException.getSQLState()) || "61000".equals(sqlException.getSQLState())) {
            if (log.isDebugEnabled())
                log.debug("Found a SQL for locking errors: " + sqlException.getSQLState());
            appExps = new ApplicationExceptions(new LockedApplicationException(exception));
        } else {
            int errorCode = sqlException.getErrorCode();
            if (c_customSqlErrorCodeStart != null) {
                if (errorCode >= c_customSqlErrorCodeStart.intValue() && errorCode <= c_customSqlErrorCodeEnd.intValue()) {
                    // Extract the first line from the message, since we do not want to pass the SQL stacktrace
                    String reason = sqlException.getMessage();
                    if (reason != null) {
                        int i = reason.indexOf('\n');
                        if (i > -1)
                            reason = reason.substring(0, i);
                    }
                    if (log.isDebugEnabled())
                        log.debug("Convert SQLException to SQLApplicationException since it has a custom sqlErrorCode of " + errorCode);
                    appExps = new ApplicationExceptions(new SQLApplicationException(reason, exception));
                } else {
                    if (log.isDebugEnabled())
                        log.debug("Ignoring SQLException since its ErrorCode is not custom: " + errorCode);
                }
            }
        }
    }
    return appExps;
}
Also used : LockedApplicationException(org.jaffa.persistence.engines.jdbcengine.LockedApplicationException) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) SQLApplicationException(org.jaffa.persistence.engines.jdbcengine.SQLApplicationException) SQLException(java.sql.SQLException)

Example 99 with ApplicationExceptions

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

the class BeanMoulder method deleteBean.

/**
 * Take a source object and delete it or delete is children if it has any
 * @param path The path of this object being processed. This identifies possible parent
 * and/or indexed entries where this object is contained.
 * @param source Source object to mould from, typically a DomainDAO
 * @param uow Transaction handle all creates/update will be performed within.
 * Throws an exception if null.
 * @param handler Possible bean handler to be used when processing this source object graph
 * @throws ApplicationExceptions Thrown if one or more application logic errors are generated during moulding
 * @throws FrameworkException Thrown if any runtime moulding error has occured.
 */
public static void deleteBean(String path, DomainDAO source, UOW uow, MouldHandler handler) throws ApplicationExceptions, FrameworkException {
    log.debug("Delete Bean " + path);
    // Call custom validation code in the DAO
    source.validate();
    ApplicationExceptions aes = new ApplicationExceptions();
    if (uow == null) {
        String err = "UOW Required";
        log.error(err);
        throw new RuntimeException(err);
    }
    try {
        IPersistent domainObject = null;
        GraphMapping mapping = MappingFactory.getInstance(source);
        Map keys = new LinkedHashMap();
        Class doClass = mapping.getDomainClass();
        // Get the key fields used in the domain object
        boolean gotKeys = fillInKeys(path, source, mapping, keys);
        // read DO based on key
        if (gotKeys) {
            // get the method on the DO to read via PK
            Method[] ma = doClass.getMethods();
            Method findByPK = null;
            for (int i = 0; i < ma.length; i++) {
                if (ma[i].getName().equals("findByPK")) {
                    if (ma[i].getParameterTypes().length == (keys.size() + 1) && (ma[i].getParameterTypes())[0] == UOW.class) {
                        // Found with name and correct no. of input params
                        findByPK = ma[i];
                        break;
                    }
                }
            }
            if (findByPK == null) {
                aes.add(new DomainObjectNotFoundException(doClass.getName()));
                throw aes;
            }
            // Build input array
            Object[] inputs = new Object[keys.size() + 1];
            {
                inputs[0] = uow;
                int i = 1;
                for (Iterator it = keys.values().iterator(); it.hasNext(); i++) {
                    inputs[i] = it.next();
                }
            }
            // Find Object based on key
            domainObject = (IPersistent) findByPK.invoke(null, inputs);
        } else
            log.debug("Object " + path + " has either missing or null key values - Assume Create is needed");
        // Error if DO not found
        if (domainObject == null) {
            String label = doClass.getName();
            // Try and use meta data to get domain objects label
            try {
                label = PersistentHelper.getLabelToken(doClass.getName());
            } catch (Exception e) {
            // ignore any problem trying to get the label!
            }
            aes.add(new DomainObjectNotFoundException(label + " (path=" + path + ")"));
            throw aes;
        }
        // Process the delete, either on this DO, or a related DO if there is one
        deleteBeanData(path, source, uow, handler, mapping, domainObject);
    } catch (IllegalAccessException e) {
        MouldException me = new MouldException(MouldException.ACCESS_ERROR, path, e.getMessage());
        log.error(me.getLocalizedMessage(), e);
        throw me;
    } catch (InvocationTargetException e) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof FrameworkException)
                throw (FrameworkException) e.getCause();
            if (e.getCause() instanceof ApplicationExceptions)
                throw (ApplicationExceptions) e.getCause();
            if (e.getCause() instanceof ApplicationException) {
                aes.add((ApplicationException) e.getCause());
                throw aes;
            }
        }
        MouldException me = new MouldException(MouldException.INVOCATION_ERROR, path, e);
        log.error(me.getLocalizedMessage(), me.getCause());
        throw me;
    } catch (InstantiationException e) {
        MouldException me = new MouldException(MouldException.INSTANTICATION_ERROR, path, e.getMessage());
        log.error(me.getLocalizedMessage(), e);
        throw me;
    }
// } catch (Exception e) {
// throw handleException(e,aes);
// }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) FrameworkException(org.jaffa.exceptions.FrameworkException) Method(java.lang.reflect.Method) FrameworkException(org.jaffa.exceptions.FrameworkException) ApplicationException(org.jaffa.exceptions.ApplicationException) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MultipleDomainObjectsFoundException(org.jaffa.exceptions.MultipleDomainObjectsFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) ApplicationException(org.jaffa.exceptions.ApplicationException) IPersistent(org.jaffa.persistence.IPersistent) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) Iterator(java.util.Iterator) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GraphMapping(org.jaffa.beans.moulding.mapping.GraphMapping)

Example 100 with ApplicationExceptions

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

the class BeanMoulder method deleteChildBean.

/**
 *  Take a source object and try and mold it back it its domain object.
 *  This is the same as updateParent, except from the way it retrieved the
 *  record, and the way it creates a new record.
 */
private static void deleteChildBean(String path, DomainDAO source, UOW uow, MouldHandler handler, IPersistent parentDomain, GraphMapping parentMapping, String parentField) throws ApplicationExceptions, FrameworkException {
    log.debug("Delete Child Bean " + path);
    // Call custom validation code in the DAO
    source.validate();
    ApplicationExceptions aes = new ApplicationExceptions();
    if (uow == null) {
        String err = "UOW Required";
        log.error(err);
        throw new RuntimeException(err);
    }
    String relationshipName = parentMapping.getDomainFieldName(parentField);
    if (relationshipName.endsWith("Array"))
        relationshipName = relationshipName.substring(0, relationshipName.length() - 5);
    if (relationshipName.endsWith("Object"))
        relationshipName = relationshipName.substring(0, relationshipName.length() - 6);
    try {
        IPersistent domainObject = null;
        GraphMapping mapping = MappingFactory.getInstance(source);
        Map keys = new LinkedHashMap();
        Class doClass = mapping.getDomainClass();
        boolean gotKeys = false;
        if (mapping.getKeyFields() == null || mapping.getKeyFields().size() == 0) {
            // No keys, must be one-to-one
            log.debug("Find 'one-to-one' object - " + path);
            // Just use the getXxxObject method to get the related domain object,
            // if there is one...
            domainObject = (IPersistent) getProperty(parentMapping.getDomainFieldDescriptor(parentField), parentDomain);
            if (domainObject == null)
                log.debug("Not Found - " + path);
        } else {
            // Get the key fields used in the domain object. Use the findXxxxxCriteria() method,
            // then add the extra fields to the criteria object, to get the unique record.
            gotKeys = fillInKeys(path, source, mapping, keys);
            // read DO based on key
            if (gotKeys) {
                // get the method to get the PK criteria (i.e. public Criteria findVendorSiteCriteria(); )
                Method findCriteria = null;
                String methodName = "find" + StringHelper.getUpper1(relationshipName) + "Criteria";
                try {
                    findCriteria = parentDomain.getClass().getMethod(methodName, new Class[] {});
                } catch (NoSuchMethodException e) {
                    log.error("Find method '" + methodName + "' not found!");
                }
                if (findCriteria == null)
                    throw new MouldException(MouldException.METHOD_NOT_FOUND, path, methodName);
                // Find Criteria For Related Object
                Criteria criteria = (Criteria) findCriteria.invoke(parentDomain, new Object[] {});
                // Add extra key info...
                for (Iterator it = keys.keySet().iterator(); it.hasNext(); ) {
                    String keyField = (String) it.next();
                    Object value = keys.get(keyField);
                    keyField = StringHelper.getUpper1(mapping.getDomainFieldName(keyField));
                    criteria.addCriteria(keyField, value);
                    log.debug(path + "- Add to criteria:" + keyField + "=" + value);
                }
                // See if we get an object :-)
                Iterator itr = uow.query(criteria).iterator();
                if (itr.hasNext())
                    domainObject = (IPersistent) itr.next();
                if (itr.hasNext()) {
                    // Error, multiple objects found
                    MultipleDomainObjectsFoundException m = new MultipleDomainObjectsFoundException(criteria.getTable() + " @ " + path);
                    aes.add(m);
                    throw aes;
                }
            }
        }
        // Error if DO not found
        if (domainObject == null) {
            aes.add(new DomainObjectNotFoundException(doClass.getName() + " @ " + path));
            throw aes;
        }
        // Process the delete, either on this DO, or a related DO if there is one
        deleteBeanData(path, source, uow, handler, mapping, domainObject);
    } catch (IllegalAccessException e) {
        MouldException me = new MouldException(MouldException.ACCESS_ERROR, path, e.getMessage());
        log.error(me.getLocalizedMessage(), e);
        throw me;
    } catch (InvocationTargetException e) {
        if (e.getCause() != null) {
            if (e.getCause() instanceof FrameworkException)
                throw (FrameworkException) e.getCause();
            if (e.getCause() instanceof ApplicationExceptions)
                throw (ApplicationExceptions) e.getCause();
            if (e.getCause() instanceof ApplicationException) {
                aes.add((ApplicationException) e.getCause());
                throw aes;
            }
        }
        MouldException me = new MouldException(MouldException.INVOCATION_ERROR, path, e);
        log.error(me.getLocalizedMessage(), me.getCause());
        throw me;
    } catch (InstantiationException e) {
        MouldException me = new MouldException(MouldException.INSTANTICATION_ERROR, path, e.getMessage());
        log.error(me.getLocalizedMessage(), e);
        throw me;
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) FrameworkException(org.jaffa.exceptions.FrameworkException) Method(java.lang.reflect.Method) Criteria(org.jaffa.persistence.Criteria) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) ApplicationException(org.jaffa.exceptions.ApplicationException) IPersistent(org.jaffa.persistence.IPersistent) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) MultipleDomainObjectsFoundException(org.jaffa.exceptions.MultipleDomainObjectsFoundException) Iterator(java.util.Iterator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GraphMapping(org.jaffa.beans.moulding.mapping.GraphMapping)

Aggregations

ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)575 FrameworkException (org.jaffa.exceptions.FrameworkException)307 FormKey (org.jaffa.presentation.portlet.FormKey)205 ApplicationException (org.jaffa.exceptions.ApplicationException)116 GridModel (org.jaffa.presentation.portlet.widgets.model.GridModel)104 GridModelRow (org.jaffa.presentation.portlet.widgets.model.GridModelRow)103 UOW (org.jaffa.persistence.UOW)82 Criteria (org.jaffa.persistence.Criteria)66 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)59 MandatoryFieldException (org.jaffa.datatypes.exceptions.MandatoryFieldException)23 ValidationException (org.jaffa.datatypes.ValidationException)21 Iterator (java.util.Iterator)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)15 Method (java.lang.reflect.Method)15 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)15 DuplicateKeyException (org.jaffa.exceptions.DuplicateKeyException)14 OutputCommand (org.jaffa.modules.printing.domain.OutputCommand)11 MalformedURLException (java.net.MalformedURLException)10 UserRequest (org.jaffa.applications.jaffa.modules.user.domain.UserRequest)10 PrinterDefinition (org.jaffa.modules.printing.domain.PrinterDefinition)10