Search in sources :

Example 1 with TransactionStatusCount

use of org.jaffa.transaction.domain.TransactionStatusCount in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getTransactionCountPerStatusByType.

/**
 * Gets the count per status of all open Transaction with the input type
 *
 * @param type the type to filter on
 * @return the count of all open Transaction with the input type
 * @throws FrameworkException
 */
@Override
public TransactionStatusCount getTransactionCountPerStatusByType(String type) throws FrameworkException {
    UOW uow = null;
    TransactionStatusCount result = new TransactionStatusCount();
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionMeta.getName());
        criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
        criteria.addCriteria(TransactionMeta.TYPE, type);
        criteria.addGroupBy(TransactionMeta.STATUS, TransactionMeta.STATUS);
        long openCount = 0L, successCount = 0L, errorCount = 0L, holdCount = 0L, inProcessCount = 0L, interruptedCount = 0L;
        for (Object queryResult : uow.query(criteria)) {
            if (!(queryResult instanceof Map)) {
                continue;
            }
            Map row = (Map) queryResult;
            String status = (String) row.get(TransactionMeta.STATUS);
            if (status != null) {
                Transaction.Status enumeratedStatus = Transaction.Status.valueOf(status);
                Number count = (Number) row.get(Criteria.ID_FUNCTION_COUNT);
                switch(enumeratedStatus) {
                    case O:
                        openCount += count.longValue();
                        break;
                    case S:
                        successCount += count.longValue();
                        break;
                    case E:
                        errorCount += count.longValue();
                        break;
                    case H:
                        holdCount += count.longValue();
                        break;
                    case I:
                        inProcessCount += count.longValue();
                        break;
                    case INT:
                        interruptedCount += count.longValue();
                        break;
                }
            }
        }
        result.setOpenCount(openCount);
        result.setSuccessCount(successCount);
        result.setErrorCount(errorCount);
        result.setHoldCount(holdCount);
        result.setInProcessCount(inProcessCount);
        result.setInterruptedCount(interruptedCount);
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return result;
}
Also used : TransactionStatusCount(org.jaffa.transaction.domain.TransactionStatusCount) Transaction(org.jaffa.transaction.domain.Transaction) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with TransactionStatusCount

use of org.jaffa.transaction.domain.TransactionStatusCount 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)

Aggregations

TransactionStatusCount (org.jaffa.transaction.domain.TransactionStatusCount)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)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 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)1 Criteria (org.jaffa.persistence.Criteria)1 UOW (org.jaffa.persistence.UOW)1 IllegalPersistentStateRuntimeException (org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException)1 PostLoadFailedException (org.jaffa.persistence.exceptions.PostLoadFailedException)1 QueryFailedException (org.jaffa.persistence.exceptions.QueryFailedException)1 QueueGraph (org.jaffa.qm.apis.data.QueueGraph)1 QueueQueryResponse (org.jaffa.qm.apis.data.QueueQueryResponse)1 PropertyFilter (org.jaffa.qm.util.PropertyFilter)1 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)1 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)1