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