Search in sources :

Example 1 with MessageFieldCriteria

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;
}
Also used : MessageFieldCriteria(org.jaffa.qm.apis.data.MessageFieldCriteria)

Example 2 with MessageFieldCriteria

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;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) MessageQueryResponse(org.jaffa.qm.apis.data.MessageQueryResponse) LinkedList(java.util.LinkedList) IllegalPersistentStateRuntimeException(org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) PostLoadFailedException(org.jaffa.persistence.exceptions.PostLoadFailedException) FrameworkException(org.jaffa.exceptions.FrameworkException) QueryFailedException(org.jaffa.persistence.exceptions.QueryFailedException) ApplicationException(org.jaffa.exceptions.ApplicationException) MessageFieldCriteria(org.jaffa.qm.apis.data.MessageFieldCriteria) Transaction(org.jaffa.transaction.domain.Transaction) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) PropertyFilter(org.jaffa.qm.util.PropertyFilter) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

MessageFieldCriteria (org.jaffa.qm.apis.data.MessageFieldCriteria)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 JaffaMessagingFrameworkException (org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException)1 IllegalPersistentStateRuntimeException (org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException)1 PostLoadFailedException (org.jaffa.persistence.exceptions.PostLoadFailedException)1 QueryFailedException (org.jaffa.persistence.exceptions.QueryFailedException)1 MessageGraph (org.jaffa.qm.apis.data.MessageGraph)1 MessageQueryResponse (org.jaffa.qm.apis.data.MessageQueryResponse)1 PropertyFilter (org.jaffa.qm.util.PropertyFilter)1 Transaction (org.jaffa.transaction.domain.Transaction)1