use of org.kie.kogito.process.ProcessError in project kogito-runtimes by kiegroup.
the class PublishEventIT method testServiceTaskProcessWithError.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testServiceTaskProcessWithError() throws Exception {
Application app = generateCodeProcessesOnly("servicetask/ServiceProcessDifferentOperations.bpmn2");
assertThat(app).isNotNull();
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
Process<? extends Model> p = app.get(Processes.class).processById("ServiceProcessDifferentOperations");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance processInstance = p.createInstance(m);
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ERROR);
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(1);
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 5);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "WorkItemNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active thus null for leave time
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
assertThat(body.getError()).isNotNull();
assertThat(body.getError().getErrorMessage()).contains("java.lang.NullPointerException");
assertThat(body.getError().getNodeDefinitionId()).isEqualTo("_38E04E27-3CCA-47F9-927B-E37DC4B8CE25");
parameters.put("s", "john");
m.fromMap(parameters);
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.updateVariables(m);
uow.end();
events = publisher.extract();
assertThat(events).isNotNull().hasSize(1);
body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 5);
assertThat(body.getError()).isNotNull();
assertThat(body.getError().getErrorMessage()).contains("java.lang.NullPointerException");
assertThat(body.getError().getNodeDefinitionId()).isEqualTo("_38E04E27-3CCA-47F9-927B-E37DC4B8CE25");
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
if (processInstance.error().isPresent()) {
((ProcessError) processInstance.error().get()).retrigger();
}
uow.end();
events = publisher.extract();
assertThat(events).isNotNull().hasSize(1);
body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 2);
assertThat(body.getError()).isNull();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKeys("s");
assertThat(result.toMap().get("s")).isNotNull().isEqualTo("Goodbye Hello john!!");
}
use of org.kie.kogito.process.ProcessError in project kogito-runtimes by kiegroup.
the class MockCacheProcessInstancesTest method testBasicFlowWithError.
private void testBasicFlowWithError(Consumer<ProcessInstance<BpmnVariables>> op) {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask-Script.bpmn2")).get(0);
// workaround as BpmnProcess does not compile the scripts but just reads the xml
for (Node node : ((WorkflowProcess) process.get()).getNodes()) {
if (node instanceof ActionNode) {
DroolsAction a = ((ActionNode) node).getAction();
a.setMetaData("Action", (Action) kcontext -> {
System.out.println("The variable value is " + kcontext.getVariable("s") + " about to call toString on it");
kcontext.getVariable("s").toString();
});
}
}
process.setProcessInstancesFactory(new CacheProcessInstancesFactory(cacheManager));
process.configure();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create());
processInstance.start();
assertThat(processInstance.status()).isEqualTo(STATE_ERROR);
Optional<ProcessError> errorOp = processInstance.error();
assertThat(errorOp).isPresent();
assertThat(errorOp.get().failedNodeId()).isEqualTo("ScriptTask_1");
assertThat(errorOp.get().errorMessage()).isNotNull().contains("java.lang.NullPointerException");
op.accept(processInstance);
assertThat(processInstance.error()).isNotPresent();
WorkItem workItem = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john"))).get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
processInstance.completeWorkItem(workItem.getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
}
use of org.kie.kogito.process.ProcessError in project kogito-runtimes by kiegroup.
the class ActivityGenerationModelTest method testExclusiveSplitRetriggerAfterError.
@Test
public void testExclusiveSplitRetriggerAfterError() throws Exception {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-ExclusiveSplit.bpmn2")).get(0);
ProcessMetaData metaData = ProcessToExecModelGenerator.INSTANCE.generate((WorkflowProcess) process.get());
String content = metaData.getGeneratedClassModel().toString();
assertThat(content).isNotNull();
log(content);
Map<String, String> classData = new HashMap<>();
classData.put("org.drools.bpmn2.TestProcess", content);
SystemOutWorkItemHandler workItemHandler = new SystemOutWorkItemHandler();
Map<String, BpmnProcess> processes = createProcesses(classData, Collections.singletonMap("Email", workItemHandler));
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "First1");
params.put("y", "Second1");
ProcessInstance<BpmnVariables> processInstance = processes.get("com.sample.test").createInstance(BpmnVariables.create(params));
processInstance.start();
assertEquals(KogitoProcessInstance.STATE_ERROR, processInstance.status());
Optional<ProcessError> errorOptional = processInstance.error();
assertThat(errorOptional).isPresent();
ProcessError error = errorOptional.get();
assertThat(error.failedNodeId()).isEqualTo("_2");
assertThat(error.errorMessage()).contains("XOR split could not find at least one valid outgoing connection for split Split");
params.put("x", "First");
processInstance.updateVariables(BpmnVariables.create(params));
error.retrigger();
assertEquals(STATE_COMPLETED, processInstance.status());
}
use of org.kie.kogito.process.ProcessError in project kogito-runtimes by kiegroup.
the class AbstractProcessInstance method buildProcessError.
protected ProcessError buildProcessError() {
WorkflowProcessInstance pi = processInstance();
final String errorMessage = pi.getErrorMessage();
final String nodeInError = pi.getNodeIdInError();
final Throwable errorCause = pi.getErrorCause().orElse(null);
return new ProcessError() {
@Override
public String failedNodeId() {
return nodeInError;
}
@Override
public String errorMessage() {
return errorMessage;
}
@Override
public Throwable errorCause() {
return errorCause;
}
@Override
public void retrigger() {
WorkflowProcessInstanceImpl pInstance = (WorkflowProcessInstanceImpl) processInstance();
NodeInstance ni = pInstance.getByNodeDefinitionId(nodeInError, pInstance.getNodeContainer());
pInstance.setState(STATE_ACTIVE);
pInstance.internalSetErrorNodeId(null);
pInstance.internalSetErrorMessage(null);
ni.trigger(null, Node.CONNECTION_DEFAULT_TYPE);
removeOnFinish();
}
@Override
public void skip() {
WorkflowProcessInstanceImpl pInstance = (WorkflowProcessInstanceImpl) processInstance();
NodeInstance ni = pInstance.getByNodeDefinitionId(nodeInError, pInstance.getNodeContainer());
pInstance.setState(STATE_ACTIVE);
pInstance.internalSetErrorNodeId(null);
pInstance.internalSetErrorMessage(null);
((NodeInstanceImpl) ni).triggerCompleted(Node.CONNECTION_DEFAULT_TYPE, true);
removeOnFinish();
}
};
}
use of org.kie.kogito.process.ProcessError in project kogito-runtimes by kiegroup.
the class BaseProcessInstanceManagementResource method doGetInstanceInError.
public T doGetInstanceInError(String processId, String processInstanceId) {
return executeOnInstanceInError(processId, processInstanceId, processInstance -> {
ProcessError error = processInstance.error().get();
Map<String, String> data = new HashMap<>();
data.put("id", processInstance.id());
data.put("failedNodeId", error.failedNodeId());
data.put("message", error.errorMessage());
return buildOkResponse(data);
});
}
Aggregations