Search in sources :

Example 1 with ExceptionHandler

use of org.jbpm.process.core.context.exception.ExceptionHandler in project jbpm by kiegroup.

the class CompensationScopeInstance method handleException.

public void handleException(String activityRef, Object dunno) {
    assert activityRef != null : "It should not be possible for the compensation activity reference to be null here.";
    CompensationScope compensationScope = (CompensationScope) getExceptionScope();
    // broadcast/general compensation in reverse order
    if (activityRef.startsWith(IMPLICIT_COMPENSATION_PREFIX)) {
        activityRef = activityRef.substring(IMPLICIT_COMPENSATION_PREFIX.length());
        assert activityRef.equals(compensationScope.getContextContainerId()) : "Compensation activity ref [" + activityRef + "] does not match" + " Compensation Scope container id [" + compensationScope.getContextContainerId() + "]";
        Map<String, ExceptionHandler> handlers = compensationScope.getExceptionHandlers();
        List<String> completedNodeIds = ((WorkflowProcessInstanceImpl) getProcessInstance()).getCompletedNodeIds();
        ListIterator<String> iter = completedNodeIds.listIterator(completedNodeIds.size());
        while (iter.hasPrevious()) {
            String completedId = iter.previous();
            ExceptionHandler handler = handlers.get(completedId);
            if (handler != null) {
                handleException(handler, completedId, null);
            }
        }
    } else {
        // Specific compensation
        ExceptionHandler handler = compensationScope.getExceptionHandler(activityRef);
        if (handler == null) {
            throw new IllegalArgumentException("Could not find CompensationHandler for " + activityRef);
        }
        handleException(handler, activityRef, null);
    }
    // Cancel all node instances created for compensation
    while (!compensationInstances.isEmpty()) {
        NodeInstance generatedInstance = compensationInstances.pop();
        ((NodeInstanceContainer) generatedInstance.getNodeInstanceContainer()).removeNodeInstance(generatedInstance);
    }
}
Also used : ExceptionHandler(org.jbpm.process.core.context.exception.ExceptionHandler) NodeInstanceContainer(org.jbpm.workflow.instance.NodeInstanceContainer) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) CompensationScope(org.jbpm.process.core.context.exception.CompensationScope) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) NodeInstance(org.jbpm.workflow.instance.NodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance)

Example 2 with ExceptionHandler

use of org.jbpm.process.core.context.exception.ExceptionHandler in project jbpm by kiegroup.

the class XmlWorkflowProcessDumper method visitExceptionHandlers.

public static void visitExceptionHandlers(Map<String, ExceptionHandler> exceptionHandlers, StringBuilder xmlDump) {
    if (exceptionHandlers != null && exceptionHandlers.size() > 0) {
        xmlDump.append("    <exceptionHandlers>" + EOL);
        for (Map.Entry<String, ExceptionHandler> entry : exceptionHandlers.entrySet()) {
            ExceptionHandler exceptionHandler = entry.getValue();
            if (exceptionHandler instanceof ActionExceptionHandler) {
                ActionExceptionHandler actionExceptionHandler = (ActionExceptionHandler) exceptionHandler;
                xmlDump.append("      <exceptionHandler faultName=\"" + entry.getKey() + "\" type=\"action\" ");
                String faultVariable = actionExceptionHandler.getFaultVariable();
                if (faultVariable != null && faultVariable.length() > 0) {
                    xmlDump.append("faultVariable=\"" + faultVariable + "\" ");
                }
                xmlDump.append(">" + EOL);
                DroolsAction action = actionExceptionHandler.getAction();
                if (action != null) {
                    AbstractNodeHandler.writeAction(action, xmlDump);
                }
                xmlDump.append("      </exceptionHandler>" + EOL);
            } else {
                throw new IllegalArgumentException("Unknown exception handler type: " + exceptionHandler);
            }
        }
        xmlDump.append("    </exceptionHandlers>" + EOL);
    }
}
Also used : ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) ExceptionHandler(org.jbpm.process.core.context.exception.ExceptionHandler) DroolsAction(org.jbpm.workflow.core.DroolsAction) Map(java.util.Map) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler)

Example 3 with ExceptionHandler

use of org.jbpm.process.core.context.exception.ExceptionHandler in project jbpm by kiegroup.

the class ProcessBuilderImpl method buildContexts.

public void buildContexts(ContextContainer contextContainer, ProcessBuildContext buildContext) {
    List<Context> exceptionScopes = contextContainer.getContexts(ExceptionScope.EXCEPTION_SCOPE);
    if (exceptionScopes != null) {
        for (Context context : exceptionScopes) {
            // TODO: OCRAM: add compensation scope to process builder????
            ExceptionScope exceptionScope = (ExceptionScope) context;
            for (ExceptionHandler exceptionHandler : exceptionScope.getExceptionHandlers().values()) {
                if (exceptionHandler instanceof ActionExceptionHandler) {
                    DroolsConsequenceAction action = (DroolsConsequenceAction) ((ActionExceptionHandler) exceptionHandler).getAction();
                    ActionDescr actionDescr = new ActionDescr();
                    actionDescr.setText(action.getConsequence());
                    actionDescr.setResource(buildContext.getProcessDescr().getResource());
                    ProcessDialect dialect = ProcessDialectRegistry.getDialect(action.getDialect());
                    dialect.getActionBuilder().build(buildContext, action, actionDescr, (ProcessImpl) buildContext.getProcess());
                }
            }
        }
    }
}
Also used : Context(org.jbpm.process.core.Context) ProcessBuildContext(org.jbpm.process.builder.ProcessBuildContext) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) ExceptionHandler(org.jbpm.process.core.context.exception.ExceptionHandler) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ActionDescr(org.drools.compiler.lang.descr.ActionDescr) ProcessDialect(org.jbpm.process.builder.dialect.ProcessDialect) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler)

Example 4 with ExceptionHandler

use of org.jbpm.process.core.context.exception.ExceptionHandler in project jbpm by kiegroup.

the class ExceptionScopeInstance method handleException.

public void handleException(String exception, Object params) {
    ExceptionHandler handler = getExceptionScope().getExceptionHandler(exception);
    if (handler == null) {
        throw new IllegalArgumentException("Could not find ExceptionHandler for " + exception);
    }
    handleException(handler, exception, params);
}
Also used : ExceptionHandler(org.jbpm.process.core.context.exception.ExceptionHandler)

Aggregations

ExceptionHandler (org.jbpm.process.core.context.exception.ExceptionHandler)4 ActionExceptionHandler (org.jbpm.process.core.context.exception.ActionExceptionHandler)2 Map (java.util.Map)1 ActionDescr (org.drools.compiler.lang.descr.ActionDescr)1 ProcessBuildContext (org.jbpm.process.builder.ProcessBuildContext)1 ProcessDialect (org.jbpm.process.builder.dialect.ProcessDialect)1 Context (org.jbpm.process.core.Context)1 CompensationScope (org.jbpm.process.core.context.exception.CompensationScope)1 ExceptionScope (org.jbpm.process.core.context.exception.ExceptionScope)1 DroolsAction (org.jbpm.workflow.core.DroolsAction)1 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)1 NodeInstance (org.jbpm.workflow.instance.NodeInstance)1 NodeInstanceContainer (org.jbpm.workflow.instance.NodeInstanceContainer)1 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)1 EventNodeInstance (org.jbpm.workflow.instance.node.EventNodeInstance)1 EventSubProcessNodeInstance (org.jbpm.workflow.instance.node.EventSubProcessNodeInstance)1