Search in sources :

Example 1 with TransactionField

use of org.jaffa.transaction.domain.TransactionField in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getTransactionField.

/**
 * Gets the TransactionField with the input Transaction ID and field name.
 *
 * @param transactionId the ID of the Transaction the TransactionField is part of
 * @param fieldName     the field name of the TransactionField to return
 * @return the TransactionField with the input Transaction ID and field name
 * @throws FrameworkException
 */
@Override
public TransactionField getTransactionField(String transactionId, String fieldName) throws FrameworkException {
    UOW uow = null;
    TransactionField field = null;
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionFieldMeta.getName());
        criteria.addCriteria(TransactionFieldMeta.TRANSACTION_ID, transactionId);
        criteria.addCriteria(TransactionFieldMeta.FIELD_NAME, fieldName);
        for (Object result : uow.query(criteria)) {
            if (result instanceof TransactionField) {
                field = (TransactionField) result;
                break;
            }
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return field;
}
Also used : TransactionField(org.jaffa.transaction.domain.TransactionField) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW)

Example 2 with TransactionField

use of org.jaffa.transaction.domain.TransactionField in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getFieldByNameValue.

/**
 * Get a TansactionField given its name and value.
 *
 * @param fieldName  the name of the field to return
 * @param fieldValue the value of the field to return
 * @return the TransactionField with the input fieldName and value
 * @throws FrameworkException
 */
@Override
public TransactionField getFieldByNameValue(String fieldName, String fieldValue) throws FrameworkException {
    UOW uow = null;
    TransactionField transactionField = null;
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionFieldMeta.getName());
        AtomicCriteria ac = new AtomicCriteria();
        ac.addCriteria(TransactionFieldMeta.FIELD_NAME, fieldName);
        criteria.addAtomic(ac);
        criteria.addCriteria(TransactionFieldMeta.VALUE, fieldValue);
        for (Object result : uow.query(criteria)) {
            if (!(result instanceof TransactionField)) {
                continue;
            }
            transactionField = (TransactionField) result;
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return transactionField;
}
Also used : TransactionField(org.jaffa.transaction.domain.TransactionField) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW)

Example 3 with TransactionField

use of org.jaffa.transaction.domain.TransactionField in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method createTransactionFields.

/**
 * Create an array of {@link org.jaffa.transaction.domain.TransactionField} based on the fields of the {@link org
 * .jaffa.transaction.domain.Transaction}
 *
 * @param transaction the transaction to create fields for
 * @param dataBean    the internal object of the transaction payload
 * @return an array of {@link org.jaffa.transaction.domain.TransactionField}
 * @throws FrameworkException
 * @throws ApplicationExceptions
 */
private Collection<TransactionField> createTransactionFields(Transaction transaction, Object dataBean) throws FrameworkException, ValidationException, ApplicationExceptions {
    Collection<TransactionField> transactionFields = new LinkedList<TransactionField>();
    // Create a TransactionField object for each header element as defined in the configuration file
    final TransactionInfo transactionInfo = transaction.getTransactionInfo();
    if ((transactionInfo.getHeader() != null) && (transactionInfo.getHeader().getParam() != null)) {
        for (Param param : transactionInfo.getHeader().getParam()) {
            // get the value of the header parameter
            String value = TransactionEngine.obtainParamValue(param, dataBean);
            // create a transaction field and set its ID
            TransactionField transactionField = new TransactionField();
            transactionField.setTransactionId(transaction.getId());
            // set the name and value of the transaction field, then add it to the list of all transaction fields
            transactionField.setFieldName(param.getName());
            transactionField.setValue(value);
            transactionFields.add(transactionField);
        }
    }
    return transactionFields;
}
Also used : Param(org.jaffa.transaction.services.configdomain.Param) TransactionInfo(org.jaffa.transaction.services.configdomain.TransactionInfo) TransactionField(org.jaffa.transaction.domain.TransactionField) LinkedList(java.util.LinkedList)

Example 4 with TransactionField

use of org.jaffa.transaction.domain.TransactionField 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)

Example 5 with TransactionField

use of org.jaffa.transaction.domain.TransactionField in project jaffa-framework by jaffa-projects.

