use of io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer in project automatiko-engine by automatiko-io.
the class FileSystemProcessInstancesTest method testBasicFlowControlledByUnitOfWork.
@Test
void testBasicFlowControlledByUnitOfWork() {
UnitOfWorkManager uowManager = new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory());
ProcessConfig config = new StaticProcessConfig(new DefaultWorkItemHandlerConfig(), new DefaultProcessEventListenerConfig(), uowManager, null, new DefaultVariableInitializer(), new FileSystemProcessInstancesFactory());
BpmnProcess process = createProcess(config, "BPMN2-UserTask.bpmn2");
process.configure();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
UnitOfWork uow = uowManager.newUnitOfWork();
uow.start();
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
assertThat(processInstance.description()).isEqualTo("User Task");
assertThat(process.instances().values(1, 10)).hasSize(1);
FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
verify(fileSystemBasedStorage, times(2)).create(any(), any());
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_DESCRIPTION), eq("User Task"));
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_STATUS), eq("1"));
String testVar = (String) processInstance.variables().get("test");
assertThat(testVar).isEqualTo("test");
assertThat(processInstance.description()).isEqualTo("User Task");
WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
uow = uowManager.newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
uow.end();
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
verify(fileSystemBasedStorage, times(1)).remove(any(), any());
assertThat(fileSystemBasedStorage.size()).isZero();
}
use of io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer in project automatiko-engine by automatiko-io.
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, new DefaultVariableInitializer(), 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 io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer in project automatiko-engine by automatiko-io.
the class ServerlessProcess method processConfig.
public static ProcessConfig processConfig() {
DefaultWorkItemHandlerConfig workItemHandlerConfig = new DefaultWorkItemHandlerConfig();
DefaultProcessEventListenerConfig processEventListenerConfig = new DefaultProcessEventListenerConfig();
return new StaticProcessConfig(workItemHandlerConfig, processEventListenerConfig, new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null, new DefaultVariableInitializer(), null);
}
use of io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer in project automatiko-engine by automatiko-io.
the class JbpmBpmn2TestCase method config.
protected ProcessConfig config(List<WorkItemHandler> handlers, List<ProcessEventListener> listeners) {
DefaultWorkItemHandlerConfig handlerConfig = new DefaultWorkItemHandlerConfig();
handlers.forEach(h -> handlerConfig.register(h.getName(), h));
DefaultProcessEventListenerConfig listenerConfig = new DefaultProcessEventListenerConfig();
listeners.forEach(h -> listenerConfig.register(h));
ProcessConfig config = new StaticProcessConfig(handlerConfig, listenerConfig, new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null, new DefaultVariableInitializer(), null);
return config;
}
use of io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer in project automatiko-engine by automatiko-io.
the class PredictionAwareHumanTaskLifeCycleTest method configure.
@BeforeEach
public void configure() {
predictNow = new AtomicBoolean(false);
trainedTasks = new ArrayList<>();
predictionService = new PredictionService() {
@Override
public void train(io.automatiko.engine.api.runtime.process.WorkItem task, Map<String, Object> inputData, Map<String, Object> outputData) {
trainedTasks.add(task.getId());
}
@Override
public PredictionOutcome predict(io.automatiko.engine.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, new DefaultVariableInitializer(), null);
}
Aggregations