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