Search in sources :

Example 6 with ProcessConfig

use of io.automatiko.engine.api.workflow.ProcessConfig in project automatiko-engine by automatiko-io.

the class VariableTagsTest method testProcessWithReadonlyVariable.

@Test
public void testProcessWithReadonlyVariable() throws Exception {
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler("Human Task");
    ProcessConfig config = config(workItemHandler);
    BpmnProcess process = create(config, "variable-tags/approval-with-readonly-variable-tags.bpmn2");
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("approver", "john");
    ProcessInstance<BpmnVariables> instance = process.createInstance(BpmnVariables.create(parameters));
    instance.start();
    assertEquals(STATE_ACTIVE, instance.status());
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertThrows(VariableViolationException.class, () -> instance.completeWorkItem(workItem.getId(), Collections.singletonMap("ActorId", "john")));
    instance.abort();
    assertEquals(STATE_ABORTED, instance.status());
}
Also used : TestWorkItemHandler(io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler) BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) ProcessConfig(io.automatiko.engine.api.workflow.ProcessConfig) HashMap(java.util.HashMap) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 7 with ProcessConfig

use of io.automatiko.engine.api.workflow.ProcessConfig in project automatiko-engine by automatiko-io.

the class ActivityTest method testMinimalProcessMetaData.

@Test
public void testMinimalProcessMetaData() throws Exception {
    final List<String> list1 = new ArrayList<String>();
    final List<String> list2 = new ArrayList<String>();
    final List<String> list3 = new ArrayList<String>();
    final List<String> list4 = new ArrayList<String>();
    DefaultProcessEventListener listener = new DefaultProcessEventListener() {

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            logger.debug("before node");
            Map<String, Object> metaData = event.getNodeInstance().getNode().getMetaData();
            for (Map.Entry<String, Object> entry : metaData.entrySet()) {
                logger.debug(entry.getKey() + " " + entry.getValue());
            }
            String customTag = (String) metaData.get("customTag");
            if (customTag != null) {
                list1.add(customTag);
            }
            String customTag2 = (String) metaData.get("customTag2");
            if (customTag2 != null) {
                list2.add(customTag2);
            }
        }

        public void afterVariableChanged(ProcessVariableChangedEvent event) {
            logger.debug("after variable");
            VariableScope variableScope = (VariableScope) ((io.automatiko.engine.workflow.base.core.impl.ProcessImpl) event.getProcessInstance().getProcess()).resolveContext(VariableScope.VARIABLE_SCOPE, event.getVariableId());
            if (variableScope == null) {
                return;
            }
            Map<String, Object> metaData = variableScope.findVariable(event.getVariableId()).getMetaData();
            for (Map.Entry<String, Object> entry : metaData.entrySet()) {
                logger.debug(entry.getKey() + " " + entry.getValue());
            }
            String customTag = (String) metaData.get("customTagVar");
            if (customTag != null) {
                list3.add(customTag);
            }
        }

        public void afterProcessStarted(ProcessStartedEvent event) {
            logger.debug("after process");
            Map<String, Object> metaData = event.getProcessInstance().getProcess().getMetaData();
            for (Map.Entry<String, Object> entry : metaData.entrySet()) {
                logger.debug(entry.getKey() + " " + entry.getValue());
            }
            String customTag = (String) metaData.get("customTagProcess");
            if (customTag != null) {
                list4.add(customTag);
            }
        }
    };
    ProcessConfig config = config(listener);
    BpmnProcess process = create(config, "BPMN2-MinimalProcessMetaData.bpmn2");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "krisv");
    ProcessInstance<BpmnVariables> instance = process.createInstance(BpmnVariables.create(params));
    instance.start();
    assertEquals(STATE_COMPLETED, instance.status());
    assertEquals(3, list1.size());
    assertEquals(2, list2.size());
    assertEquals(1, list3.size());
    assertEquals(1, list4.size());
}
Also used : ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) ProcessConfig(io.automatiko.engine.api.workflow.ProcessConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessStartedEvent(io.automatiko.engine.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(io.automatiko.engine.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) HashMap(java.util.HashMap) Map(java.util.Map) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 8 with ProcessConfig

use of io.automatiko.engine.api.workflow.ProcessConfig 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();
}
Also used : BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) StaticProcessConfig(io.automatiko.engine.workflow.StaticProcessConfig) ProcessConfig(io.automatiko.engine.api.workflow.ProcessConfig) StaticProcessConfig(io.automatiko.engine.workflow.StaticProcessConfig) DefaultVariableInitializer(io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer) WorkItem(io.automatiko.engine.api.workflow.WorkItem) DefaultWorkItemHandlerConfig(io.automatiko.engine.workflow.DefaultWorkItemHandlerConfig) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) UnitOfWorkManager(io.automatiko.engine.api.uow.UnitOfWorkManager) CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 9 with ProcessConfig

use of io.automatiko.engine.api.workflow.ProcessConfig in project automatiko-engine by automatiko-io.

the class BpmnProcessCompiler method from.

