use of org.jaffa.transaction.apis.data.TransactionGraph 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;
}
Aggregations