Search in sources :

Example 91 with ApplicationException

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

the class FinderAction method do_LoadQuery_Clicked.

/**
 * This event is invoked when a user presses the LoadQuery button
 * @return The FormKey for the criteria screen
 */
public FormKey do_LoadQuery_Clicked() {
    FormKey fk = null;
    FinderForm myForm = (FinderForm) form;
    FinderComponent2 myComp = (FinderComponent2) myForm.getComponent();
    if (myForm.doValidateForLoadQuery(request)) {
        if (myComp.getSavedQueryId() != null) {
            try {
                myComp.loadQuery();
                myForm.doValidate(request);
            } catch (ApplicationException e) {
                if (log.isDebugEnabled())
                    log.debug("ModifySearch Failed");
                myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
            }
        }
    }
    try {
        fk = myComp.displayCriteria();
    } catch (ApplicationExceptions e) {
        if (log.isDebugEnabled())
            log.debug("ModifySearch Failed");
        myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
    } catch (FrameworkException e) {
        log.error(null, e);
        myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, "error.framework.general");
    }
    // Direct User back to current form
    if (fk == null)
        fk = myComp.getCriteriaFormKey();
    return fk;
}
Also used : ApplicationException(org.jaffa.exceptions.ApplicationException) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) FrameworkException(org.jaffa.exceptions.FrameworkException) FormKey(org.jaffa.presentation.portlet.FormKey)

Example 92 with ApplicationException

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

the class LockingService method checkOrDeleteLockingTransactions.

/**
 * Browses all Transactions looking for the locks, as specified in the transaction-configuration for the input dataBean.
 * Calls any specified lock-check filter class if one has been defined
 * Throws an ApplicationException, if any matching Transaction is found, and if the input argument 'deleteLockingTransaction' is false.
 * Deletes all matching Transactions, if the input argument 'deleteLockingTransaction' is true.
 *
 * @param uow                      The UOW.
 * @param dataBean                 Any serializable object.
 * @param transactionInfo          the corresponding TransactionInfo object, as specified in the configuration file.
 * @param deleteLockingTransaction determines if the matching Transactions are to be deleted.
 * @throws FrameworkException    Indicates some system error.
 * @throws ApplicationExceptions Indicates application error(s).
 */
private static void checkOrDeleteLockingTransactions(UOW uow, Object dataBean, TransactionInfo transactionInfo, boolean deleteLockingTransaction, String transactionId) throws FrameworkException, ApplicationExceptions {
    // Check if lock checks exists for the message
    if (transactionInfo.getLockCheck() != null) {
        Filter filterConfig = transactionInfo.getLockCheck().getFilter();
        // Load the appropriate class
        if (filterConfig != null) {
            try {
                Class<ILockCheckFilter> filterClass = (Class<ILockCheckFilter>) Class.forName(filterConfig.getClassName());
                TransactionMessageService transactionService = TransactionMessageDAOFactory.getTransactionMessageService();
                Collection<Transaction> transactions = filterClass.newInstance().getFilteredResults(dataBean, transactionService);
                deleteLockCheck(uow, transactions, deleteLockingTransaction, transactionId);
            } catch (Exception e) {
                throw ExceptionHelper.throwAFR(e);
            }
        // load the load check parameters directly from the message config
        } else if (transactionInfo.getLockCheck().getParam() != null) {
            TransactionMessageDAO transactionDAO = TransactionMessageDAOFactory.getTransactionMessageDAO();
            // Run this logic for each Param
            for (Param param : transactionInfo.getLockCheck().getParam()) {
                String value = TransactionEngine.obtainParamValue(param, dataBean);
                Collection<Transaction> transactions = transactionDAO.getTransactionsByField(param.getName(), value);
                deleteLockCheck(uow, transactions, deleteLockingTransaction, transactionId);
            }
        }
    }
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) Filter(org.jaffa.transaction.services.configdomain.Filter) TransactionMessageDAO(org.jaffa.transaction.daos.TransactionMessageDAO) Param(org.jaffa.transaction.services.configdomain.Param) Collection(java.util.Collection) TransactionMessageService(org.jaffa.transaction.daos.TransactionMessageService) FrameworkException(org.jaffa.exceptions.FrameworkException) ApplicationException(org.jaffa.exceptions.ApplicationException)

