Search in sources :

Example 1 with GraphComparator

use of org.jaffa.soa.graph.GraphComparator in project jaffa-framework by jaffa-projects.

the class JmsQueueAdmin 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.getSubType()) && FinderTx.match(null, criteria.getDirection()) && FinderTx.match(null, criteria.getLastChangedOn()) && FinderTx.match(null, criteria.getLastChangedBy())) {
            String[] queueNames = JmsBrowser.getAccessibleQueueNames();
            if (queueNames != null && queueNames.length > 0) {
                String jmsFilter = createJmsFilter(criteria);
                PropertyFilter pf = PropertyFilter.getInstance(MessageGraph.class, criteria.getResultGraphRules());
                Collection<MessageGraph> graphs = new LinkedList<MessageGraph>();
                for (String queueName : queueNames) {
                    if (FinderTx.match(queueName, criteria.getType())) {
                        // Retrieve messages for each requested status
                        for (MessageGraph.Status status : SUPPORTED_MESSAGE_STATUS) {
                            if (FinderTx.match(status.toString(), criteria.getStatus())) {
                                Message[] messages = null;
                                if (status == MessageGraph.Status.OPEN)
                                    messages = JmsBrowser.getPendingMessages(queueName, jmsFilter);
                                if (messages != null) {
                                    for (Message message : messages) {
                                        MessageGraph graph = createMessageGraph(message, queueName, pf);
                                        if (pf.isFieldIncluded("status"))
                                            graph.setStatus(status);
                                        graphs.add(graph);
                                    }
                                }
                            }
                        }
                    }
                }
                if (graphs.size() > 0) {
                    output.setGraphs(graphs.toArray(new MessageGraph[graphs.size()]));
                    if (criteria.getOrderByFields() != null && criteria.getOrderByFields().length > 0)
                        Arrays.sort(output.getGraphs(), new GraphComparator(criteria.getOrderByFields()));
                    handlePaging(output, criteria);
                }
            }
        }
    } 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) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageQueryResponse(org.jaffa.qm.apis.data.MessageQueryResponse) LinkedList(java.util.LinkedList) JMSException(javax.jms.JMSException) IntrospectionException(java.beans.IntrospectionException) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) GraphComparator(org.jaffa.soa.graph.GraphComparator) PropertyFilter(org.jaffa.qm.util.PropertyFilter)

Example 2 with GraphComparator

use of org.jaffa.soa.graph.GraphComparator in project jaffa-framework by jaffa-projects.

the class QueueManager method queueQuery.

// TODO-SWAT add script events here
public QueueQueryResponse queueQuery(QueueCriteria criteria) {
    try {
        if (log.isDebugEnabled())
            log.debug("Input to queueQuery: " + criteria);
        QueueQueryResponse aggregateResponse = new QueueQueryResponse();
        IQueueAdmin[] implementations = findImplementations();
        if (implementations != null && implementations.length > 0) {
            for (IQueueAdmin implementation : implementations) {
                QueueQueryResponse response = implementation.queueQuery(criteria);
                if (response != null && response.getErrors() != null && response.getErrors().length > 0) {
                    aggregateResponse.setErrors(response.getErrors());
                    break;
                } else if (response != null && response.getGraphs() != null && response.getGraphs().length > 0) {
                    aggregateResponse.setGraphs(concatenate(aggregateResponse.getGraphs(), response.getGraphs()));
                }
            }
            if (aggregateResponse.getErrors() == null && aggregateResponse.getGraphs() != null && aggregateResponse.getGraphs().length > 0 && criteria.getOrderByFields() != null && criteria.getOrderByFields().length > 0)
                Arrays.sort(aggregateResponse.getGraphs(), new GraphComparator(criteria.getOrderByFields()));
            handlePaging(aggregateResponse, criteria);
        }
        if (aggregateResponse.getGraphs() == null)
            aggregateResponse.setGraphs(new QueueGraph[0]);
        if (log.isDebugEnabled())
            log.debug("Response from queueQuery: " + aggregateResponse);
        return aggregateResponse;
    } catch (Exception e) {
        log.error("Error in obtaining IQueueAdmin implementations", e);
        return new QueueQueryResponse(null, ServiceError.generate(e));
    }
}
Also used : QueueQueryResponse(org.jaffa.qm.apis.data.QueueQueryResponse) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) GraphComparator(org.jaffa.soa.graph.GraphComparator)

Aggregations

GraphComparator (org.jaffa.soa.graph.GraphComparator)2 IntrospectionException (java.beans.IntrospectionException)1 LinkedList (java.util.LinkedList)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 TextMessage (javax.jms.TextMessage)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 MessageGraph (org.jaffa.qm.apis.data.MessageGraph)1 MessageQueryResponse (org.jaffa.qm.apis.data.MessageQueryResponse)1 QueueGraph (org.jaffa.qm.apis.data.QueueGraph)1 QueueQueryResponse (org.jaffa.qm.apis.data.QueueQueryResponse)1 PropertyFilter (org.jaffa.qm.util.PropertyFilter)1