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;
}
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;
}
Aggregations