Search in sources :

Example 1 with TransactionFieldCriteria

use of org.jaffa.transaction.apis.data.TransactionFieldCriteria in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getCountOpenInProgress.

/**
 * Gets the count of all Transactions with the specified field-value that are in the Open or InProgress state.
 *
 * @param field the field to check the value of
 * @param value the input value of the field we are looking for
 * @return the count of all Transactions with the specified field-value that are in the Open or InProgress state
 * @throws FrameworkException
 */
@Override
public long getCountOpenInProgress(String field, String value) throws FrameworkException {
    UOW uow = null;
    long transactionCount = 0;
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionMeta.getName());
        AtomicCriteria ac0 = new AtomicCriteria();
        ac0.addCriteria(TransactionMeta.STATUS, Transaction.Status.O.toString());
        ac0.addOrCriteria(TransactionMeta.STATUS, Transaction.Status.I.toString());
        criteria.addAtomic(ac0);
        Criteria transactionFieldCriteria = new Criteria();
        transactionFieldCriteria.setTable(TransactionFieldMeta.getName());
        transactionFieldCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
        criteria.addAggregate(transactionFieldCriteria);
        AtomicCriteria ac = new AtomicCriteria();
        ac.addCriteria(TransactionFieldMeta.FIELD_NAME, field);
        ac.addCriteria(TransactionFieldMeta.VALUE, value);
        transactionFieldCriteria.addAtomic(ac);
        // return the count, or zero
        for (Object result : uow.query(criteria)) {
            if (!(result instanceof Transaction)) {
                continue;
            }
            transactionCount++;
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return transactionCount;
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) 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 2 with TransactionFieldCriteria

use of org.jaffa.transaction.apis.data.TransactionFieldCriteria 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 3 with TransactionFieldCriteria

use of org.jaffa.transaction.apis.data.TransactionFieldCriteria in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getTransactionsByFieldsOred.

/**
 * Gets all Transactions that have any of 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 that a Transaction must have at least one of to ne returned
 * @return a collection of Transactions that contain the specified fields with the input values
 * @throws FrameworkException
 */
@Override
public Collection<Transaction> getTransactionsByFieldsOred(HashMap<String, 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());
        Criteria transactionFieldCriteria = new Criteria();
        transactionFieldCriteria.setTable(TransactionFieldMeta.getName());
        transactionFieldCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
        transactionCriteria.addAggregate(transactionFieldCriteria);
        AtomicCriteria ac = new AtomicCriteria();
        // add each field in the field map to the query
        AtomicCriteria firstCriteria = null;
        for (Map.Entry<String, Serializable> field : fields.entrySet()) {
            // if there is no field defined, skip to the next entry
            if ((field.getKey() == null) || field.getKey().isEmpty()) {
                continue;
            }
            AtomicCriteria ac1 = new AtomicCriteria();
            ac1.addCriteria(TransactionFieldMeta.FIELD_NAME, field.getKey());
            if (field.getValue() == null) {
                ac1.addCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
            } else {
                ac1.addCriteria(TransactionFieldMeta.VALUE, field.getValue());
            }
            if (firstCriteria != null) {
                firstCriteria.addOrAtomic(ac1);
            } else {
                firstCriteria = ac1;
                ac.addAtomic(firstCriteria);
            }
        }
        transactionFieldCriteria.addAtomic(ac);
        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 : Serializable(java.io.Serializable) 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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

UOW (org.jaffa.persistence.UOW)3 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)3 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)3 Transaction (org.jaffa.transaction.domain.Transaction)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)2 Criteria (org.jaffa.persistence.Criteria)2 Serializable (java.io.Serializable)1 StringCriteriaField (org.jaffa.components.finder.StringCriteriaField)1 TransactionService (org.jaffa.transaction.apis.TransactionService)1 TransactionGraph (org.jaffa.transaction.apis.data.TransactionGraph)1 TransactionQueryResponse (org.jaffa.transaction.apis.data.TransactionQueryResponse)1