Search in sources :

Example 1 with Param

use of org.jaffa.transaction.services.configdomain.Param 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 2 with Param

use of org.jaffa.transaction.services.configdomain.Param in project jaffa-framework by jaffa-projects.

the class LockingService method checkOrDeleteLockingTransactions.

/**
 * Browses all Transactions looking for the locks, as specified in the transaction-configuration for the input dataBean.
 * Calls any specified lock-check filter class if one has been defined
 * Throws an ApplicationException, if any matching Transaction is found, and if the input argument 'deleteLockingTransaction' is false.
 * Deletes all matching Transactions, if the input argument 'deleteLockingTransaction' is true.
 *
 * @param uow                      The UOW.
 * @param dataBean                 Any serializable object.
 * @param transactionInfo          the corresponding TransactionInfo object, as specified in the configuration file.
 * @param deleteLockingTransaction determines if the matching Transactions are to be deleted.
 * @throws FrameworkException    Indicates some system error.
 * @throws ApplicationExceptions Indicates application error(s).
 */
private static void checkOrDeleteLockingTransactions(UOW uow, Object dataBean, TransactionInfo transactionInfo, boolean deleteLockingTransaction, String transactionId) throws FrameworkException, ApplicationExceptions {
    // Check if lock checks exists for the message
    if (transactionInfo.getLockCheck() != null) {
        Filter filterConfig = transactionInfo.getLockCheck().getFilter();
        // Load the appropriate class
        if (filterConfig != null) {
            try {
                Class<ILockCheckFilter> filterClass = (Class<ILockCheckFilter>) Class.forName(filterConfig.getClassName());
                TransactionMessageService transactionService = TransactionMessageDAOFactory.getTransactionMessageService();
                Collection<Transaction> transactions = filterClass.newInstance().getFilteredResults(dataBean, transactionService);
                deleteLockCheck(uow, transactions, deleteLockingTransaction, transactionId);
            } catch (Exception e) {
                throw ExceptionHelper.throwAFR(e);
            }
        // load the load check parameters directly from the message config
        } else if (transactionInfo.getLockCheck().getParam() != null) {
            TransactionMessageDAO transactionDAO = TransactionMessageDAOFactory.getTransactionMessageDAO();
            // Run this logic for each Param
            for (Param param : transactionInfo.getLockCheck().getParam()) {
                String value = TransactionEngine.obtainParamValue(param, dataBean);
                Collection<Transaction> transactions = transactionDAO.getTransactionsByField(param.getName(), value);
                deleteLockCheck(uow, transactions, deleteLockingTransaction, transactionId);
            }
        }
    }
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) Filter(org.jaffa.transaction.services.configdomain.Filter) TransactionMessageDAO(org.jaffa.transaction.daos.TransactionMessageDAO) Param(org.jaffa.transaction.services.configdomain.Param) Collection(java.util.Collection) TransactionMessageService(org.jaffa.transaction.daos.TransactionMessageService) FrameworkException(org.jaffa.exceptions.FrameworkException) ApplicationException(org.jaffa.exceptions.ApplicationException)

Example 3 with Param

use of org.jaffa.transaction.services.configdomain.Param in project jaffa-framework by jaffa-projects.

the class LoggingService method setLoggingContext.

/**
 * Adds the appropriate elements to the Message Driven Context (MDC) of Log4J, as specified in the input transaction config.
 * @param payload Any serializable object.
 * @param transactionInfo the corresponding TransactionInfo object, as specified in the configuration file.
 */
public static void setLoggingContext(Object payload, TransactionInfo transactionInfo, Transaction transaction) {
    // Push the current MDC context into the thread-level stack
    Map<String, Object> currentLoggingContext = MDC.getContext() != null ? new HashMap<String, Object>(MDC.getContext()) : new HashMap<String, Object>();
    Stack<Map<String, Object>> stack = t_loggingContext.get();
    if (stack == null) {
        stack = new Stack<Map<String, Object>>();
        t_loggingContext.set(stack);
    }
    stack.push(currentLoggingContext);
    // If not passed, determine the transactionInfo based on the payload
    if (transactionInfo == null && payload != null)
        transactionInfo = ConfigurationService.getInstance().getTransactionInfo(payload);
    // Add elements to the MDC, based on the presence of loggingNames in the header information of the transaction configuration
    if (transactionInfo != null && transactionInfo.getHeader() != null && transactionInfo.getHeader().getParam() != null) {
        for (Param param : transactionInfo.getHeader().getParam()) {
            if (param.getLoggingName() != null) {
                String key = param.getLoggingName().value();
                try {
                    Object value = TransactionEngine.obtainParamValue(param, payload);
                    if (value != null)
                        MDC.put(key, value);
                    else
                        MDC.remove(key);
                } catch (Exception e) {
                    if (log.isDebugEnabled())
                        log.debug("Error in obtaining value for the LoggingName " + key, e);
                }
            }
        }
    }
    // Add some standard elements to the MDC
    if (MDC.get(BusinessEventLogMeta.CORRELATION_TYPE) == null && transaction != null && transaction.getId() != null) {
        MDC.put(BusinessEventLogMeta.CORRELATION_TYPE, DEFAULT_CORRELATION_TYPE);
        MDC.put(BusinessEventLogMeta.CORRELATION_KEY1, transaction.getId());
        if (transaction.getType() != null)
            MDC.put(BusinessEventLogMeta.CORRELATION_KEY2, transaction.getType());
        if (transaction.getSubType() != null)
            MDC.put(BusinessEventLogMeta.CORRELATION_KEY3, transaction.getSubType());
        if (transaction.getCreatedBy() != null)
            MDC.put(BusinessEventLogMeta.LOGGED_BY, transaction.getCreatedBy());
    }
    // Add transactionId as the message id
    if (transaction != null && transaction.getId() != null)
        MDC.put(BusinessEventLogMeta.MESSAGE_ID, transaction.getId());
    try {
        // Add in scheduledTaskId to MDC if it has been passed in as TransactionField
        if (transaction.getTransactionFieldArray() != null) {
            for (TransactionField tField : transaction.getTransactionFieldArray()) {
                if ("JaffaTransactionInvokerScheduledTaskId".equals(tField.getFieldName()))
                    MDC.put(BusinessEventLogMeta.SCHEDULED_TASK_ID, tField.getValue());
            }
        }
    } catch (Exception e) {
        if (log.isDebugEnabled())
            log.debug("Unable to fetch transaction field array from transaction", e);
    }
}
Also used : Param(org.jaffa.transaction.services.configdomain.Param) TransactionField(org.jaffa.transaction.domain.TransactionField) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Param (org.jaffa.transaction.services.configdomain.Param)3 TransactionField (org.jaffa.transaction.domain.TransactionField)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 TransactionMessageDAO (org.jaffa.transaction.daos.TransactionMessageDAO)1 TransactionMessageService (org.jaffa.transaction.daos.TransactionMessageService)1 Transaction (org.jaffa.transaction.domain.Transaction)1 Filter (org.jaffa.transaction.services.configdomain.Filter)1 TransactionInfo (org.jaffa.transaction.services.configdomain.TransactionInfo)1