Search in sources :

Example 1 with MessageField

use of org.jaffa.qm.apis.data.MessageField in project jaffa-framework by jaffa-projects.

the class JmsQueueAdmin method createMessageGraph.

/**
 * Molds the input JMS Message into a MessageGraph.
 */
private static MessageGraph createMessageGraph(Message message, String queueName, PropertyFilter pf) throws JMSException, IntrospectionException {
    MessageGraph graph = new MessageGraph();
    graph.setQueueMetaData(createQueueMetaData(queueName, pf));
    if (pf.isFieldIncluded("type"))
        graph.setType(queueName);
    if (pf.isFieldIncluded("messageId"))
        graph.setMessageId(message.getJMSMessageID());
    if (pf.isFieldIncluded("priority"))
        graph.setPriority(new Long(message.getJMSPriority()));
    if (pf.isFieldIncluded("createdOn"))
        graph.setCreatedOn(message.getJMSTimestamp() != 0 ? new DateTime(message.getJMSTimestamp()) : null);
    if (pf.isFieldIncluded("createdBy"))
        graph.setCreatedBy(message.getStringProperty(JmsBrowser.HEADER_USER_ID));
    if (pf.isFieldIncluded("errorMessage"))
        graph.setErrorMessage(message.getStringProperty(JmsBrowser.HEADER_ERROR_DETAILS));
    if (pf.isFieldIncluded("payload") && message instanceof TextMessage)
        graph.setPayload(((TextMessage) message).getText());
    if (pf.isFieldIncluded("hasAdminAccess"))
        graph.setHasAdminAccess(JmsBrowser.hasAdminMessageAccess(queueName));
    if (pf.isFieldIncluded("applicationFields") || pf.isFieldIncluded("technicalFields")) {
        // Generate a Map of header elements, keyed by the name of each header element
        // Names beginning with JMS and jaffa_ will be treated as techincal, while the rest will be assumed to be application-specific
        Map<String, MessageField> applicationFields = new LinkedHashMap<String, MessageField>();
        Map<String, MessageField> technicalFields = new TreeMap<String, MessageField>();
        for (Enumeration e = message.getPropertyNames(); e.hasMoreElements(); ) {
            String name = (String) e.nextElement();
            String value = Formatter.format(message.getObjectProperty(name));
            MessageField messageField = new MessageField();
            messageField.setName(name);
            messageField.setValue(value);
            if (name.startsWith("JMS") || name.startsWith("jaffa_"))
                technicalFields.put(name, messageField);
            else
                applicationFields.put(name, messageField);
        }
        // Treat all the JMS* properties of the Message as technical
        if (pf.isFieldIncluded("technicalFields")) {
            BeanInfo beanInfo = Introspector.getBeanInfo(Message.class);
            if (beanInfo != null) {
                PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
                if (pds != null) {
                    for (PropertyDescriptor pd : pds) {
                        if (pd.getReadMethod() != null && !pd.getPropertyType().isArray()) {
                            String name = pd.getName();
                            try {
                                Object value = pd.getReadMethod().invoke(message);
                                MessageField messageField = new MessageField();
                                messageField.setName(name);
                                messageField.setValue(Formatter.format(value));
                                technicalFields.put(name, messageField);
                            } catch (Exception e) {
                                if (log.isDebugEnabled())
                                    log.debug("Exception thrown while reading Message property: " + name, e);
                            }
                        }
                    }
                }
            }
            if (!technicalFields.isEmpty())
                graph.setTechnicalFields(technicalFields.values().toArray(new MessageField[technicalFields.size()]));
        }
        // Add labels to the application-fields from the configuration-file
        if (pf.isFieldIncluded("applicationFields")) {
            QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName);
            if (queueInfo != null && queueInfo.getDisplayParam() != null) {
                for (DisplayParam displayParam : queueInfo.getDisplayParam()) {
                    if (displayParam.getLabel() != null && applicationFields.containsKey(displayParam.getName()))
                        applicationFields.get(displayParam.getName()).setLabel(MessageHelper.replaceTokens(displayParam.getLabel()));
                }
            }
            if (!applicationFields.isEmpty())
                graph.setApplicationFields(applicationFields.values().toArray(new MessageField[applicationFields.size()]));
        }
    }
    return graph;
}
Also used : QueueInfo(org.jaffa.modules.messaging.services.configdomain.QueueInfo) Enumeration(java.util.Enumeration) PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) TreeMap(java.util.TreeMap) DateTime(org.jaffa.datatypes.DateTime) MessageField(org.jaffa.qm.apis.data.MessageField) JMSException(javax.jms.JMSException) IntrospectionException(java.beans.IntrospectionException) LinkedHashMap(java.util.LinkedHashMap) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) DisplayParam(org.jaffa.modules.messaging.services.configdomain.DisplayParam) TextMessage(javax.jms.TextMessage)

Example 2 with MessageField

use of org.jaffa.qm.apis.data.MessageField in project jaffa-framework by jaffa-projects.

the class TransactionAdmin method createMessageGraph.

/**
 * Molds the input Transaction into a MessageGraph.
 */
