use of org.jaffa.qm.apis.data.MessageGraph in project jaffa-framework by jaffa-projects.
the class TransactionAdmin method deleteMessage.
// ///////////////////////////////// Add in intercept for delete
/**
* NOTE: Each graph is expected to contain messageId. It may also contain the optional queueMetaData.queueSystemId and type, which may help optimize the process.
*/
public MessageAdminResponse[] deleteMessage(MessageGraph[] graphs) {
if (log.isDebugEnabled()) {
log.debug("Input to deleteMessage: " + Arrays.toString(graphs));
}
Collection<MessageAdminResponse> output = null;
String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
Arrays.sort(types);
for (MessageGraph graph : graphs) {
if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
if (graph.getType() == null || (types != null && Arrays.binarySearch(types, graph.getType()) >= 0)) {
UOW uow = null;
try {
String graphType = graph.getType();
String messageId = graph.getMessageId();
if (graphType != null && !TransactionEngine.getInstance().hasAdminAccess(graphType)) {
throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { graphType }));
}
uow = new UOW();
Transaction transaction = transactionDAO.getTransaction(messageId);
if (!TransactionEngine.getInstance().hasAdminAccess(transaction.getType())) {
throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { transaction.getType() }));
}
if (transaction != null) {
// Invoke Message Handler class to perform onDelete process
invokeHandler(uow, transaction, "onDelete");
if (log.isDebugEnabled()) {
log.debug("Deleting message " + messageId);
}
transactionDAO.delete(uow, transaction);
uow.commit();
} else {
if (log.isDebugEnabled()) {
log.debug("Delete cannot be performed since message " + messageId + " not found");
}
}
} catch (Exception e) {
MessageAdminResponse response = new MessageAdminResponse();
response.setSource(graph);
ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
if (appExps != null) {
if (log.isDebugEnabled()) {
log.debug("Error while deleting Message " + graph, appExps);
}
response.setErrors(ServiceError.generate(appExps));
} else {
log.error("Internal Error while deleting Message " + graph, e);
response.setErrors(ServiceError.generate(e));
}
if (output == null) {
output = new LinkedList<MessageAdminResponse>();
}
output.add(response);
} finally {
if (uow != null) {
try {
uow.rollback();
} catch (Exception ignore) {
}
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Message " + graph + " will not be deleted by this implementation, since the queue does not belong to this implementation");
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Message " + graph + " will not be deleted by this implementation, since the input queueSystemId does not match this system");
}
}
}
if (log.isDebugEnabled()) {
log.debug("Output from deleteMessage: " + output);
}
return output != null && output.size() > 0 ? output.toArray(new MessageAdminResponse[output.size()]) : null;
}
use of org.jaffa.qm.apis.data.MessageGraph in project jaffa-framework by jaffa-projects.
the class JmsQueueAdmin method resubmitMessage.
/**
* NOTE: Each graph is expected to contain type, messageId and status. It may also contain the optional queueMetaData.queueSystemId, which may help optimize the process.
*/
public MessageAdminResponse[] resubmitMessage(MessageGraph[] graphs) {
if (log.isDebugEnabled())
log.debug("Input to resubmitMessage: " + Arrays.toString(graphs));
Collection<MessageAdminResponse> output = null;
String[] queueNames = null;
for (MessageGraph graph : graphs) {
if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
// Initialize and sort the queueNames array; if not already done
if (queueNames == null) {
queueNames = ConfigurationService.getInstance().getQueueNames();
Arrays.sort(queueNames);
}
if (Arrays.binarySearch(queueNames, graph.getType()) >= 0) {
try {
if (graph.getStatus() == MessageGraph.Status.ERROR) {
if (log.isDebugEnabled())
log.debug("Resubmitting ERROR message " + graph.getMessageId());
JmsBrowser.resubmitMessage(graph.getType(), graph.getMessageId());
} else {
if (log.isDebugEnabled())
log.debug("Message cannnot be resubmitted since unsupported status " + graph.getStatus() + " has been passed");
}
} catch (Exception e) {
MessageAdminResponse response = new MessageAdminResponse();
response.setSource(graph);
ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
if (appExps != null) {
if (log.isDebugEnabled())
log.debug("Error while resubmitting Message " + graph, appExps);
response.setErrors(ServiceError.generate(appExps));
} else {
log.error("Internal Error while resubmitting Message " + graph, e);
response.setErrors(ServiceError.generate(e));
}
if (output == null)
output = new LinkedList<MessageAdminResponse>();
output.add(response);
}
} else {
if (log.isDebugEnabled())
log.debug("Message " + graph + " will not be resubmitted by this implementation, since the queue does not belong to this implementation");
}
} else {
if (log.isDebugEnabled())
log.debug("Message " + graph + " will not be resubmitted by this implementation, since the input queueSystemId does not match this system");
}
}
if (log.isDebugEnabled())
log.debug("Output from resubmitMessage: " + output);
return output != null && output.size() > 0 ? output.toArray(new MessageAdminResponse[output.size()]) : null;
}
use of org.jaffa.qm.apis.data.MessageGraph in project jaffa-framework by jaffa-projects.
the class QueueManager method messageQuery.
public MessageQueryResponse messageQuery(MessageCriteria criteria) throws ApplicationExceptions {
try {
if (log.isDebugEnabled())
log.debug("Input to messageQuery: " + criteria);
MessageQueryResponse aggregateResponse = new MessageQueryResponse();
IQueueAdmin[] implementations = findImplementations();
// Find which implementation of queue admin can be used to query messages for supplied queue
IQueueAdmin queryImplementation = null;
boolean foundMultiple = false;
if (implementations != null && implementations.length > 0) {
for (IQueueAdmin implementation : implementations) {
QueueCriteria queueCriteria = new QueueCriteria();
queueCriteria.setType(criteria.getType());
queueCriteria.setQueueSystemId(criteria.getQueueSystemId());
QueueQueryResponse queueResponse = implementation.queueQuery(queueCriteria);
if (queueResponse != null && queueResponse.getGraphs() != null && queueResponse.getGraphs().length == 1) {
if (queryImplementation != null)
foundMultiple = true;
queryImplementation = implementation;
} else if (queueResponse.getGraphs() != null && queueResponse.getGraphs().length > 1) {
foundMultiple = true;
}
}
}
if (foundMultiple) {
log.error("Found multiple IQueueAdmin implementations for message query");
throw new ApplicationExceptions(new QueueAdminException(QueueAdminException.MULTIPLE_QUEUES));
}
// Use correct queue admin to retrieve messages. Admin class should perform sorting and paging.
if (queryImplementation != null) {
MessageQueryResponse response = queryImplementation.messageQuery(criteria);
if (response != null && response.getErrors() != null && response.getErrors().length > 0) {
aggregateResponse.setErrors(response.getErrors());
} else if (response != null && response.getGraphs() != null && response.getGraphs().length > 0) {
aggregateResponse.setGraphs(concatenate(aggregateResponse.getGraphs(), response.getGraphs()));
}
if (response.getTotalRecords() != null && response.getTotalRecords() > 0)
aggregateResponse.setTotalRecords(response.getTotalRecords());
}
if (aggregateResponse.getGraphs() == null)
aggregateResponse.setGraphs(new MessageGraph[0]);
if (log.isDebugEnabled())
log.debug("Response from messageQuery: " + aggregateResponse);
return aggregateResponse;
} catch (Exception e) {
log.error("Error in obtaining IQueueAdmin implementations", e);
return new MessageQueryResponse(null, ServiceError.generate(e));
}
}
use of org.jaffa.qm.apis.data.MessageGraph 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