use of org.kie.kogito.process.workitems.InternalKogitoWorkItem in project kogito-runtimes by kiegroup.
the class WorkItemNodeInstance method cancel.
@Override
public void cancel() {
InternalKogitoWorkItem item = getWorkItem();
if (item != null && item.getState() != COMPLETED && item.getState() != ABORTED) {
try {
((InternalKogitoWorkItemManager) getProcessInstance().getKnowledgeRuntime().getWorkItemManager()).internalAbortWorkItem(item.getStringId());
} catch (WorkItemHandlerNotFoundException wihnfe) {
getProcessInstance().setState(STATE_ABORTED);
throw wihnfe;
}
}
if (exceptionHandlingProcessInstanceId != null) {
KogitoProcessRuntime kruntime = getKieRuntimeForSubprocess();
ProcessInstance processInstance = (ProcessInstance) kruntime.getProcessInstance(exceptionHandlingProcessInstanceId);
if (processInstance != null) {
processInstance.setState(STATE_ABORTED);
}
}
super.cancel();
}
use of org.kie.kogito.process.workitems.InternalKogitoWorkItem in project kogito-runtimes by kiegroup.
the class WorkItemNodeInstance method createWorkItem.
protected InternalKogitoWorkItem createWorkItem(WorkItemNode workItemNode) {
Work work = workItemNode.getWork();
workItem = newWorkItem();
workItem.setName(work.getName());
workItem.setProcessInstanceId(getProcessInstance().getStringId());
Map<String, Object> resolvedParameters = new HashMap<>();
Collection<String> metaParameters = work.getMetaParameters();
for (Entry<String, Object> e : work.getParameters().entrySet()) {
if (!metaParameters.contains(e.getKey()) && e.getValue() != null) {
resolvedParameters.put(e.getKey(), e.getValue());
if (e.getValue() instanceof String) {
// we try first is a variable
Object value = this.getVariable((String) e.getValue());
if (value != null) {
resolvedParameters.put(e.getKey(), value);
} else {
resolvedParameters.put(e.getKey(), resolveValue(e.getValue()));
}
}
}
}
workItem.setStartDate(new Date());
Function<String, Object> varResolver = (varRef) -> {
if (resolvedParameters.containsKey(varRef)) {
return resolvedParameters.get(varRef);
}
return getVariable(varRef);
};
Map<String, Object> inputSet = NodeIoHelper.processInputs(this, varResolver);
inputSet.putAll(resolvedParameters);
if (dynamicParameters != null) {
inputSet.putAll(dynamicParameters);
}
workItem.getParameters().putAll(inputSet);
return workItem;
}
use of org.kie.kogito.process.workitems.InternalKogitoWorkItem in project kogito-runtimes by kiegroup.
the class KogitoDefaultWorkItemManager method completeWorkItem.
@Override
public void completeWorkItem(String id, Map<String, Object> results, Policy<?>... policies) {
InternalKogitoWorkItem workItem = workItems.get(id);
// work item may have been aborted
if (workItem != null) {
workItem.setResults(results);
KogitoProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceStringId());
workItem.setState(COMPLETED);
// process instance may have finished already
if (processInstance != null) {
processInstance.signalEvent("workItemCompleted", workItem);
}
workItems.remove(id);
}
}
use of org.kie.kogito.process.workitems.InternalKogitoWorkItem in project kogito-runtimes by kiegroup.
the class PredictionAwareHumanTaskLifeCycleTest method configure.
@BeforeEach
public void configure() {
predictNow = new AtomicBoolean(false);
trainedTasks = new ArrayList<>();
predictionService = new PredictionService() {
@Override
public void train(org.kie.api.runtime.process.WorkItem task, Map<String, Object> inputData, Map<String, Object> outputData) {
trainedTasks.add(((InternalKogitoWorkItem) task).getStringId());
}
@Override
public PredictionOutcome predict(org.kie.api.runtime.process.WorkItem task, Map<String, Object> inputData) {
if (predictNow.get()) {
return new PredictionOutcome(95, 75, Collections.singletonMap("output", "predicted value"));
}
return new PredictionOutcome();
}
@Override
public String getIdentifier() {
return "test";
}
};
CachedWorkItemHandlerConfig wiConfig = new CachedWorkItemHandlerConfig();
wiConfig.register("Human Task", new HumanTaskWorkItemHandler(new PredictionAwareHumanTaskLifeCycle(predictionService)));
config = new StaticProcessConfig(wiConfig, new DefaultProcessEventListenerConfig(), new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null);
}
use of org.kie.kogito.process.workitems.InternalKogitoWorkItem in project kogito-runtimes by kiegroup.
the class ActivityTest method testUserTaskVerifyParameters.
@Test
public void testUserTaskVerifyParameters() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-UserTask.bpmn2");
kruntime.getKieSession().getEnvironment().set("deploymentId", "test-deployment-id");
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
KogitoProcessInstance processInstance = kruntime.startProcess("UserTask");
assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("john", workItem.getParameter("ActorId"));
final String pId = processInstance.getStringId();
kruntime.getKieSession().execute((ExecutableCommand<Void>) context -> {
KogitoProcessInstance processInstance1 = kruntime.getProcessInstance(pId);
assertNotNull(processInstance1);
NodeInstance nodeInstance = ((KogitoNodeInstanceContainer) processInstance1).getNodeInstance(((InternalKogitoWorkItem) workItem).getNodeInstanceStringId());
assertNotNull(nodeInstance);
assertTrue(nodeInstance instanceof WorkItemNodeInstance);
String deploymentId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getDeploymentId();
String nodeInstanceId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeInstanceStringId();
long nodeId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeId();
assertEquals(((InternalKogitoWorkItem) workItem).getDeploymentId(), deploymentId);
assertEquals(((InternalKogitoWorkItem) workItem).getNodeId(), nodeId);
assertEquals(((InternalKogitoWorkItem) workItem).getNodeInstanceStringId(), nodeInstanceId);
return null;
});
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
assertProcessInstanceFinished(processInstance, kruntime);
}
Aggregations