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);
}
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);
}
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);
}
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);
}
}
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);
}
Aggregations