Search in sources :

Example 1 with StaticProcessConfig

use of org.kie.kogito.process.impl.StaticProcessConfig 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 StaticProcessConfig

use of org.kie.kogito.process.impl.StaticProcessConfig 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 StaticProcessConfig

use of org.kie.kogito.process.impl.StaticProcessConfig in project kogito-runtimes by kiegroup.

the class ActivityGenerationModelTest method createProcesses.

protected Map<String, BpmnProcess> createProcesses(Map<String, String> classData, Map<String, KogitoWorkItemHandler> handlers) throws Exception {
    MemoryFileSystem srcMfs = new MemoryFileSystem();
    MemoryFileSystem trgMfs = new MemoryFileSystem();
    String[] sources = new String[classData.size()];
    int index = 0;
    for (Entry<String, String> entry : classData.entrySet()) {
        String fileName = entry.getKey().replaceAll("\\.", "/") + ".java";
        sources[index++] = fileName;
        srcMfs.write(fileName, entry.getValue().getBytes());
    }
    CompilationResult result = JAVA_COMPILER.compile(sources, srcMfs, trgMfs, this.getClass().getClassLoader());
    assertThat(result).isNotNull();
    assertThat(result.getErrors()).hasSize(0);
    CachedWorkItemHandlerConfig wiConfig = new CachedWorkItemHandlerConfig();
    for (Entry<String, KogitoWorkItemHandler> entry : handlers.entrySet()) {
        wiConfig.register(entry.getKey(), entry.getValue());
    }
    ProcessConfig config = new StaticProcessConfig(wiConfig, new DefaultProcessEventListenerConfig(), new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null);
    TestClassLoader cl = new TestClassLoader(this.getClass().getClassLoader(), trgMfs.getMap());
    Map<String, BpmnProcess> processes = new HashMap<>();
    BpmnProcesses bpmnProcesses = new BpmnProcesses();
    StaticApplication application = new StaticApplication(new StaticConfig(null, config), bpmnProcesses);
    for (String className : classData.keySet()) {
        Class<?> processClass = Class.forName(className, true, cl);
        Method processMethod = processClass.getMethod("process");
        Process process = (Process) processMethod.invoke(null);
        assertThat(process).isNotNull();
        processes.put(process.getId(), new BpmnProcess(process, config, application));
    }
    return processes;
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ProcessConfig(org.kie.kogito.process.ProcessConfig) StaticProcessConfig(org.kie.kogito.process.impl.StaticProcessConfig) StaticProcessConfig(org.kie.kogito.process.impl.StaticProcessConfig) HashMap(java.util.HashMap) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) StaticConfig(org.kie.kogito.StaticConfig) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) Process(org.kie.api.definition.process.Process) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) Method(java.lang.reflect.Method) BpmnProcesses(org.kie.kogito.process.bpmn2.BpmnProcesses) StaticApplication(org.kie.kogito.StaticApplication) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) CachedWorkItemHandlerConfig(org.kie.kogito.process.impl.CachedWorkItemHandlerConfig) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(org.kie.kogito.process.impl.DefaultProcessEventListenerConfig) CompilationResult(org.kie.memorycompiler.CompilationResult) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager)

Aggregations

CachedWorkItemHandlerConfig (org.kie.kogito.process.impl.CachedWorkItemHandlerConfig)3 DefaultProcessEventListenerConfig (org.kie.kogito.process.impl.DefaultProcessEventListenerConfig)3 StaticProcessConfig (org.kie.kogito.process.impl.StaticProcessConfig)3 CollectingUnitOfWorkFactory (org.kie.kogito.services.uow.CollectingUnitOfWorkFactory)3 DefaultUnitOfWorkManager (org.kie.kogito.services.uow.DefaultUnitOfWorkManager)3 HashMap (java.util.HashMap)2 HumanTaskWorkItemHandler (org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Method (java.lang.reflect.Method)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)1 Process (org.kie.api.definition.process.Process)1 WorkflowProcess (org.kie.api.definition.process.WorkflowProcess)1 StaticApplication (org.kie.kogito.StaticApplication)1 StaticConfig (org.kie.kogito.StaticConfig)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 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)1 BpmnProcesses (org.kie.kogito.process.bpmn2.BpmnProcesses)1