the class TransactionAdmin method invokeHandler.

/**
 * Invokes the intended handler. This Handler must implement the IMessageHandler Interface in order to be invoked.
 *
 * @param uow
 * @param transaction
 * @param methodName
 * @throws JaffaMessagingFrameworkException
 */
private static void invokeHandler(UOW uow, Transaction transaction, String methodName) throws Exception {
    try {
        TransactionPayload tp = transaction.getTransactionPayloadObject();
        Object dataBean = tp != null ? tp.moldInternalPayload() : null;
        if (dataBean != null) {
            // Load transaction configuration
            TransactionInfo transactionInfo = ConfigurationService.getInstance().getTransactionInfo(tp.getInternalMessageClass());
            if (transactionInfo == null) {
                throw new JaffaMessagingFrameworkException(JaffaTransactionFrameworkException.TRANSACTION_INFO_MISSING, new Object[] { tp.getInternalMessageClass() });
            }
            // Obtain the handlerClass
            if (transactionInfo.getToClass() == null || transactionInfo.getToClass().length() == 0) {
                if (log.isDebugEnabled()) {
                    log.debug(methodName + " toClass is not defined in data bean configuration: " + transactionInfo.getDataBean());
                }
                return;
            }
            Class handlerClass = Class.forName(transactionInfo.getToClass());
            // Class dataBeanClass = Class.forName(transactionInfo.getDataBean());
            if (IMessageHandler.class.isAssignableFrom(handlerClass)) {
                // Unmarshals the Message payload into a dataBean using the dataBeanClassName
                Method handlerMethod = null;
                Object handlerObject = null;
                // Obtain the handler method
                try {
                    handlerMethod = handlerClass.getMethod(methodName, new Class[] { UOW.class, Map.class, Object.class });
                } catch (NoSuchMethodException e) {
                    // Hence use the dataBeanClass specified in the messageInfo to get the appropriate handlerMethod
                    if (log.isDebugEnabled()) {
                        log.debug(methodName + " method not found in " + handlerClass.getName());
                    }
                    return;
                }
                handlerObject = handlerClass.newInstance();
                Map<String, String> headerMap = new HashMap<String, String>();
                // Sets the transactionField elements as defined in the configuration file.
                TransactionField[] fields = transaction.getTransactionFieldArray();
                if (fields != null) {
                    for (TransactionField field : fields) {
                        headerMap.put(field.getFieldName(), field.getValue());
                    }
                }
                // Invoke the handler
                if (log.isDebugEnabled()) {
                    log.debug("Invoking the handler " + handlerMethod);
                }
                handlerMethod.invoke(handlerObject, new Object[] { uow, headerMap, dataBean });
            }
        }
    } catch (Exception e) {
        // Just log the error
        log.error("Exception thrown while deleting the transaction. Transaction was: " + transaction, e);
        throw e;
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) TransactionField(org.jaffa.transaction.domain.TransactionField) Method(java.lang.reflect.Method) IllegalPersistentStateRuntimeException(org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) PostLoadFailedException(org.jaffa.persistence.exceptions.PostLoadFailedException) FrameworkException(org.jaffa.exceptions.FrameworkException) QueryFailedException(org.jaffa.persistence.exceptions.QueryFailedException) ApplicationException(org.jaffa.exceptions.ApplicationException) TransactionInfo(org.jaffa.transaction.services.configdomain.TransactionInfo) TransactionPayload(org.jaffa.transaction.domain.TransactionPayload) UOW(org.jaffa.persistence.UOW) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TransactionField (org.jaffa.transaction.domain.TransactionField)9 UOW (org.jaffa.persistence.UOW)5 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)3 Criteria (org.jaffa.persistence.Criteria)3 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)3 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)3 TransactionInfo (org.jaffa.transaction.services.configdomain.TransactionInfo)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 FrameworkException (org.jaffa.exceptions.FrameworkException)2 JaffaMessagingFrameworkException (org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException)2 Transaction (org.jaffa.transaction.domain.Transaction)2 Param (org.jaffa.transaction.services.configdomain.Param)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 IllegalPersistentStateRuntimeException (org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException)1