Search in sources :

Example 21 with Transaction

use of org.jaffa.transaction.domain.Transaction 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 22 with Transaction

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

the class JaffaTransactionMessageService method getTransactionByFields.

/**
 * Gets the Transaction that has the specified fields with the input values.
 *
 * @param fields the field name/value pairs
 * @return the Transaction that contains the specified fields with the input values
 * @throws FrameworkException
 */
@Override
public Transaction getTransactionByFields(HashMap<String, String> fields) throws FrameworkException {
    UOW uow = null;
    Transaction transaction = null;
    try {
        uow = new UOW();
        Criteria transactionCriteria = new Criteria();
        transactionCriteria.setTable(TransactionMeta.getName());
        // add each field in the field map to the query
        for (Map.Entry<String, String> field : fields.entrySet()) {
            if ((field.getKey() == null) || field.getKey().isEmpty()) {
                continue;
            }
            Criteria fieldCriteria = new Criteria();
            fieldCriteria.setTable(TransactionFieldMeta.getName());
            fieldCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
            fieldCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, field.getKey());
            fieldCriteria.addCriteria(TransactionFieldMeta.VALUE, field.getValue());
            transactionCriteria.addAggregate(fieldCriteria);
        }
        for (Object result : uow.query(transactionCriteria)) {
            if (!(result instanceof Transaction)) {
                continue;
            }
            transaction = (Transaction) result;
            break;
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return transaction;
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 23 with Transaction

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

the class JaffaTransactionMessageService method filterSetOfTxIdsToOpenOrInProgress.

/**
 * Takes the input list of Transaction IDs and filters it down to the Transactions that are either in
 * the Open or InProgress state.  The filtered list is returned.
 *
 * @param transactionIds the list of all Transaction IDs to check the status of
 * @return Transaction IDs of the input list that are in the Open or InProgress state
 * @throws FrameworkException
 */
@Override
public List<String> filterSetOfTxIdsToOpenOrInProgress(List<String> transactionIds) throws FrameworkException {
    UOW uow = null;
    List<String> results = new ArrayList<String>();
    try {
        uow = new UOW();
        AtomicCriteria ac = new AtomicCriteria();
        for (String transactionId : transactionIds) {
            ac.addOrCriteria(TransactionMeta.ID, transactionId);
        }
        AtomicCriteria ac1 = new AtomicCriteria();
        ac1.addCriteria(TransactionMeta.STATUS, Transaction.Status.O.toString());
        ac1.addOrCriteria(TransactionMeta.STATUS, Transaction.Status.I.toString());
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionMeta.getName());
        criteria.addAtomic(ac);
        criteria.addAtomic(ac1);
        for (Object result : uow.query(criteria)) {
            if (!(result instanceof Transaction)) {
                continue;
            }
            results.add(((Transaction) result).getId());
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return results;
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) ArrayList(java.util.ArrayList) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW)

Example 24 with Transaction

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

the class JaffaTransactionMessageService method getOpenInProgressLastChangedBefore.

/**
 * Gets all Transactions in the open or InProgress state that were last changed before the input time.
 *
 * @param input the time to compare Open and InProgress Transactions lastChangedTime to
 * @return all Transactions in the open or InProgress state that were last changed before the input time
 * @throws FrameworkException
 */
@Override
public Collection<Transaction> getOpenInProgressLastChangedBefore(DateTime input) throws FrameworkException {
    UOW uow = null;
    Collection<Transaction> results = new ArrayList<Transaction>();
    try {
        uow = new UOW();
        // get all transactions in the "O" or "I" state that are older than the configured age limit
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionMeta.getName());
        // status can equal "O" or "I"
        AtomicCriteria statusCriteria = new AtomicCriteria();
        statusCriteria.addCriteria(TransactionMeta.STATUS, Criteria.RELATIONAL_EQUALS, Transaction.Status.O.toString());
        statusCriteria.addOrCriteria(TransactionMeta.STATUS, Criteria.RELATIONAL_EQUALS, Transaction.Status.I.toString());
        // last changed on should be older than (less than) the retryTime
        AtomicCriteria ageCriteria = new AtomicCriteria();
        ageCriteria.addCriteria(TransactionMeta.LAST_CHANGED_ON, Criteria.RELATIONAL_SMALLER_THAN, input);
        // add the two criteria to one query
        criteria.addAtomic(statusCriteria);
        criteria.addAtomic(ageCriteria);
        Collection transactions = uow.query(criteria);
        // create a list of transactions from the results
        for (Object result : transactions) {
            if (!(result instanceof Transaction)) {
                continue;
            }
            results.add((Transaction) result);
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return results;
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW)

Example 25 with Transaction

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

the class JaffaTransactionMessageService method getTransaction.

/**
 * Gets the Transaction with the input ID
 *
 * @param id the ID of the Transaction to get
 * @return the Transaction with the input ID
 * @throws FrameworkException
 */
@Override
public Transaction getTransaction(String id) throws FrameworkException {
    UOW uow = null;
    Transaction transaction = null;
    try {
        uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(TransactionMeta.getName());
        c.addCriteria(TransactionMeta.ID, id);
        Iterator i = uow.query(c).iterator();
        if (i.hasNext()) {
            transaction = (Transaction) i.next();
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return transaction;
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) Iterator(java.util.Iterator) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW)

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