Search in sources :

Example 1 with PropertyFilter

use of org.jaffa.qm.util.PropertyFilter 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 PropertyFilter

use of org.jaffa.qm.util.PropertyFilter in project jaffa-framework by jaffa-projects.

the class JmsQueueAdmin method queueQuery.

public QueueQueryResponse queueQuery(QueueCriteria criteria) {
    if (log.isDebugEnabled())
        log.debug("Input to queueQuery: " + criteria);
    QueueQueryResponse output = new QueueQueryResponse();
    try {
        // Match the queueSystemId as well apply checks for unsupported criteria
        if (FinderTx.match(QUEUE_SYSTEM_ID, criteria.getQueueSystemId()) && FinderTx.match(null, criteria.getSuccessCount()) && FinderTx.match(null, criteria.getHoldCount()) && FinderTx.match(null, criteria.getInterruptedCount())) {
            String[] queueNames = JmsBrowser.getAccessibleQueueNames();
            if (queueNames != null && queueNames.length > 0) {
                PropertyFilter pf = PropertyFilter.getInstance(QueueGraph.class, criteria.getResultGraphRules());
                Collection<QueueGraph> graphs = new LinkedList<QueueGraph>();
                for (String queueName : queueNames) {
                    if (FinderTx.match(queueName, criteria.getType())) {
                        QueueGraph graph = new QueueGraph();
                        // Compute message count only if required by criteria or if it is included in the property-filter
                        if (criteria.getOpenCount() != null || pf.isFieldIncluded("openCount")) {
                            Message[] messages = JmsBrowser.getPendingMessages(queueName);
                            Long count = messages != null ? messages.length : 0L;
                            if (!FinderTx.match(count, criteria.getOpenCount()))
                                continue;
                            if (pf.isFieldIncluded("openCount"))
                                graph.setOpenCount(count);
                        }
                        // Apply the status criteria
                        if (criteria.getStatus() != null || pf.isFieldIncluded("status")) {
                            QueueGraph.Status status;
                            QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName);
                            if (queueInfo != null && queueInfo.getConsumerPolicy() != ConsumerPolicy.NONE)
                                status = QueueGraph.Status.ACTIVE;
                            else
                                status = QueueGraph.Status.ACTIVE;
                            if (!FinderTx.match(status.toString(), criteria.getStatus()))
                                continue;
                            if (pf.isFieldIncluded("status"))
                                graph.setStatus(status);
                        }
                        // Stamp the remaining properties, if included in the property-filter
                        graph.setQueueMetaData(createQueueMetaData(queueName, pf));
                        if (pf.isFieldIncluded("type"))
                            graph.setType(queueName);
                        if (pf.isFieldIncluded("hasAdminAccess"))
                            graph.setHasAdminAccess(JmsBrowser.hasAdminMessageAccess(queueName));
                        graphs.add(graph);
                    }
                }
                if (graphs.size() > 0)
                    output.setGraphs(graphs.toArray(new QueueGraph[graphs.size()]));
            }
        }
    } catch (Exception e) {
        // add errors to the response
        ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
        if (appExps != null) {
            if (log.isDebugEnabled())
                log.debug("Error in queueQuery execution", appExps);
            output.setErrors(ServiceError.generate(appExps));
        } else {
            log.error("Internal Error in queueQuery execution", e);
            output.setErrors(ServiceError.generate(e));
        }
    }
    if (log.isDebugEnabled())
        log.debug("Output from queueQuery: " + output);
    return output;
}
Also used : QueueInfo(org.jaffa.modules.messaging.services.configdomain.QueueInfo) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueQueryResponse(org.jaffa.qm.apis.data.QueueQueryResponse) LinkedList(java.util.LinkedList) JMSException(javax.jms.JMSException) IntrospectionException(java.beans.IntrospectionException) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) PropertyFilter(org.jaffa.qm.util.PropertyFilter)

Example 3 with PropertyFilter

use of org.jaffa.qm.util.PropertyFilter in project jaffa-framework by jaffa-projects.

the class TransactionAdmin method queueQuery.

