Search in sources :

Example 1 with Transaction

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

the class JaffaTransactionMessageService method getTransactionByFieldsAndBeginsWithFields.

/**
 * Gets the Transaction that has the specified fields-values and also fields that begin with
 * the specified values.  If multiple beginsWith values are defined for a field, the field will be checked against
 * them all.
 *
 * @param fields     the field name/value pairs
 * @param beginsWith the field name/begins-with values
 * @return the Transaction that contains the specified fields with the input values
 * @throws FrameworkException
 */
@Override
public Transaction getTransactionByFieldsAndBeginsWithFields(HashMap<String, String> fields, HashMap<String, String> beginsWith) throws FrameworkException {
    UOW uow = null;
    Transaction transaction = null;
    try {
        uow = new UOW();
        TransactionCriteria transactionCriteria = new TransactionCriteria();
        List<TransactionFieldCriteria> tranFieldCriteriaList = new ArrayList<TransactionFieldCriteria>();
        // add all of the field criteria
        for (Map.Entry<String, String> field : fields.entrySet()) {
            TransactionFieldCriteria fieldCriteria = new TransactionFieldCriteria();
            fieldCriteria.setFieldName(field.getKey());
            StringCriteriaField stringCriteria = StringCriteriaField.getStringCriteriaField(StringCriteriaField.RELATIONAL_EQUALS, field.getValue(), null);
            fieldCriteria.setValue(stringCriteria);
            tranFieldCriteriaList.add(fieldCriteria);
        }
        // add all of the begins with criteria
        for (Map.Entry<String, String> beginsWithField : beginsWith.entrySet()) {
            TransactionFieldCriteria beginsWithCriteria = new TransactionFieldCriteria();
            beginsWithCriteria.setFieldName(beginsWithField.getKey());
            StringCriteriaField stringCriteria = StringCriteriaField.getStringCriteriaField(StringCriteriaField.RELATIONAL_BEGINS_WITH, beginsWithField.getValue(), null);
            beginsWithCriteria.setValue(stringCriteria);
            tranFieldCriteriaList.add(beginsWithCriteria);
        }
        // set all of the field criteria on the transaction criteria
        TransactionFieldCriteria[] criteriaArray = new TransactionFieldCriteria[tranFieldCriteriaList.size()];
        criteriaArray = tranFieldCriteriaList.toArray(criteriaArray);
        transactionCriteria.setTransactionFields(criteriaArray);
        // call the transaction service for a response to the query
        TransactionService transactionService = new TransactionService();
        TransactionQueryResponse response = transactionService.query(transactionCriteria);
        // return a transaction from the response
        for (TransactionGraph transactionGraph : response.getGraphs()) {
            if ((transactionGraph != null) && (transactionGraph.getId() != null)) {
                transaction = getTransaction(transactionGraph.getId());
            }
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return transaction;
}
Also used : TransactionService(org.jaffa.transaction.apis.TransactionService) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) ArrayList(java.util.ArrayList) TransactionQueryResponse(org.jaffa.transaction.apis.data.TransactionQueryResponse) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) Transaction(org.jaffa.transaction.domain.Transaction) TransactionGraph(org.jaffa.transaction.apis.data.TransactionGraph) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringCriteriaField(org.jaffa.components.finder.StringCriteriaField)

Example 2 with Transaction

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

the class JaffaTransactionMessageService method getTransactionsByFields.

/**
 * Gets all Transactions that have the specified fields with the input values.
 * If there are more than one value for a key, this will return fields that have any of the specified values.
 *
 * @param fields the field name/value pairs
 * @return a collection of Transactions that contain the specified fields with the input values
 * @throws FrameworkException
 */
