Search in sources :

Example 1 with ActionExceptionHandler

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

the class ProcessHandler method linkBoundaryErrorEvent.

private static void linkBoundaryErrorEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
    ContextContainer compositeNode = (ContextContainer) attachedNode;
    ExceptionScope exceptionScope = (ExceptionScope) compositeNode.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
    if (exceptionScope == null) {
        exceptionScope = new ExceptionScope();
        compositeNode.addContext(exceptionScope);
        compositeNode.setDefaultContext(exceptionScope);
    }
    String errorCode = (String) node.getMetaData().get("ErrorEvent");
    boolean hasErrorCode = (Boolean) node.getMetaData().get("HasErrorEvent");
    String errorStructureRef = (String) node.getMetaData().get("ErrorStructureRef");
    ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
    String variable = ((EventNode) node).getVariableName();
    DroolsConsequenceAction action = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Error-" + attachedTo + "-" + errorCode + "\", kcontext.getVariable(\"" + variable + "\"));");
    exceptionHandler.setAction(action);
    exceptionHandler.setFaultVariable(variable);
    exceptionScope.setExceptionHandler(hasErrorCode ? errorCode : null, exceptionHandler);
    if (errorStructureRef != null) {
        exceptionScope.setExceptionHandler(errorStructureRef, exceptionHandler);
    }
    List<DroolsAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
    if (actions == null) {
        actions = new ArrayList<DroolsAction>();
    }
    DroolsConsequenceAction cancelAction = new DroolsConsequenceAction("java", null);
    cancelAction.setMetaData("Action", new CancelNodeInstanceAction(attachedTo));
    actions.add(cancelAction);
    ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) ContextContainer(org.jbpm.process.core.ContextContainer) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) CancelNodeInstanceAction(org.jbpm.process.instance.impl.CancelNodeInstanceAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler)

Example 2 with ActionExceptionHandler

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

the class DynamicNodeFactory method exceptionHandler.

public DynamicNodeFactory exceptionHandler(String exception, String dialect, String action) {
    ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
    exceptionHandler.setAction(new DroolsConsequenceAction(dialect, action));
    return exceptionHandler(exception, exceptionHandler);
}
Also used : DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler)

Example 3 with ActionExceptionHandler

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

the class RuleFlowProcessFactory method exceptionHandler.

public RuleFlowProcessFactory exceptionHandler(String exception, String dialect, String action) {
    ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
    exceptionHandler.setAction(new DroolsConsequenceAction(dialect, action));
    return exceptionHandler(exception, exceptionHandler);
}
Also used : DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler)

Example 4 with ActionExceptionHandler

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

the class DefaultExceptionScopeInstance method handleException.

public void handleException(ExceptionHandler handler, String exception, Object params) {
    if (handler instanceof ActionExceptionHandler) {
        ActionExceptionHandler exceptionHandler = (ActionExceptionHandler) handler;
        Action action = (Action) exceptionHandler.getAction().getMetaData("Action");
        try {
            ProcessInstance processInstance = getProcessInstance();
            ProcessContext processContext = new ProcessContext(processInstance.getKnowledgeRuntime());
            ContextInstanceContainer contextInstanceContainer = getContextInstanceContainer();
            if (contextInstanceContainer instanceof NodeInstance) {
                processContext.setNodeInstance((NodeInstance) contextInstanceContainer);
            } else {
                processContext.setProcessInstance(processInstance);
            }
            String faultVariable = exceptionHandler.getFaultVariable();
            if (faultVariable != null) {
                processContext.setVariable(faultVariable, params);
            }
            action.execute(processContext);
        } catch (Exception e) {
            throw new RuntimeException("unable to execute Action", e);
        }
    } else {
        throw new IllegalArgumentException("Unknown exception handler " + handler);
    }
}
Also used : Action(org.jbpm.process.instance.impl.Action) ProcessInstance(org.jbpm.process.instance.ProcessInstance) ContextInstanceContainer(org.jbpm.process.instance.ContextInstanceContainer) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) NodeInstance(org.jbpm.workflow.instance.NodeInstance) ProcessContext(org.drools.core.spi.ProcessContext)

Example 5 with ActionExceptionHandler

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

the class CompositeNodeFactory method exceptionHandler.

public CompositeNodeFactory exceptionHandler(String exception, String dialect, String action) {
    ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
    exceptionHandler.setAction(new DroolsConsequenceAction(dialect, action));
    return exceptionHandler(exception, exceptionHandler);
}
Also used : DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler)

Aggregations

ActionExceptionHandler (org.jbpm.process.core.context.exception.ActionExceptionHandler)11 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)8 ExceptionScope (org.jbpm.process.core.context.exception.ExceptionScope)6 DroolsAction (org.jbpm.workflow.core.DroolsAction)5 ContextContainer (org.jbpm.process.core.ContextContainer)4 EventNode (org.jbpm.workflow.core.node.EventNode)4 ArrayList (java.util.ArrayList)2 ExceptionHandler (org.jbpm.process.core.context.exception.ExceptionHandler)2 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)2 CancelNodeInstanceAction (org.jbpm.process.instance.impl.CancelNodeInstanceAction)2 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)2 Constraint (org.jbpm.workflow.core.Constraint)2 ConstraintImpl (org.jbpm.workflow.core.impl.ConstraintImpl)2 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)2 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Diff (org.custommonkey.xmlunit.Diff)1