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);
}
}
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();
}
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();
}
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));
}
}
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"));
}
Aggregations