@Override
public Collection<Transaction> getTransactionsByFields(HashMap<String, List<Serializable>> fields) throws FrameworkException {
    UOW uow = null;
    List<Transaction> results = new ArrayList<Transaction>();
    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, List<Serializable>> field : fields.entrySet()) {
            // if there is no field or values defined, skip to the next entry
            if ((field.getKey() == null) || field.getKey().isEmpty() || field.getValue().isEmpty()) {
                continue;
            }
            // if the value list has one entry, create a criteria
            if (field.getValue().size() == 1) {
                Criteria singleValueCriteria = new Criteria();
                singleValueCriteria.setTable(TransactionFieldMeta.getName());
                singleValueCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
                singleValueCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, field.getKey());
                if (field.getValue().get(0) == null) {
                    singleValueCriteria.addCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                } else {
                    singleValueCriteria.addCriteria(TransactionFieldMeta.VALUE, field.getValue().get(0));
                }
                transactionCriteria.addAggregate(singleValueCriteria);
                continue;
            }
            // if the value list has multiple entries, create an atomic criteria for each one
            Criteria multiValueCriteria = new AtomicCriteria();
            multiValueCriteria.setTable(TransactionFieldMeta.getName());
            multiValueCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
            multiValueCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, field.getKey());
            AtomicCriteria ac = new AtomicCriteria();
            for (Object value : field.getValue()) {
                // check if this is the first criteria or an 'or' criteria when adding it
                if (value == null) {
                    if ((ac.getCriteriaEntries() == null) || ac.getCriteriaEntries().isEmpty()) {
                        ac.addCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                    } else {
                        ac.addOrCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                    }
                } else {
                    if ((ac.getCriteriaEntries() == null) || ac.getCriteriaEntries().isEmpty()) {
                        ac.addCriteria(TransactionFieldMeta.VALUE, value);
                    } else {
                        ac.addOrCriteria(TransactionFieldMeta.VALUE, value);
                    }
                }
            }
            multiValueCriteria.addAtomic(ac);
            transactionCriteria.addAggregate(multiValueCriteria);
        }
        for (Object result : uow.query(transactionCriteria)) {
            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) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) 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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with Transaction

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

the class JaffaTransactionMessageService method getTransactionsByTypeSubTypeFieldsOrderBy.

/**
 * Gets an ordered list of Transaction that match the input type, subType and fields.
 * If more than one value is defined for a field, that field will be checked against all values to see if it
 * matched any of them (they will be OR-ed).
 *
 * @param type    the type of Transactions to return
 * @param subType the subType of Transactions to return
 * @param fields  the fields to check the Transaction for, if multiple values are defined for a field, the
 *                field will be checked to see if it matches any of the values (they will be OR-ed)
 * @param orderBy the fields to sort the return list by, each field has a boolean value that determines the
 *                direction.  True for ascending and false for descending.
 * @return an ordered list of Transactions that match the input type, subType and fields
 * @throws FrameworkException
 */
@Override
public List<Transaction> getTransactionsByTypeSubTypeFieldsOrderBy(String type, String subType, HashMap<String, List<String>> fields, LinkedHashMap<String, Boolean> orderBy) throws FrameworkException {
    List<Transaction> results = new ArrayList<Transaction>();
    UOW uow = null;
    try {
        uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(TransactionMeta.getName());
        // query on type and subType
        StringCriteriaField typeField = StringCriteriaField.getStringCriteriaField(CriteriaField.RELATIONAL_EQUALS, type, null);
        StringCriteriaField subTypeField = StringCriteriaField.getStringCriteriaField(CriteriaField.RELATIONAL_EQUALS, subType, null);
        FinderTx.addCriteria(typeField, TransactionMeta.TYPE, c);
        FinderTx.addCriteria(subTypeField, TransactionMeta.SUB_TYPE, c);
        // add the fields
        for (Map.Entry<String, List<String>> entry : fields.entrySet()) {
            Criteria joinCriteria = new Criteria();
            joinCriteria.setTable(TransactionFieldMeta.getName());
            joinCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
            // the key is the field name
            joinCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, entry.getKey());
            // the values are OR-ed together
            AtomicCriteria ac = new AtomicCriteria();
            for (String value : entry.getValue()) {
                if (value == null) {
                    if ((ac.getCriteriaEntries() == null) || ac.getCriteriaEntries().isEmpty()) {
                        ac.addCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                    } else {
                        ac.addOrCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                    }
                } else {
                    if ((ac.getCriteriaEntries() == null) || ac.getCriteriaEntries().isEmpty()) {
                        ac.addCriteria(TransactionFieldMeta.VALUE, value);
                    } else {
                        ac.addOrCriteria(TransactionFieldMeta.VALUE, value);
                    }
                }
            }
            joinCriteria.addAtomic(ac);
            c.addAggregate(joinCriteria);
        }
        // add the orderBy
        for (Map.Entry<String, Boolean> entry : orderBy.entrySet()) {
            int sort = Criteria.ORDER_BY_ASC;
            if (entry.getValue() != null && !entry.getValue()) {
                sort = Criteria.ORDER_BY_DESC;
            }
            c.addOrderBy(entry.getKey(), sort);
        }
        // add the query results to the return list
        for (Object o : uow.query(c)) {
            results.add((Transaction) o);
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return results;
}
Also used : 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) Transaction(org.jaffa.transaction.domain.Transaction) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringCriteriaField(org.jaffa.components.finder.StringCriteriaField)