private static MessageGraph createMessageGraph(Transaction transaction, PropertyFilter pf) throws FrameworkException {
    MessageGraph graph = new MessageGraph();
    graph.setQueueMetaData(createQueueMetaData(transaction.getSubType(), pf));
    if (pf.isFieldIncluded("type")) {
        graph.setType(transaction.getType());
    }
    if (pf.isFieldIncluded("subType")) {
        graph.setSubType(transaction.getSubType());
    }
    if (pf.isFieldIncluded("messageId")) {
        graph.setMessageId(transaction.getId());
    }
    if (pf.isFieldIncluded("direction")) {
        graph.setDirection(transaction.getDirection());
    }
    if (pf.isFieldIncluded("status")) {
        graph.setStatus(transactionToMessageStatus(transaction.getStatus()));
    }
    if (pf.isFieldIncluded("createdOn")) {
        graph.setCreatedOn(transaction.getCreatedOn());
    }
    if (pf.isFieldIncluded("createdBy")) {
        graph.setCreatedBy(transaction.getCreatedBy());
    }
    if (pf.isFieldIncluded("lastChangedOn")) {
        graph.setLastChangedOn(transaction.getLastChangedOn());
    }
    if (pf.isFieldIncluded("lastChangedBy")) {
        graph.setLastChangedBy(transaction.getLastChangedBy());
    }
    if (pf.isFieldIncluded("errorMessage")) {
        graph.setErrorMessage(transaction.getErrorMessage());
    }
    if (pf.isFieldIncluded("payload")) {
        graph.setPayload(transaction.getTransactionPayloadObject() != null ? transaction.getTransactionPayloadObject().returnInternalPayload() : null);
    }
    if (pf.isFieldIncluded("hasAdminAccess")) {
        graph.setHasAdminAccess(TransactionEngine.getInstance().hasAdminAccess(transaction.getType()));
    }
    if (pf.isFieldIncluded("applicationFields")) {
        Map<String, MessageField> applicationFields = new LinkedHashMap<String, MessageField>();
        TransactionField[] transactionFields = transaction.getTransactionFieldArray();
        if (transactionFields != null && transactionFields.length > 0) {
            for (int i = 0; i < transactionFields.length; i++) {
                TransactionField transactionField = transactionFields[i];
                MessageField applicationField = new MessageField();
                applicationField.setName(transactionField.getFieldName());
                applicationField.setValue(transactionField.getValue());
                applicationFields.put(applicationField.getName(), applicationField);
            }
        }
        // Add labels to the application-fields from the configuration-file
        TypeInfo typeInfo = ConfigurationService.getInstance().getTypeInfo(transaction.getType());
        if (typeInfo != null && typeInfo.getDisplayParam() != null) {
            for (DisplayParam displayParam : typeInfo.getDisplayParam()) {
                if (displayParam.getLabel() != null && applicationFields.containsKey(displayParam.getName())) {
                    applicationFields.get(displayParam.getName()).setLabel(MessageHelper.replaceTokens(displayParam.getLabel()));
                }
            }
        }
        if (!applicationFields.isEmpty()) {
            graph.setApplicationFields(applicationFields.values().toArray(new MessageField[applicationFields.size()]));
        }
    }
    if (pf.isFieldIncluded("messageDependencies")) {
        TransactionDependency[] transactionDependencies = transaction.getTransactionDependencyArray();
        if (transactionDependencies != null && transactionDependencies.length > 0) {
            MessageDependency[] messageDependencies = new MessageDependency[transactionDependencies.length];
            for (int i = 0; i < transactionDependencies.length; i++) {
                TransactionDependency transactionDependency = transactionDependencies[i];
                MessageDependency messageDependency = new MessageDependency();
                messageDependency.setDependsOnId(transactionDependency.getDependsOnId());
                if (transactionDependency.getStatus() != null) {
                    MessageDependency.Status messageDependencyStatus = null;
                    TransactionDependency.Status transactionDependencyStatus = TransactionDependency.Status.valueOf(transactionDependency.getStatus());
                    switch(transactionDependencyStatus) {
                        case O:
                            messageDependencyStatus = MessageDependency.Status.OPEN;
                            break;
                        case S:
                            messageDependencyStatus = MessageDependency.Status.SUCCESS;
                            break;
                    }
                    messageDependency.setStatus(messageDependencyStatus);
                }
                messageDependencies[i] = messageDependency;
            }
            graph.setMessageDependencies(messageDependencies);
        }
    }
    return graph;
}
Also used : MessageDependency(org.jaffa.qm.apis.data.MessageDependency) TransactionField(org.jaffa.transaction.domain.TransactionField) TypeInfo(org.jaffa.transaction.services.configdomain.TypeInfo) MessageField(org.jaffa.qm.apis.data.MessageField) LinkedHashMap(java.util.LinkedHashMap) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) DisplayParam(org.jaffa.transaction.services.configdomain.DisplayParam) TransactionDependency(org.jaffa.transaction.domain.TransactionDependency)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2 MessageField (org.jaffa.qm.apis.data.MessageField)2 MessageGraph (org.jaffa.qm.apis.data.MessageGraph)2 BeanInfo (java.beans.BeanInfo)1 IntrospectionException (java.beans.IntrospectionException)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 Enumeration (java.util.Enumeration)1 TreeMap (java.util.TreeMap)1 JMSException (javax.jms.JMSException)1 TextMessage (javax.jms.TextMessage)1 DateTime (org.jaffa.datatypes.DateTime)1 DisplayParam (org.jaffa.modules.messaging.services.configdomain.DisplayParam)1 QueueInfo (org.jaffa.modules.messaging.services.configdomain.QueueInfo)1 MessageDependency (org.jaffa.qm.apis.data.MessageDependency)1 TransactionDependency (org.jaffa.transaction.domain.TransactionDependency)1 TransactionField (org.jaffa.transaction.domain.TransactionField)1 DisplayParam (org.jaffa.transaction.services.configdomain.DisplayParam)1 TypeInfo (org.jaffa.transaction.services.configdomain.TypeInfo)1