Search in sources :

Example 11 with WorkItem

use of io.automatiko.engine.api.runtime.process.WorkItem in project automatiko-engine by automatiko-io.

the class ProtobufProcessMarshaller method readWorkItems.

public void readWorkItems(MarshallerReaderContext context) throws IOException {
    AutomatikoMessages.ProcessData _pdata = (AutomatikoMessages.ProcessData) context.parameterObject;
    InternalProcessRuntime wm = context.getProcessRuntime();
    for (AutomatikoMessages.WorkItem _workItem : _pdata.getExtension(AutomatikoMessages.workItem)) {
        WorkItem workItem = readWorkItem(context, _workItem);
        ((DefaultWorkItemManager) wm.getWorkItemManager()).internalAddWorkItem((WorkItem) workItem);
    }
}
Also used : DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem)

Example 12 with WorkItem

use of io.automatiko.engine.api.runtime.process.WorkItem in project automatiko-engine by automatiko-io.

the class WorkItemNodeInstance method cancel.

@Override
public void cancel() {
    WorkItem item = getWorkItem();
    if (item != null && item.getState() != COMPLETED && item.getState() != ABORTED) {
        try {
            ((DefaultWorkItemManager) getProcessInstance().getProcessRuntime().getWorkItemManager()).internalAbortWorkItem(item.getId());
        } catch (WorkItemHandlerNotFoundException wihnfe) {
            getProcessInstance().setState(STATE_ABORTED);
            throw wihnfe;
        }
    }
    if (exceptionHandlingProcessInstanceId != null) {
        ProcessInstance processInstance = (ProcessInstance) getProcessInstance().getProcessRuntime().getProcessInstance(exceptionHandlingProcessInstanceId);
        if (processInstance != null) {
            processInstance.setState(STATE_ABORTED);
        }
    }
    super.cancel();
}
Also used : DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem)

Example 13 with WorkItem

use of io.automatiko.engine.api.runtime.process.WorkItem in project automatiko-engine by automatiko-io.

the class WorkItemNodeInstance method getNodeName.

@Override
public String getNodeName() {
    Node node = getNode();
    if (node == null) {
        String nodeName = "[Dynamic]";
        WorkItem item = getWorkItem();
        if (item != null) {
            nodeName += " " + item.getParameter("TaskName");
        }
        return nodeName;
    }
    return super.getNodeName();
}
Also used : WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem)

Example 14 with WorkItem

use of io.automatiko.engine.api.runtime.process.WorkItem in project automatiko-engine by automatiko-io.

the class ProtobufProcessMarshaller method writeWorkItems.

public void writeWorkItems(MarshallerWriteContext context) throws IOException {
    AutomatikoMessages.ProcessData.Builder _pdata = (AutomatikoMessages.ProcessData.Builder) context.parameterObject;
    List<WorkItem> workItems = new ArrayList<WorkItem>(((DefaultWorkItemManager) context.getProcessRuntime().getWorkItemManager()).getWorkItems());
    Collections.sort(workItems, new Comparator<WorkItem>() {

        public int compare(WorkItem o1, WorkItem o2) {
            return (int) (o2.getId().compareTo(o1.getId()));
        }
    });
    for (WorkItem workItem : workItems) {
        _pdata.addExtension(AutomatikoMessages.workItem, writeWorkItemInstance(context, workItem));
    }
}
Also used : ArrayList(java.util.ArrayList) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem)

Example 15 with WorkItem

use of io.automatiko.engine.api.runtime.process.WorkItem 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

WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)22 ProcessConfig (io.automatiko.engine.api.workflow.ProcessConfig)7 Test (org.junit.jupiter.api.Test)7 WorkItemHandler (io.automatiko.engine.api.runtime.process.WorkItemHandler)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 WorkItemManager (io.automatiko.engine.api.runtime.process.WorkItemManager)5 ClassPathResource (io.automatiko.engine.services.io.ClassPathResource)5 DefaultWorkItemHandlerConfig (io.automatiko.engine.workflow.DefaultWorkItemHandlerConfig)5 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)4 ArrayList (java.util.ArrayList)4 HumanTaskWorkItem (io.automatiko.engine.api.runtime.process.HumanTaskWorkItem)3 HashMap (java.util.HashMap)3 DelayedExecution (io.automatiko.engine.api.event.process.DelayedExecution)2 ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)2 ProcessEventListener (io.automatiko.engine.api.event.process.ProcessEventListener)2 ProcessNodeInstanceFailedEvent (io.automatiko.engine.api.event.process.ProcessNodeInstanceFailedEvent)2 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)2