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