Example 93 with ApplicationException

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

the class LockingService method deleteLockCheck.

/**
 * @param uow                      The UOW.
 * @param transactions             the transactions the check
 * @param deleteLockingTransaction determines if the matching Transactions are to be deleted.
 * @throws FrameworkException    Indicates some system error.
 * @throws ApplicationExceptions Indicates application error(s).
 */
private static void deleteLockCheck(UOW uow, Collection<Transaction> transactions, boolean deleteLockingTransaction, String transactionId) throws FrameworkException, ApplicationExceptions {
    // Now perform the checking based on the flag
    if (deleteLockingTransaction) {
        TransactionMessageDAO transactionDAO = TransactionMessageDAOFactory.getTransactionMessageDAO();
        for (Transaction transaction : transactions) {
            if (Transaction.Status.I.toString().equals(transaction.getStatus())) {
                // Interrupt an In-Process Transaction
                try {
                    transaction.setStatus(Transaction.Status.INT.toString());
                    transactionDAO.save(uow, transaction);
                } catch (ApplicationException e) {
                    if (log.isDebugEnabled()) {
                        log.debug("Exception thrown while Interrupting an In-Process Transaction", e);
                    }
                    throw new ApplicationExceptions(e);
                }
            } else if (!Transaction.Status.INT.toString().equals(transaction.getStatus())) {
                // Ignore an Interrupted Transaction
                // Delete the Transaction
                transactionDAO.delete(uow, transaction);
            }
        }
    } else {
        for (Transaction transaction : transactions) {
            if (!Transaction.Status.S.toString().equals(transaction.getStatus())) {
                // Should throw an exception. This also prevents a message from locking itself out
                if ((transactionId == null) || !transaction.getId().equals(transactionId)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Found Transaction record(s) that match the lock criteria");
                    }
                    throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.lockError"));
                }
            }
        }
    }
}
Also used : ApplicationException(org.jaffa.exceptions.ApplicationException) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) Transaction(org.jaffa.transaction.domain.Transaction) TransactionMessageDAO(org.jaffa.transaction.daos.TransactionMessageDAO)

Example 94 with ApplicationException

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

the class TransactionService method localUpdate.

/**
 * This override to the base class performs the following:
 * - Automatically transforms the Delete of an In-Process Transaction, to an Update to INT status
 * - An Interrupted Transaction cannot be deleted
 * - Only allows status change from E to O
 * - Allows creation of a new Transaction in O or H status only
 */
@Override
public TransactionGraph localUpdate(String path, TransactionGraph graph, UOW uow) throws FrameworkException, ApplicationExceptions {
    boolean createMode = true;
    if (graph.getId() != null) {
        Transaction domain = Transaction.findByPK(uow, graph.getId());
        if (domain != null) {
            createMode = false;
            if (domain.getType() != null && !TransactionEngine.getInstance().hasAdminAccess(domain.getType())) {
                // Admin access is needed to update/delete/resubmit this transaction
                throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { domain.getType() }));
            }
            if (graph.getDeleteObject() != null && graph.getDeleteObject()) {
                if (Transaction.Status.I.toString().equals(domain.getStatus())) {
                    // Automatically transform the Delete of an In-Process Transaction, to an Update to INT status
                    graph.setDeleteObject(null);
                    graph.setStatus(Transaction.Status.INT.toString());
                } else if (Transaction.Status.INT.toString().equals(domain.getStatus())) {
                    // An Interrupted Transaction cannot be deleted
                    throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.cannnotDeleteINT"));
                }
            } else if (graph.hasChanged("status") && !((Transaction.Status.E.toString().equals(domain.getStatus()) || Transaction.Status.O.toString().equals(domain.getStatus())) && Transaction.Status.O.toString().equals(graph.getStatus()))) {
                // Only allow status change from E to O (or O to O)
                throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.invalidStatusChange"));
            }
        }
    }
    if (createMode) {
        if (graph.getType() != null && !TransactionEngine.getInstance().hasAdminAccess(graph.getType())) {
            // Admin access is needed to create this transaction
            throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { graph.getType() }));
        }
        if (graph.getStatus() == null)
            graph.setStatus(Transaction.Status.O.toString());
        else if (!Transaction.Status.O.toString().equals(graph.getStatus()) && !Transaction.Status.H.toString().equals(graph.getStatus())) {
            // Allow creation of a new Transaction in O or H status only
            throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.invalidStatusOnCreate"));
        }
    }
    return super.localUpdate(path, graph, uow);
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) Transaction(org.jaffa.transaction.domain.Transaction)

