Search in sources :

Example 1 with HumanTaskWorkItemHandler

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);
}
Also used : InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) HumanTaskWorkItemHandler(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler) StaticProcessConfig(org.kie.kogito.process.impl.StaticProcessConfig) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CachedWorkItemHandlerConfig(org.kie.kogito.process.impl.CachedWorkItemHandlerConfig) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(org.kie.kogito.process.impl.DefaultProcessEventListenerConfig) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with HumanTaskWorkItemHandler

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"));
    }
}
Also used : HumanTaskWorkItemHandler(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler) PredictionAwareHumanTaskLifeCycle(org.kie.kogito.prediction.api.PredictionAwareHumanTaskLifeCycle) StaticProcessConfig(org.kie.kogito.process.impl.StaticProcessConfig) HashMap(java.util.HashMap) CachedWorkItemHandlerConfig(org.kie.kogito.process.impl.CachedWorkItemHandlerConfig) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(org.kie.kogito.process.impl.DefaultProcessEventListenerConfig) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with HumanTaskWorkItemHandler

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());
}
Also used : Policy(org.kie.kogito.process.workitem.Policy) HumanTaskWorkItemHandler(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler) ProcessConfig(org.kie.kogito.process.ProcessConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Config(org.kie.kogito.Config) ProcessConfig(org.kie.kogito.process.ProcessConfig) WorkItemHandlerConfig(org.kie.kogito.process.WorkItemHandlerConfig) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) WorkItem(org.kie.kogito.process.WorkItem) WorkItemHandlerConfig(org.kie.kogito.process.WorkItemHandlerConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.jupiter.api.Test)

Aggregations

HumanTaskWorkItemHandler (org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 CachedWorkItemHandlerConfig (org.kie.kogito.process.impl.CachedWorkItemHandlerConfig)2 DefaultProcessEventListenerConfig (org.kie.kogito.process.impl.DefaultProcessEventListenerConfig)2 StaticProcessConfig (org.kie.kogito.process.impl.StaticProcessConfig)2 CollectingUnitOfWorkFactory (org.kie.kogito.services.uow.CollectingUnitOfWorkFactory)2 DefaultUnitOfWorkManager (org.kie.kogito.services.uow.DefaultUnitOfWorkManager)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.jupiter.api.Test)1 Config (org.kie.kogito.Config)1 KogitoWorkItemHandler (org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler)1 PredictionAwareHumanTaskLifeCycle (org.kie.kogito.prediction.api.PredictionAwareHumanTaskLifeCycle)1 ProcessConfig (org.kie.kogito.process.ProcessConfig)1 WorkItem (org.kie.kogito.process.WorkItem)1 WorkItemHandlerConfig (org.kie.kogito.process.WorkItemHandlerConfig)1 Policy (org.kie.kogito.process.workitem.Policy)1 InternalKogitoWorkItem (org.kie.kogito.process.workitems.InternalKogitoWorkItem)1