public List<BpmnProcess> from(ProcessConfig config, Resource... resources) {
    try {
        List<Process> processes = new ArrayList<>();
        for (Resource resource : resources) {
            XmlProcessReader xmlReader = new XmlProcessReader(getSemanticModules(), Thread.currentThread().getContextClassLoader());
            configureProcessReader(xmlReader, config);
            processes.addAll(xmlReader.read(resource.getReader()));
        }
        List<BpmnProcess> bpmnProcesses = processes.stream().map(p -> create(p, config)).filter(p -> p != null).collect(Collectors.toList());
        bpmnProcesses.forEach(p -> {
            for (Node node : ((WorkflowProcess) p.process()).getNodesRecursively()) {
                processNode(node, bpmnProcesses);
            }
        });
        return (List<BpmnProcess>) bpmnProcesses;
    } catch (Exception e) {
        throw new BpmnProcessReaderException(e);
    }
}
Also used : SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) SemanticModule(io.automatiko.engine.workflow.compiler.xml.SemanticModule) SemanticModules(io.automatiko.engine.workflow.compiler.xml.SemanticModules) XmlProcessReader(io.automatiko.engine.workflow.compiler.xml.XmlProcessReader) ProcessConfig(io.automatiko.engine.api.workflow.ProcessConfig) Collectors(java.util.stream.Collectors) BPMNSemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNSemanticModule) Node(io.automatiko.engine.api.definition.process.Node) ArrayList(java.util.ArrayList) Resource(io.automatiko.engine.api.io.Resource) List(java.util.List) BPMNDISemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNDISemanticModule) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) Process(io.automatiko.engine.api.definition.process.Process) BPMNExtensionsSemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNExtensionsSemanticModule) XmlProcessReader(io.automatiko.engine.workflow.compiler.xml.XmlProcessReader) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) Node(io.automatiko.engine.api.definition.process.Node) ArrayList(java.util.ArrayList) Resource(io.automatiko.engine.api.io.Resource) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) Process(io.automatiko.engine.api.definition.process.Process) ArrayList(java.util.ArrayList) List(java.util.List) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess)

Example 10 with ProcessConfig

use of io.automatiko.engine.api.workflow.ProcessConfig in project automatiko-engine by automatiko-io.

the class EventStateWorkflowsTest method testEventStateWorkflow.

@Test
public void testEventStateWorkflow() throws Exception {
    ProcessConfig processConfig = ServerlessProcess.processConfig();
    ((DefaultWorkItemHandlerConfig) processConfig.workItemHandlers()).register("Service Task", new WorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            System.out.println(workItem.getParameters());
            ObjectMapper mapper = new ObjectMapper();
            ObjectNode data = mapper.createObjectNode();
            data.put("greeting", "Hello " + ((TextNode) workItem.getParameter("name")).asText());
            manager.completeWorkItem(workItem.getId(), Collections.singletonMap(JsonVariableScope.WORKFLOWDATA_KEY, data));
        }

        @Override
        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
        }
    });
    ServerlessProcess process = ServerlessProcess.from(processConfig, new ClassPathResource("event-state/event-state-greeting2.json")).get(0);
    assertThat(process).isNotNull();
    ServerlessProcessInstance pi = (ServerlessProcessInstance) process.createInstance();
    pi.start();
    JsonNode data = new ObjectMapper().readTree("{\n" + "  \"data\": {\"greet\" : { \"name\" : \"john\"}}\n" + "}");
    pi.send(Sig.of("Message-GreetingEvent", data));
    assertThat(pi.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    assertThat(pi.variables().toMap()).hasSize(3).containsKey("greeting").extracting("greeting").isEqualTo(new TextNode("Hello john"));
}
Also used : ProcessConfig(io.automatiko.engine.api.workflow.ProcessConfig) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) DefaultWorkItemHandlerConfig(io.automatiko.engine.workflow.DefaultWorkItemHandlerConfig) ClassPathResource(io.automatiko.engine.services.io.ClassPathResource) WorkItemHandler(io.automatiko.engine.api.runtime.process.WorkItemHandler) WorkItemManager(io.automatiko.engine.api.runtime.process.WorkItemManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessConfig (io.automatiko.engine.api.workflow.ProcessConfig)13 Test (org.junit.jupiter.api.Test)11 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)7 DefaultWorkItemHandlerConfig (io.automatiko.engine.workflow.DefaultWorkItemHandlerConfig)7 BpmnProcess (io.automatiko.engine.workflow.bpmn2.BpmnProcess)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 TextNode (com.fasterxml.jackson.databind.node.TextNode)5 WorkItemHandler (io.automatiko.engine.api.runtime.process.WorkItemHandler)5 WorkItemManager (io.automatiko.engine.api.runtime.process.WorkItemManager)5 ClassPathResource (io.automatiko.engine.services.io.ClassPathResource)5 BpmnVariables (io.automatiko.engine.workflow.bpmn2.BpmnVariables)4 TestWorkItemHandler (io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler)4 HashMap (java.util.HashMap)4 DefaultProcessEventListener (io.automatiko.engine.api.event.process.DefaultProcessEventListener)2 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)2 CollectingUnitOfWorkFactory (io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory)2 DefaultUnitOfWorkManager (io.automatiko.engine.services.uow.DefaultUnitOfWorkManager)2 DefaultProcessEventListenerConfig (io.automatiko.engine.workflow.DefaultProcessEventListenerConfig)2