Package org.broadleafcommerce.core.workflow.state

Examples of org.broadleafcommerce.core.workflow.state.ActivityStateManager


    @Override
    public ProcessContext<?> doActivities(Object seedData) throws WorkflowException {
        if (LOG.isDebugEnabled()) {
            LOG.debug(getBeanName() + " processor is running..");
        }
        ActivityStateManager activityStateManager = ((ActivityStateManager) getBeanFactory().getBean("blActivityStateManager"));
        if (activityStateManager == null) {
            throw new IllegalStateException("Unable to find an instance of ActivityStateManager registered under bean id blActivityStateManager");
        }
        ProcessContext<?> context = null;
        RollbackStateLocal rollbackStateLocal = RollbackStateLocal.getRollbackStateLocal();
        if (rollbackStateLocal == null) {
            rollbackStateLocal = new RollbackStateLocal();
            rollbackStateLocal.setThreadId(String.valueOf(Thread.currentThread().getId()));
            rollbackStateLocal.setWorkflowId(getBeanName());
            RollbackStateLocal.setRollbackStateLocal(rollbackStateLocal);
        }
        try {
            //retrieve injected by Spring
            List<Activity<ProcessContext<?>>> activities = getActivities();

            //retrieve a new instance of the Workflow ProcessContext
            context = createContext(seedData);

            for (Activity<ProcessContext<?>> activity : activities) {
                if (activity.shouldExecute(context)) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("running activity:" + activity.getBeanName() + " using arguments:" + context);
                    }
   
                    try {
                        context = activity.execute(context);
                    } catch (Throwable th) {
                        if (getAutoRollbackOnError()) {
                            LOG.info("Automatically rolling back state for any previously registered RollbackHandlers. RollbackHandlers may be registered for workflow activities in appContext.");
                            ActivityStateManagerImpl.getStateManager().rollbackAllState();
                        }
                        ErrorHandler errorHandler = activity.getErrorHandler();
                        if (errorHandler == null) {
                            LOG.info("no error handler for this action, run default error" + "handler and abort processing ");
                            getDefaultErrorHandler().handleError(context, th);
                            break;
                        } else {
                            LOG.info("run error handler and continue");
                            errorHandler.handleError(context, th);
                        }
                    }
   
                    //ensure its ok to continue the process
                    if (processShouldStop(context, activity)) {
                        break;
                    }
   
                    //register the RollbackHandler
                    if (activity.getRollbackHandler() != null && activity.getAutomaticallyRegisterRollbackHandler()) {
                        ActivityStateManagerImpl.getStateManager().registerState(activity, context, activity.getRollbackRegion(), activity.getRollbackHandler(), activity.getStateConfiguration());
                    }
                } else {
                    LOG.debug("Not executing activity: " + activity.getBeanName() + " based on the context: " + context);
                }
            }
        } finally {
            rollbackStateLocal = RollbackStateLocal.getRollbackStateLocal();
            if (rollbackStateLocal != null && rollbackStateLocal.getWorkflowId().equals(getBeanName())) {
                activityStateManager.clearAllState();
                RollbackStateLocal.setRollbackStateLocal(null);
            }
        }
        LOG.debug(getBeanName() + " processor is done.");
View Full Code Here

TOP

Related Classes of org.broadleafcommerce.core.workflow.state.ActivityStateManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.