use of io.automatiko.engine.api.workflow.EventDescription in project automatiko-engine by automatiko-io.
the class SignalEventTest method testBoundarySignalEventWithData.
@Test
public void testBoundarySignalEventWithData() throws Exception {
Application app = generateCode(Collections.singletonList("signalevent/BoundarySignalEventOnTask.bpmn2"), Collections.singletonList("ruletask/BusinessRuleTask.drl"));
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("BoundarySignalOnTask");
Model m = p.createModel();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Set<EventDescription<?>> eventDescriptions = processInstance.events();
assertThat(eventDescriptions).hasSize(2).extracting("event").contains("MySignal", "workItemCompleted");
assertThat(eventDescriptions).extracting("eventType").contains("signal", "workItem");
assertThat(eventDescriptions).extracting("dataType").hasAtLeastOneElementOfType(GroupedNamedDataType.class);
assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.id());
processInstance.send(Sig.of("MySignal", "test"));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKey("x");
assertThat(result.toMap().get("x")).isEqualTo("test");
assertThat(p.instances().values(1, 10)).hasSize(0);
}
use of io.automatiko.engine.api.workflow.EventDescription in project automatiko-engine by automatiko-io.
the class SignalEventTest method testIntermediateSignalEventWithData.
@Test
public void testIntermediateSignalEventWithData() throws Exception {
Application app = generateCode(Collections.singletonList("signalevent/IntermediateCatchEventSignal.bpmn2"), Collections.singletonList("ruletask/BusinessRuleTask.drl"));
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("IntermediateCatchEvent");
Model m = p.createModel();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Set<EventDescription<?>> eventDescriptions = processInstance.events();
assertThat(eventDescriptions).hasSize(1).extracting("event").contains("workItemCompleted");
assertThat(eventDescriptions).extracting("eventType").contains("workItem");
assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.id());
List<WorkItem> workItems = processInstance.workItems();
assertThat(workItems).hasSize(1);
processInstance.completeWorkItem(workItems.get(0).getId(), null);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
eventDescriptions = processInstance.events();
assertThat(eventDescriptions).hasSize(1).extracting("event").contains("MyMessage");
assertThat(eventDescriptions).extracting("eventType").contains("signal");
assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.id());
processInstance.send(Sig.of("MyMessage", "test"));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKey("x");
assertThat(result.toMap().get("x")).isEqualTo("test");
assertThat(p.instances().values(1, 10)).hasSize(0);
}
use of io.automatiko.engine.api.workflow.EventDescription in project automatiko-engine by automatiko-io.
the class WorkflowProcessInstanceImpl method getEventDescriptions.
@Override
public Set<EventDescription<?>> getEventDescriptions() {
if (getState() == ProcessInstance.STATE_COMPLETED || getState() == ProcessInstance.STATE_ABORTED) {
return Collections.emptySet();
}
VariableScope variableScope = (VariableScope) ((ContextContainer) getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
Set<EventDescription<?>> eventDesciptions = new LinkedHashSet<>();
List<EventListener> activeListeners = eventListeners.values().stream().flatMap(List::stream).collect(Collectors.toList());
activeListeners.addAll(externalEventListeners.values().stream().flatMap(List::stream).collect(Collectors.toList()));
activeListeners.forEach(el -> eventDesciptions.addAll(el.getEventDescriptions()));
((io.automatiko.engine.workflow.process.core.WorkflowProcess) getProcess()).getNodesRecursively().stream().filter(n -> n instanceof EventNodeInterface).forEach(n -> {
NamedDataType dataType = null;
if (((EventNodeInterface) n).getVariableName() != null) {
Map<String, Object> dataOutputs = (Map<String, Object>) n.getMetaData().get("DataOutputs");
if (dataOutputs != null) {
for (Entry<String, Object> dOut : dataOutputs.entrySet()) {
dataType = new NamedDataType(dOut.getKey(), dOut.getValue());
}
} else {
Variable eventVar = variableScope.findVariable(((EventNodeInterface) n).getVariableName());
if (eventVar != null) {
dataType = new NamedDataType(eventVar.getName(), eventVar.getType());
}
}
}
if (n instanceof BoundaryEventNode) {
BoundaryEventNode boundaryEventNode = (BoundaryEventNode) n;
StateBasedNodeInstance attachedToNodeInstance = (StateBasedNodeInstance) getNodeInstances(true).stream().filter(ni -> ni.getNode().getMetaData().get(UNIQUE_ID).equals(boundaryEventNode.getAttachedToNodeId())).findFirst().orElse(null);
if (attachedToNodeInstance != null) {
Map<String, String> properties = new HashMap<>();
properties.put("AttachedToID", attachedToNodeInstance.getNodeDefinitionId());
properties.put("AttachedToName", attachedToNodeInstance.getNodeName());
String eventType = EVENT_TYPE_SIGNAL;
String eventName = boundaryEventNode.getType();
Map<String, String> timerProperties = attachedToNodeInstance.extractTimerEventInformation();
if (timerProperties != null) {
properties.putAll(timerProperties);
eventType = "timer";
eventName = "timerTriggered";
}
eventDesciptions.add(new BaseEventDescription(eventName, (String) n.getMetaData().get(UNIQUE_ID), n.getName(), eventType, null, getId(), dataType, properties));
}
} else if (n instanceof EventSubProcessNode) {
EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) n;
boolean isContainerActive = false;
if (eventSubProcessNode.getParentContainer() instanceof WorkflowProcess) {
isContainerActive = true;
} else if (eventSubProcessNode.getParentContainer() instanceof CompositeNode) {
isContainerActive = !getNodeInstances(((CompositeNode) eventSubProcessNode.getParentContainer()).getId()).isEmpty();
}
if (isContainerActive) {
Node startNode = eventSubProcessNode.findStartNode();
Map<Timer, ProcessAction> timers = eventSubProcessNode.getTimers();
if (timers != null && !timers.isEmpty()) {
getNodeInstances(eventSubProcessNode.getId()).forEach(ni -> {
Map<String, String> timerProperties = ((StateBasedNodeInstance) ni).extractTimerEventInformation();
if (timerProperties != null) {
eventDesciptions.add(new BaseEventDescription("timerTriggered", (String) startNode.getMetaData().get("UniqueId"), startNode.getName(), "timer", ni.getId(), getId(), null, timerProperties));
}
});
} else {
for (String eventName : eventSubProcessNode.getEvents()) {
if ("variableChanged".equals(eventName)) {
continue;
}
eventDesciptions.add(new BaseEventDescription(eventName, (String) startNode.getMetaData().get("UniqueId"), startNode.getName(), "signal", null, getId(), dataType));
}
}
}
} else if (n instanceof EventNode) {
NamedDataType finalDataType = dataType;
getNodeInstances(n.getId()).forEach(ni -> eventDesciptions.add(new BaseEventDescription(((EventNode) n).getType(), (String) n.getMetaData().get(UNIQUE_ID), n.getName(), (String) n.getMetaData().getOrDefault(EVENT_TYPE, EVENT_TYPE_SIGNAL), ni.getId(), getId(), finalDataType)));
} else if (n instanceof StateNode) {
getNodeInstances(n.getId()).forEach(ni -> eventDesciptions.add(new BaseEventDescription((String) n.getMetaData().get(CONDITION), (String) n.getMetaData().get(UNIQUE_ID), n.getName(), (String) n.getMetaData().getOrDefault(EVENT_TYPE, EVENT_TYPE_SIGNAL), ni.getId(), getId(), null)));
}
});
return eventDesciptions;
}
Aggregations