Search in sources :

Example 1 with TransactionDependency

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

the class JaffaTransactionMessageService method getDependenciesByDependsOnId.

/**
 * Gets all TransactionDependencies in any state that depend on the Transaction with the input ID.
 *
 * @param transactionId the ID of the Transaction
 * @return all TransactionDependencies in any state that depend on the Transaction with the input ID
 * @throws FrameworkException
 */
@Override
public Collection<TransactionDependency> getDependenciesByDependsOnId(String transactionId) throws FrameworkException {
    UOW uow = null;
    List<TransactionDependency> results = new ArrayList<TransactionDependency>();
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionDependencyMeta.getName());
        criteria.addCriteria(TransactionDependencyMeta.DEPENDS_ON_ID, transactionId);
        for (Object result : uow.query(criteria)) {
            results.add((TransactionDependency) result);
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) 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) TransactionDependency(org.jaffa.transaction.domain.TransactionDependency)

Example 2 with TransactionDependency

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

the class JaffaTransactionMessageService method getOpenDependenciesByDependsOnId.

/**
 * Gets all TransactionDependencies in the open state that depend on the Transaction with the input ID.
 *
 * @param transactionId the ID of the Transaction
 * @return all TransactionDependencies in the open state that depend on the Transaction with the input ID
 * @throws FrameworkException
 */
@Override
public Collection<TransactionDependency> getOpenDependenciesByDependsOnId(String transactionId) throws FrameworkException {
    UOW uow = null;
    List<TransactionDependency> results = new ArrayList<TransactionDependency>();
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionDependencyMeta.getName());
        criteria.addCriteria(TransactionDependencyMeta.DEPENDS_ON_ID, transactionId);
        criteria.addCriteria(TransactionDependencyMeta.STATUS, TransactionDependency.Status.O.toString());
        for (Object result : uow.query(criteria)) {
            results.add((TransactionDependency) result);
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) 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) TransactionDependency(org.jaffa.transaction.domain.TransactionDependency)

Example 3 with TransactionDependency

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

the class JaffaTransactionMessageService method getTransactionDependency.

/**
 * Gets a TransactionDependency with the input transaction ID and depends on ID
 *
 * @param transactionId the ID of the Transaction the dependency is for
 * @param dependsOnId   the ID of the Transaction that is being depended on
 * @return the TransactionDependency with the input transaction ID and depends on ID
 * @throws FrameworkException
 */
@Override
public TransactionDependency getTransactionDependency(String transactionId, String dependsOnId) throws FrameworkException {
    UOW uow = null;
    TransactionDependency dependency = null;
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionDependencyMeta.getName());
        criteria.addCriteria(TransactionDependencyMeta.TRANSACTION_ID, transactionId);
        criteria.addCriteria(TransactionDependencyMeta.DEPENDS_ON_ID, dependsOnId);
        for (Object result : uow.query(criteria)) {
            if (result instanceof TransactionDependency) {
                dependency = (TransactionDependency) result;
            }
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return dependency;
}
Also used : 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) TransactionDependency(org.jaffa.transaction.domain.TransactionDependency)

Example 4 with TransactionDependency

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

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

the class TransactionDependencySweeper method updateTransactionDependency.

/**
 * Updates missed Transaction Dependency records
 * @param tdsv
 * @param databean
 */
private void updateTransactionDependency(TransactionDependencySweeperView tdsv, TransactionDependencySweeper databean) {
    UOW innerUow = null;
    try {
        innerUow = new UOW();
        TransactionDependency transactionDependency = TransactionDependency.findByPK(innerUow, tdsv.getTransactionId(), tdsv.getDependsOnId());
        if (transactionDependency == null) {
            log.info("TransactionDependency '" + tdsv.getTransactionId() + "/" + tdsv.getDependsOnId() + "' not found; cannot update it's status to S");
            throw new DomainObjectNotFoundException(TransactionDependencyMeta.getLabelToken());
        } else {
            transactionDependency.setStatus(TransactionDependency.Status.S.toString());
            transactionMessageDAO.save(innerUow, transactionDependency);
            innerUow.commit();
        }
    } catch (Exception e) {
        // Write to business event log
        // Sets Log4J's MDC to enable BusinessEventLogging
        MDC.put(BusinessEventLogMeta.SCHEDULED_TASK_ID, databean.getScheduleTaskId());
        MDC.put(BusinessEventLogMeta.LOGGED_BY, databean.getLoggedBy());
        log.error("Exception thrown during update of Transaction Dependency record" + e);
    } finally {
        if (innerUow != null) {
            try {
                innerUow.rollback();
            } catch (Exception e) {
                log.error("Unable to rollback inner UOW in updating Transaction Dependency");
            }
        }
    }
}
Also used : DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) UOW(org.jaffa.persistence.UOW) TransactionDependency(org.jaffa.transaction.domain.TransactionDependency) FrameworkException(org.jaffa.exceptions.FrameworkException) ApplicationException(org.jaffa.exceptions.ApplicationException) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException)

Aggregations

TransactionDependency (org.jaffa.transaction.domain.TransactionDependency)7 UOW (org.jaffa.persistence.UOW)5 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)4 Criteria (org.jaffa.persistence.Criteria)4 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)4 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 MessageDependency (org.jaffa.qm.apis.data.MessageDependency)1 MessageField (org.jaffa.qm.apis.data.MessageField)1 MessageGraph (org.jaffa.qm.apis.data.MessageGraph)1 TransactionMessageDAO (org.jaffa.transaction.daos.TransactionMessageDAO)1 TransactionField (org.jaffa.transaction.domain.TransactionField)1 DisplayParam (org.jaffa.transaction.services.configdomain.DisplayParam)1 TypeInfo (org.jaffa.transaction.services.configdomain.TypeInfo)1