Search in sources :

Example 16 with Transaction

use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.

the class TransactionDependencySweeper method updateTransaction.

/**
 * Updated missed Transaction records
 * @param tdv
 * @param databean
 */
private void updateTransaction(TransactionSweeperView tdv, TransactionDependencySweeper databean) {
    UOW innerUow = null;
    try {
        innerUow = new UOW();
        Transaction transaction = Transaction.findByPK(innerUow, tdv.getId());
        if (transaction == null) {
            log.info("Transaction '" + tdv.getId() + "' not found; cannot update it's status to O");
            throw new DomainObjectNotFoundException(TransactionDependencyMeta.getLabelToken());
        } else {
            transaction.setStatus(Transaction.Status.O.toString());
            transactionMessageDAO.save(innerUow, transaction);
            innerUow.commit();
        }
    } catch (Exception e) {
        // Write to business event log
        MDC.put(BusinessEventLogMeta.SCHEDULED_TASK_ID, databean.getScheduleTaskId());
        MDC.put(BusinessEventLogMeta.LOGGED_BY, databean.getLoggedBy());
        log.error("Exception thrown during update of Transaction record" + e);
    } finally {
        if (innerUow != null) {
            try {
                innerUow.rollback();
            } catch (Exception e) {
                log.error("Unable to rollback inner UOW in updating Transaction");
            }
        }
    }
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) UOW(org.jaffa.persistence.UOW) FrameworkException(org.jaffa.exceptions.FrameworkException) ApplicationException(org.jaffa.exceptions.ApplicationException) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException)

Example 17 with Transaction

use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.

the class TransactionEngine method updateTransactionStatusToError.

/**
 * Retrieves the Transaction and update it's status to E.
 * NOTE: The processing happens within the scope of a local new UOW.
 *
 * @param id        the Transaction Id.
 * @param exception the cause for the error.
 * @throws FrameworkException    Indicates some system error.
 * @throws ApplicationExceptions Indicates application error(s).
 */
public void updateTransactionStatusToError(String id, Exception exception) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        uow = new UOW();
        Transaction transaction = getTransaction(uow, id);
        if (transaction == null) {
            log.error("Transaction '" + id + "' not found; cannot update it's status to E");
            throw new DomainObjectNotFoundException(TransactionMeta.getLabelToken());
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Updating Transaction '" + transaction.getId() + "' to status E");
            }
            transaction.stampError(exception);
            getTransactionDAO().save(uow, transaction);
            uow.commit();
            try {
                sendFailureNotification(transaction, exception);
            } catch (Exception e) {
                log.error("Error in sending transaction failure notification", e);
            }
        }
    } catch (Exception e) {
        log.error("Failed to set failed transaction id " + id + " to E", e);
        throw ExceptionHelper.throwAFR(e);
    } finally {
        if (uow != null) {
            uow.rollback();
        }
    }
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) UOW(org.jaffa.persistence.UOW) DomainObjectChangedException(org.jaffa.exceptions.DomainObjectChangedException) FrameworkException(org.jaffa.exceptions.FrameworkException) MessagingException(javax.mail.MessagingException) ApplicationException(org.jaffa.exceptions.ApplicationException) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException)

Example 18 with Transaction

use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.

the class TransactionEngine method updateTransactionStatusToSatisfied.

/**
 * Retrieves the Transaction and update it's status to S.
 * NOTE: The processing happens within the scope of the input UOW.
 *
 * @param uow The UOW.
 * @param id  the Transaction Id.
 * @throws FrameworkException    Indicates some system error.
 * @throws ApplicationExceptions Indicates application error(s).
 */
public void updateTransactionStatusToSatisfied(UOW uow, String id) throws FrameworkException, ApplicationExceptions {
    try {
        Transaction transaction = getTransaction(uow, id);
        if (transaction == null) {
            log.error("Transaction '" + id + "' not found; cannot update it's status to S");
            throw new DomainObjectNotFoundException(TransactionMeta.getLabelToken());
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Updating Transaction '" + transaction.getId() + "' to status S");
            }
            transaction.setStatus(Transaction.Status.S.toString());
            getTransactionDAO().save(uow, transaction);
        }
    } catch (Exception e) {
        throw ExceptionHelper.throwAFR(e);
    }
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) DomainObjectChangedException(org.jaffa.exceptions.DomainObjectChangedException) FrameworkException(org.jaffa.exceptions.FrameworkException) MessagingException(javax.mail.MessagingException) ApplicationException(org.jaffa.exceptions.ApplicationException) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException)

Example 19 with Transaction

use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.

the class TransactionEngine method updateTransactionStatusToInProcess.

/**
 * Retrieves the Transaction and update it's status to I.
 * This method should only be used during a synchronous transaction as the the entire transaction must be scoped within the same UOW
 * NOTE: The processing happens within the scope of the input UOW.
 *
 * @param uow the input UOW.
 * @param id  the Transaction Id.
 * @throws FrameworkException    Indicates some system error.
 * @throws ApplicationExceptions Indicates application error(s).
 */
