Search in sources :

Example 76 with UOW

use of org.jaffa.persistence.UOW 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)

Example 77 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class TransactionDependencySweeper method updateTransaction.

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

Example 78 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class TaskFinderTx method find.

/**
 * Searches for Task objects.
 * @param taskType taskType of tasks that should be returned.
 * @throws FrameworkException in case any internal error occurs.
 * @throws ApplicationExceptions Indicates application error(s).
 * @return The search results.
 */
public TaskFinderOutDto find(String taskType) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        if (log.isDebugEnabled())
            log.debug("Retrieving all scheduled tasks");
        uow = new UOW();
        SchedulerHelper sh = SchedulerHelperFactory.instance();
        TaskFinderOutDto output = new TaskFinderOutDto();
        output.setSchedulerStatus(sh.getSchedulerStatus());
        if (output.getSchedulerStatus() == SchedulerHelper.SchedulerStatusEnumeration.STOPPED) {
            if (log.isDebugEnabled())
                log.debug("The Scheduler has been shutdown. The Task list cannot be obtained");
        } else {
            Collection<TaskFinderOutRowDto> rows = new LinkedList<TaskFinderOutRowDto>();
            String[] taskTypes = taskType != null ? taskType.split(",") : null;
            if (taskTypes != null) {
                for (String tempTaskType : taskTypes) {
                    populateTaskTypes(uow, tempTaskType, sh, rows);
                }
            } else {
                populateTaskTypes(uow, taskType, sh, rows);
            }
            output.setRows((TaskFinderOutRowDto[]) rows.toArray(new TaskFinderOutRowDto[rows.size()]));
        }
        if (log.isDebugEnabled())
            log.debug("Output: " + output);
        return output;
    } catch (Exception e) {
        throw ExceptionHelper.throwAFR(e);
    } finally {
        if (uow != null)
            uow.rollback();
    }
}
Also used : SchedulerHelper(org.jaffa.modules.scheduler.services.SchedulerHelper) UOW(org.jaffa.persistence.UOW) TaskFinderOutDto(org.jaffa.modules.scheduler.components.taskfinder.dto.TaskFinderOutDto) LinkedList(java.util.LinkedList) FrameworkException(org.jaffa.exceptions.FrameworkException) TaskFinderOutRowDto(org.jaffa.modules.scheduler.components.taskfinder.dto.TaskFinderOutRowDto)

Example 79 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class UserFinderTx method find.

// .//GEN-END:_destroy_2_be
// .//GEN-BEGIN:_find_1_be
/**
 * Searches for User objects.
 * @param input The criteria based on which the search will be performed.
 * @throws ApplicationExceptions This will be thrown if the criteria contains invalid data.
 * @throws FrameworkException Indicates some system error
 * @return The search results.
 */
public UserFinderOutDto find(UserFinderInDto input) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        // Print Debug Information for the input
        if (log.isDebugEnabled()) {
            log.debug("Input: " + input);
        }
        // create the UOW
        uow = new UOW();
        // Build the Criteria Object
        Criteria criteria = buildCriteria(input, uow);
        // .//GEN-END:_find_1_be
        // Add custom code before the query //GEN-FIRST:_find_1
        // .//GEN-LAST:_find_1
        // .//GEN-BEGIN:_find_2_be
        // Execute The Query
        Collection results = uow.query(criteria);
        // .//GEN-END:_find_2_be
        // Add custom code after the query //GEN-FIRST:_find_2
        // .//GEN-LAST:_find_2
        // .//GEN-BEGIN:_find_3_be
        // Convert the domain objects into the outbound dto
        UserFinderOutDto output = buildDto(uow, results, input);
        // Print Debug Information for the output
        if (log.isDebugEnabled()) {
            log.debug("Output: " + output);
        }
        return output;
    } finally {
        if (uow != null)
            uow.rollback();
    }
}
Also used : UserFinderOutDto(org.jaffa.applications.jaffa.modules.admin.components.userfinder.dto.UserFinderOutDto) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 80 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class ApplicationRulesUtilities method incorporateValuesFromPersistentStore.

private void incorporateValuesFromPersistentStore(String source, Map<String, Collection<String>> domainRulesCache, Collection<String> expandedRules, String[] domainInfo, String preRule, String postRule) {
    Criteria myCriteria = new Criteria();
    UOW myUOW = null;
    try {
        myCriteria.setTable(domainInfo[1]);
        /*
             * Added group by to avoid fetching everything. Performance optimization.
             * It will find the unique field value based on the provided field on rule.
             */
        myCriteria.addGroupBy(domainInfo[2], domainInfo[2]);
        myUOW = new UOW();
        Collection<String> domainFieldValues = new ArrayList<>();
        Iterator<Persistent> myCollection = myUOW.query(myCriteria).iterator();
        while (myCollection.hasNext()) {
            Map row = (Map) myCollection.next();
            String domainFieldValue = (String) row.get(domainInfo[2]);
            domainFieldValues.add(domainFieldValue);
            String expandedRule = preRule + domainFieldValue + postRule;
            // Recursively call this method to handle rules with
            // multiple internal properties.
            Collection<String> furtherExpandedRules = elaborateDomainRules(expandedRule, domainRulesCache);
            expandedRules.addAll(furtherExpandedRules);
        }
        // Mapping the domain rule name to its content in the cache
        domainRulesCache.put(domainInfo[1], domainFieldValues);
    } catch (Exception e) {
        log.error("Unable to elaborate " + source, e);
    } finally {
        if (myUOW != null) {
            try {
                myUOW.rollback();
            } catch (Exception e) {
                log.error("Failed to rollback UOW:" + e);
            }
        }
    }
}
Also used : Persistent(org.jaffa.persistence.Persistent) Criteria(org.jaffa.persistence.Criteria) RuleMetaDataCriteria(org.jaffa.rules.rulemeta.data.RuleMetaDataCriteria) UOW(org.jaffa.persistence.UOW) RulesEngineException(org.jaffa.rules.RulesEngineException)

Aggregations

UOW (org.jaffa.persistence.UOW)260 Criteria (org.jaffa.persistence.Criteria)139 FrameworkException (org.jaffa.exceptions.FrameworkException)99 ApplicationException (org.jaffa.exceptions.ApplicationException)88 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)87 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)82 Iterator (java.util.Iterator)47 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)33 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)33 ArrayList (java.util.ArrayList)19 Transaction (org.jaffa.transaction.domain.Transaction)19 Map (java.util.Map)16 LinkedHashMap (java.util.LinkedHashMap)13 HashMap (java.util.HashMap)12 DateTime (org.jaffa.datatypes.DateTime)11 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)10 IPersistent (org.jaffa.persistence.IPersistent)10 Method (java.lang.reflect.Method)9 Collection (java.util.Collection)8 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)8