public QueueQueryResponse queueQuery(QueueCriteria criteria) {
    if (log.isDebugEnabled()) {
        log.debug("Input to queueQuery: " + criteria);
    }
    QueueQueryResponse output = new QueueQueryResponse();
    try {
        // Match the queueSystemId
        if (FinderTx.match(QUEUE_SYSTEM_ID, criteria.getQueueSystemId())) {
            String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
            if (types != null && types.length > 0) {
                PropertyFilter pf = PropertyFilter.getInstance(QueueGraph.class, criteria.getResultGraphRules());
                Collection<QueueGraph> graphs = new LinkedList<QueueGraph>();
                Map<String, TransactionStatusCount> statusCountMap = transactionDAO.getTransactionCountPerStatusForTypes(types);
                for (String type : types) {
                    if (FinderTx.match(type, criteria.getType())) {
                        QueueGraph graph = new QueueGraph();
                        TransactionStatusCount statusCount = statusCountMap.get(type);
                        // Compute message count only if required by criteria or if it is included in the property-filter
                        if ((statusCount != null) && (criteria.getOpenCount() != null || pf.isFieldIncluded("openCount") || criteria.getSuccessCount() != null || pf.isFieldIncluded("successCount") || criteria.getErrorCount() != null || pf.isFieldIncluded("errorCount") || criteria.getHoldCount() != null || pf.isFieldIncluded("holdCount") || criteria.getInProcessCount() != null || pf.isFieldIncluded("inProcessCount") || criteria.getInterruptedCount() != null || pf.isFieldIncluded("interruptedCount") || pf.isFieldIncluded("lastErroredOn"))) {
                            Long openCount = statusCount.getOpenCount();
                            Long successCount = statusCount.getSuccessCount();
                            Long errorCount = statusCount.getErrorCount();
                            Long holdCount = statusCount.getHoldCount();
                            Long inProcessCount = statusCount.getInProcessCount();
                            Long interruptedCount = statusCount.getInterruptedCount();
                            if (pf.isFieldIncluded("lastErroredOn") && statusCount.getTotalCount() > 0L) {
                                graph.setLastErroredOn(transactionDAO.getLastErrorTimeByType(type));
                            }
                            if (!FinderTx.match(openCount, criteria.getOpenCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("openCount")) {
                                graph.setOpenCount(openCount);
                            }
                            if (!FinderTx.match(successCount, criteria.getSuccessCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("successCount")) {
                                graph.setSuccessCount(successCount);
                            }
                            if (!FinderTx.match(errorCount, criteria.getErrorCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("errorCount")) {
                                graph.setErrorCount(errorCount);
                            }
                            if (!FinderTx.match(holdCount, criteria.getHoldCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("holdCount")) {
                                graph.setHoldCount(holdCount);
                            }
                            if (!FinderTx.match(inProcessCount, criteria.getInProcessCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("inProcessCount")) {
                                graph.setInProcessCount(inProcessCount);
                            }
                            if (!FinderTx.match(interruptedCount, criteria.getInterruptedCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("interruptedCount")) {
                                graph.setInterruptedCount(interruptedCount);
                            }
                        }
                        // Apply the status criteria
                        if (criteria.getStatus() != null || pf.isFieldIncluded("status")) {
                            QueueGraph.Status status = QueueGraph.Status.ACTIVE;
                            if (!FinderTx.match(status.toString(), criteria.getStatus())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("status")) {
                                graph.setStatus(status);
                            }
                        }
                        // Stamp the remaining properties, if included in the property-filter
                        graph.setQueueMetaData(createQueueMetaData(type, pf));
                        if (pf.isFieldIncluded("type")) {
                            graph.setType(type);
                        }
                        if (pf.isFieldIncluded("hasAdminAccess")) {
                            graph.setHasAdminAccess(TransactionEngine.getInstance().hasAdminAccess(type));
                        }
                        graphs.add(graph);
                    }
                }
                if (graphs.size() > 0) {
                    output.setGraphs(graphs.toArray(new QueueGraph[graphs.size()]));
                }
            }
        }
    } catch (Exception e) {
        // add errors to the response
        ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
        if (appExps != null) {
            if (log.isDebugEnabled()) {
                log.debug("Error in queueQuery execution", appExps);
            }
            output.setErrors(ServiceError.generate(appExps));
        } else {
            log.error("Internal Error in queueQuery execution", e);
            output.setErrors(ServiceError.generate(e));
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Output from queueQuery: " + output);
    }
    return output;
}
Also used : TransactionStatusCount(org.jaffa.transaction.domain.TransactionStatusCount) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) QueueQueryResponse(org.jaffa.qm.apis.data.QueueQueryResponse) 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) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) PropertyFilter(org.jaffa.qm.util.PropertyFilter)

Example 4 with PropertyFilter

use of org.jaffa.qm.util.PropertyFilter 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

LinkedList (java.util.LinkedList)4 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)4 PropertyFilter (org.jaffa.qm.util.PropertyFilter)4 IntrospectionException (java.beans.IntrospectionException)2 JMSException (javax.jms.JMSException)2 Message (javax.jms.Message)2 TextMessage (javax.jms.TextMessage)2 ApplicationException (org.jaffa.exceptions.ApplicationException)2 FrameworkException (org.jaffa.exceptions.FrameworkException)2 JaffaMessagingFrameworkException (org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException)2 IllegalPersistentStateRuntimeException (org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException)2 PostLoadFailedException (org.jaffa.persistence.exceptions.PostLoadFailedException)2 QueryFailedException (org.jaffa.persistence.exceptions.QueryFailedException)2 MessageGraph (org.jaffa.qm.apis.data.MessageGraph)2 MessageQueryResponse (org.jaffa.qm.apis.data.MessageQueryResponse)2 QueueGraph (org.jaffa.qm.apis.data.QueueGraph)2 QueueQueryResponse (org.jaffa.qm.apis.data.QueueQueryResponse)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1