public void updateTransactionStatusToInProcess(UOW uow, String id) throws FrameworkException, ApplicationExceptions {
    Transaction transaction = getTransaction(uow, id);
    updateTransactionStatusToInProcess(uow, transaction);
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction)

Example 20 with Transaction

use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.

the class TransactionMessagingEngine method processTransactions.

/**
 * Any internally queued {@link Transaction} needs a corresponding JMS message submitted.
 * Prior versions did this in the postAdd() of the Transaction domain object.
 * <p/>
 * This location is now one of a few places that should be using the JmsClientHelper.send() method.
 * The other place(s) are:
 * - In the drl files for sending messages to topic queues (resources/rules/jaffa/soa/SOAEventService.drl)
 */
private void processTransactions() throws FrameworkException, ApplicationExceptions {
    log.debug("Need to Write JMS for buffered Transactions. BufferSize=" + m_transactions.size());
    // send each transaction to the JmsClientHelper
    for (Transaction transaction : m_transactions.values()) {
        // if the transaction is not defined, skip it
        if (transaction == null) {
            continue;
        }
        // if the direction is not "IN", skip this transaction
        if ((transaction.getDirection() != null) && !Direction.IN.toString().equals(transaction.getDirection())) {
            log.debug("Transaction: " + transaction.getId() + " is not an IN transaction, it will be skipped.");
            continue;
        }
        // if the status is not "O", skip this transaction
        if ((transaction.getStatus() != null) && !Status.O.toString().equals(transaction.getStatus())) {
            log.debug("Transaction: " + transaction.getId() + " is not OPEN, it will be skipped.");
            continue;
        }
        // try to submit the transaction
        try {
            // see if a scheduled ID is defined for this transaction
            String scheduledId = null;
            TransactionField[] transactionFields = transaction.getTransactionFieldArray();
            if (transactionFields != null) {
                for (TransactionField field : transaction.getTransactionFieldArray()) {
                    if ("JaffaTransactionInvokerScheduledTaskId".equals(field.getFieldName())) {
                        scheduledId = field.getValue();
                        break;
                    }
                }
            }
            // send the transaction to the JMS queue to be consumed
            getSender().send(new TransactionMessage(transaction), transaction.getCreatedBy(), scheduledId, null);
        } catch (Exception e) {
            // If there is a failure to put the transaction in the JMS queue, set the transaction to error
            Boolean postImmediate = Parser.parseBoolean((String) ContextManagerFactory.instance().getProperty(Transaction.RULE_POST_IMMEDIATE));
            if (postImmediate == null || !postImmediate.booleanValue()) {
                TransactionEngine.getInstance().updateTransactionStatusToError(transaction.getId(), e);
            }
            // Handle case where an application exception caused the issue
            ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
            if (appExps != null) {
                log.error(MessageHelper.findMessage("exception.org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException.jmsTransactionError", new Object[] { transaction }), appExps);
                TransactionEngine.getInstance().updateTransactionStatusToError(transaction.getId(), appExps);
                throw appExps;
            }
            // If the originating exception is not an application exception log it
            log.error(MessageHelper.findMessage("exception.org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException.jmsTransactionError", new Object[] { transaction }), e);
            // Create a framework exception and rethrow
            FrameworkException frameworkException = new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.JMS_TRANSACTION_ERROR, new Object[] { transaction }, e);
            if (postImmediate == null || !postImmediate.booleanValue()) {
                TransactionEngine.getInstance().updateTransactionStatusToError(transaction.getId(), frameworkException);
            }
            // Throw the framework exception and exit
            throw frameworkException;
        }
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) Transaction(org.jaffa.transaction.domain.Transaction) FrameworkException(org.jaffa.exceptions.FrameworkException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) TransactionField(org.jaffa.transaction.domain.TransactionField) FrameworkException(org.jaffa.exceptions.FrameworkException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException)

Aggregations

Transaction (org.jaffa.transaction.domain.Transaction)31 UOW (org.jaffa.persistence.UOW)19 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)14 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)14 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)13 Criteria (org.jaffa.persistence.Criteria)13 ArrayList (java.util.ArrayList)11 FrameworkException (org.jaffa.exceptions.FrameworkException)10 ApplicationException (org.jaffa.exceptions.ApplicationException)9 HashMap (java.util.HashMap)8 LinkedHashMap (java.util.LinkedHashMap)8 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)8 Map (java.util.Map)7 LinkedList (java.util.LinkedList)5 InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)5 JaffaMessagingFrameworkException (org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException)4 TransactionMessageDAO (org.jaffa.transaction.daos.TransactionMessageDAO)4 List (java.util.List)3 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)3 IllegalPersistentStateRuntimeException (org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException)3