use of org.jaffa.qm.apis.data.MessageFieldCriteria in project jaffa-framework by jaffa-projects.
the class JmsQueueAdmin method createJmsFilter.
/**
* Build a criteria string from messageId, priority, createdOn, createdBy, errorMessage and applicationFields, which can be used as a JMS filter.
*/
private static String createJmsFilter(MessageCriteria criteria) {
StringBuilder sql = new StringBuilder();
addCriteria(criteria.getMessageId(), JmsBrowser.HEADER_JMS_MESSAGE_ID, sql);
addCriteria(criteria.getPriority(), "JMSPriority", sql);
addCriteria(criteria.getCreatedOn(), "JMSTimestamp", sql);
addCriteria(criteria.getCreatedBy(), JmsBrowser.HEADER_USER_ID, sql);
addCriteria(criteria.getErrorMessage(), JmsBrowser.HEADER_ERROR_DETAILS, sql);
if (criteria.getApplicationFields() != null) {
for (MessageFieldCriteria messageFieldCriteria : criteria.getApplicationFields()) addCriteria(messageFieldCriteria.getValue(), messageFieldCriteria.getName(), sql);
}
if (log.isDebugEnabled() && sql.length() > 0)
log.debug("Created JmsFilter: " + sql);
return sql.length() > 0 ? sql.toString() : null;
}
use of org.jaffa.qm.apis.data.MessageFieldCriteria 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