Example 95 with ApplicationException

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

the class OutputCommand method validate.

// .//GEN-END:preUpdate_2_be
// All the custom code goes here//GEN-FIRST:custom
/**
 * {@inheritDoc}
 */
@Override
public void validate() throws ApplicationExceptions, FrameworkException {
    // Do not perform the sequenceNo related validations if this instance is being resequenced
    if (!m_isBeingResequenced) {
        // The sequenceNo should be at least 1
        if (isModified(OutputCommandMeta.SEQUENCE_NO)) {
            if (getSequenceNo() == null || getSequenceNo().longValue() < 1)
                throw new ApplicationExceptions(new BelowMinimumException(OutputCommandMeta.META_SEQUENCE_NO.getLabelToken(), new Object[] { new Long(1) }));
        }
        // The sequenceNo should not exceed the total number of records for a given outputType by more than 1
        if (isModified(OutputCommandMeta.OUTPUT_TYPE) || isModified(OutputCommandMeta.SEQUENCE_NO)) {
            long count = 0;
            Criteria criteria = new Criteria();
            criteria.setTable(OutputCommandMeta.getName());
            if (getOutputCommandId() != null)
                criteria.addCriteria(OutputCommandMeta.OUTPUT_COMMAND_ID, Criteria.RELATIONAL_NOT_EQUALS, getOutputCommandId());
            criteria.addCriteria(OutputCommandMeta.OUTPUT_TYPE, getOutputType());
            criteria.addFunction(Criteria.FUNCTION_COUNT, null, "f1");
            Iterator itr = getUOW().query(criteria).iterator();
            if (itr.hasNext()) {
                Map row = (Map) itr.next();
                if (row.get("f1") != null)
                    count = ((Number) row.get("f1")).longValue();
            }
            if ((getSequenceNo().longValue() - count) > 1) {
                log.error("The sequenceNo " + getSequenceNo() + " is much greater than the number of rows " + count);
                throw new ApplicationExceptions(new ApplicationException("exception.Jaffa.Printing.OutputCommandMaintenance.ValidSequenceNo") {
                });
            }
        }
    }
    super.validate();
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) BelowMinimumException(org.jaffa.datatypes.exceptions.BelowMinimumException)

Aggregations

ApplicationException (org.jaffa.exceptions.ApplicationException)125 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)114 FrameworkException (org.jaffa.exceptions.FrameworkException)97 UOW (org.jaffa.persistence.UOW)79 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)11 Criteria (org.jaffa.persistence.Criteria)11 Method (java.lang.reflect.Method)10 Iterator (java.util.Iterator)10 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 GraphMapping (org.jaffa.beans.moulding.mapping.GraphMapping)6 OutputCommand (org.jaffa.modules.printing.domain.OutputCommand)6 PrinterDefinition (org.jaffa.modules.printing.domain.PrinterDefinition)6 PrinterOutputType (org.jaffa.modules.printing.domain.PrinterOutputType)6 User (org.jaffa.applications.jaffa.modules.admin.domain.User)5 UserRequest (org.jaffa.applications.jaffa.modules.user.domain.UserRequest)5 UserTimeEntry (org.jaffa.applications.test.modules.time.domain.UserTimeEntry)5 Attachment (org.jaffa.components.attachment.domain.Attachment)5