use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler 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.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler in project kogito-runtimes by kiegroup.
the class SmileRandomForestPredictionTest method configure.
@BeforeEach
public void configure() {
final RandomForestConfiguration configuration = new RandomForestConfiguration();
final Map<String, AttributeType> inputFeatures = new HashMap<>();
inputFeatures.put("ActorId", AttributeType.NOMINAL);
configuration.setInputFeatures(inputFeatures);
configuration.setOutcomeName("output");
configuration.setOutcomeType(AttributeType.NOMINAL);
configuration.setConfidenceThreshold(0.7);
configuration.setNumTrees(1);
predictionService = new SmileRandomForest(configuration);
CachedWorkItemHandlerConfig wiConfig = new CachedWorkItemHandlerConfig();
wiConfig.register("Human Task", new HumanTaskWorkItemHandler(new PredictionAwareHumanTaskLifeCycle(predictionService)));
config = new StaticProcessConfig(wiConfig, new DefaultProcessEventListenerConfig(), new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null);
for (int i = 0; i < 10; i++) {
predictionService.train(null, Collections.singletonMap("ActorId", "john"), Collections.singletonMap("output", "predicted value"));
}
for (int i = 0; i < 8; i++) {
predictionService.train(null, Collections.singletonMap("ActorId", "mary"), Collections.singletonMap("output", "value"));
}
}
use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler in project kogito-runtimes by kiegroup.
the class JsonSchemaUtilTest method testJsonSchemaPhases.
@Test
<T> void testJsonSchemaPhases() throws IOException {
InputStream in = new ByteArrayInputStream(example.getBytes());
Policy<T>[] policies = new Policy[0];
Map<String, Object> schemaMap = JsonSchemaUtil.load(in);
in.close();
Process<T> process = mock(Process.class);
ProcessInstances<T> processInstances = mock(ProcessInstances.class);
when(process.instances()).thenReturn(processInstances);
ProcessInstance<T> processInstance = mock(ProcessInstance.class);
when(processInstances.findById("pepe", ProcessInstanceReadMode.READ_ONLY)).thenReturn((Optional) Optional.of(processInstance));
WorkItem task = mock(WorkItem.class);
when(processInstance.workItem("task", policies)).thenReturn(task);
when(task.getPhase()).thenReturn("active");
Config config = mock(Config.class);
ProcessConfig processConfig = mock(ProcessConfig.class);
when(config.get(any())).thenReturn(processConfig);
WorkItemHandlerConfig workItemHandlerConfig = mock(WorkItemHandlerConfig.class);
when(processConfig.workItemHandlers()).thenReturn(workItemHandlerConfig);
KogitoWorkItemHandler workItemHandler = new HumanTaskWorkItemHandler();
when(workItemHandlerConfig.forName("Human Task")).thenReturn(workItemHandler);
schemaMap = JsonSchemaUtil.addPhases(process, workItemHandler, "pepe", "task", policies, schemaMap);
assertFalse(((Collection) schemaMap.get("phases")).isEmpty());
}
Aggregations