Example 4 with Transaction

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

the class JaffaTransactionMessageService method getTransactionsByField.

/**
 * Gets all Transactions that have the specified field with the input value.
 *
 * @param fieldName the field to check for the input value
 * @param value     the value to check against the field
 * @return a collection of Transactions that contain the specified field with the input value
 * @throws FrameworkException
 */
@Override
public Collection<Transaction> getTransactionsByField(String fieldName, String value) throws FrameworkException {
    UOW uow = null;
    Collection<Transaction> results = new ArrayList<Transaction>();
    try {
        uow = new UOW();
        // set up a Transaction criteria
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionMeta.getName());
        // join to the TransactionField table
        Criteria joinCriteria = new Criteria();
        joinCriteria.setTable(TransactionFieldMeta.getName());
        joinCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
        joinCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, fieldName);
        // either query for a value or relational null based on the input
        if (value != null) {
            joinCriteria.addCriteria(TransactionFieldMeta.VALUE, value);
        } else {
            joinCriteria.addCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
        }
        criteria.addAggregate(joinCriteria);
        for (Object result : uow.query(criteria)) {
            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) 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 5 with Transaction

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

the class JaffaTransactionMessageService method getTransactionCountPerStatusByType.

/**
 * Gets the count per status of all open Transaction with the input type
 *
 * @param type the type to filter on
 * @return the count of all open Transaction with the input type
 * @throws FrameworkException
 */
@Override
public TransactionStatusCount getTransactionCountPerStatusByType(String type) throws FrameworkException {
    UOW uow = null;
    TransactionStatusCount result = new TransactionStatusCount();
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionMeta.getName());
        criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
        criteria.addCriteria(TransactionMeta.TYPE, type);
        criteria.addGroupBy(TransactionMeta.STATUS, TransactionMeta.STATUS);
        long openCount = 0L, successCount = 0L, errorCount = 0L, holdCount = 0L, inProcessCount = 0L, interruptedCount = 0L;
        for (Object queryResult : uow.query(criteria)) {
            if (!(queryResult instanceof Map)) {
                continue;
            }
            Map row = (Map) queryResult;
            String status = (String) row.get(TransactionMeta.STATUS);
            if (status != null) {
                Transaction.Status enumeratedStatus = Transaction.Status.valueOf(status);
                Number count = (Number) row.get(Criteria.ID_FUNCTION_COUNT);
                switch(enumeratedStatus) {
                    case O:
                        openCount += count.longValue();
                        break;
                    case S:
                        successCount += count.longValue();
                        break;
                    case E:
                        errorCount += count.longValue();
                        break;
                    case H:
                        holdCount += count.longValue();
                        break;
                    case I:
                        inProcessCount += count.longValue();
                        break;
                    case INT:
                        interruptedCount += count.longValue();
                        break;
                }
            }
        }
        result.setOpenCount(openCount);
        result.setSuccessCount(successCount);
        result.setErrorCount(errorCount);
        result.setHoldCount(holdCount);
        result.setInProcessCount(inProcessCount);
        result.setInterruptedCount(interruptedCount);
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return result;
}
Also used : TransactionStatusCount(org.jaffa.transaction.domain.TransactionStatusCount) 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)

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