use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class TransactionAdmin method messageQuery.
public MessageQueryResponse messageQuery(MessageCriteria criteria) {
if (log.isDebugEnabled()) {
log.debug("Input to messageQuery: " + criteria);
}
MessageQueryResponse output = new MessageQueryResponse();
try {
// Match the queueSystemId as well apply checks for unsupported criteria
if (FinderTx.match(QUEUE_SYSTEM_ID, criteria.getQueueSystemId()) && FinderTx.match(null, criteria.getPriority())) {
PropertyFilter pf = PropertyFilter.getInstance(MessageGraph.class, criteria.getResultGraphRules());
Collection<MessageGraph> graphs = new LinkedList<MessageGraph>();
String type = getMessageCriteriaType(criteria);
String subType = getMessageCriteriaSubType(criteria);
// we will be getting an ordered list
LinkedHashMap<String, Boolean> orderBy = getOrderByFields(criteria);
// the fields the transactions must have
HashMap<String, List<String>> fields = new HashMap<String, List<String>>();
if (criteria.getApplicationFields() != null) {
for (MessageFieldCriteria messageFieldCriteria : criteria.getApplicationFields()) {
List<String> fieldValues = getFieldCriteriaValues(messageFieldCriteria);
fields.put(messageFieldCriteria.getName(), fieldValues);
}
}
// get an ordered list of all transactions of the specified type and subType
List<Transaction> allTransactions = new ArrayList<Transaction>();
allTransactions.addAll(transactionDAO.getTransactionsByTypeSubTypeFieldsOrderBy(type, subType, fields, orderBy));
// filter the list down based on other criteria
List<Transaction> filteredTransactions = new ArrayList<Transaction>();
filteredTransactions.addAll(allTransactions);
for (Transaction transaction : allTransactions) {
if (doesTransactionFailFilterCheck(transaction, criteria)) {
filteredTransactions.remove(transaction);
}
}
// now we have a filtered and ordered list of Transactions, check if we only want a page of the results
int firstIndex = criteria.getObjectStart() == null ? 0 : criteria.getObjectStart();
int resultsCount = criteria.getObjectLimit() == null ? 0 : criteria.getObjectLimit();
int lastIndex = firstIndex + resultsCount;
if (lastIndex > filteredTransactions.size()) {
lastIndex = filteredTransactions.size();
}
List<Transaction> filteredPagedTransactions = new ArrayList<Transaction>();
if ((lastIndex > firstIndex) && ((firstIndex > 0) || (lastIndex > 0))) {
filteredPagedTransactions.addAll(filteredTransactions.subList(firstIndex, lastIndex));
} else {
filteredPagedTransactions.addAll(filteredTransactions);
}
// create a graph from the filtered and paged list of transactions
for (Transaction transaction : filteredPagedTransactions) {
MessageGraph graph = createMessageGraph(transaction, pf);
graphs.add(graph);
}
if (graphs.size() > 0) {
output.setGraphs(graphs.toArray(new MessageGraph[graphs.size()]));
}
// set the total count of rows being output
int rowsCount = graphs.size();
if ((firstIndex > 0) || (resultsCount > 0)) {
if ((firstIndex <= 0) && (rowsCount < resultsCount)) {
output.setTotalRecords(rowsCount);
} else {
output.setTotalRecords(filteredTransactions.size());
}
} else {
output.setTotalRecords(rowsCount);
}
}
} catch (Exception e) {
// add errors to the response
ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
if (appExps != null) {
if (log.isDebugEnabled()) {
log.debug("Error in messageQuery execution", appExps);
}
output.setErrors(ServiceError.generate(appExps));
} else {
log.error("Internal Error in messageQuery execution", e);
output.setErrors(ServiceError.generate(e));
}
}
if (log.isDebugEnabled()) {
log.debug("Output from messageQuery: " + output);
}
return output;
}
Aggregations