use of io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance in project automatiko-engine by automatiko-io.
the class ParticipantsAccessPolicy method whenInitiatorNotSetOrAsIdentity.
@SuppressWarnings("unchecked")
protected boolean whenInitiatorNotSetOrAsIdentity(IdentityProvider identityProvider, ProcessInstance<T> instance) {
if (identityProvider.isAdmin()) {
return true;
}
WorkflowProcessInstance pi = (WorkflowProcessInstance) ((AbstractProcessInstance<?>) instance).processInstance();
if (pi.getInitiator() == null || pi.getInitiator().isEmpty() || pi.getInitiator().equals(identityProvider.getName())) {
return true;
}
// next check if the user/group is assigned to any of the active user tasks that
// can make it eligible to access the instance
boolean result = ((WorkflowProcessInstanceImpl) pi).getNodeInstances(true).stream().filter(ni -> ni instanceof HumanTaskNodeInstance).anyMatch(ni -> {
HumanTaskWorkItem workitem = (HumanTaskWorkItem) ((HumanTaskNodeInstance) ni).getWorkItem();
return workitem.enforce(SecurityPolicy.of(identityProvider));
});
if (!result) {
result = instance.subprocesses().stream().anyMatch(spi -> whenInitiatorNotSetOrAsIdentity(identityProvider, (ProcessInstance<T>) spi));
}
return result;
}
use of io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance in project automatiko-engine by automatiko-io.
the class CompositeNodeInstance method signalEvent.
@Override
public void signalEvent(String type, Object event) {
List<NodeInstance> currentView = new ArrayList<>(this.nodeInstances);
super.signalEvent(type, event);
for (Node node : getCompositeNode().internalGetNodes()) {
if (node instanceof EventNodeInterface && ((EventNodeInterface) node).acceptsEvent(type, event)) {
if (node instanceof EventNode && ((EventNode) node).getFrom() == null || node instanceof EventSubProcessNode) {
EventNodeInstanceInterface eventNodeInstance = (EventNodeInstanceInterface) getNodeInstance(node);
eventNodeInstance.signalEvent(type, event);
} else {
List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView);
if (nodeInstances != null && !nodeInstances.isEmpty()) {
for (NodeInstance nodeInstance : nodeInstances) {
((EventNodeInstanceInterface) nodeInstance).signalEvent(type, event);
}
}
}
}
if (type.equals(node.getName()) && node.getIncomingConnections().isEmpty()) {
NodeInstance nodeInstance = getNodeInstance(node);
if (nodeInstance != null) {
if (event != null) {
Map<String, Object> dynamicParams = new HashMap<>(getProcessInstance().getVariables());
if (event instanceof Map) {
dynamicParams.putAll((Map<String, Object>) event);
} else if (event instanceof WorkflowProcessInstance) {
// ignore variables of process instance type
} else {
dynamicParams.put("Data", event);
}
nodeInstance.setDynamicParameters(dynamicParams);
}
nodeInstance.trigger(null, null);
}
}
}
}
use of io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance in project automatiko-engine by automatiko-io.
the class WorkItemTest method testMockDataWorkItemHandlerCustomFunction.
@Test
public void testMockDataWorkItemHandlerCustomFunction() {
String processId = "org.company.actions";
String workName = "Unnexistent Task";
ExecutableProcess process = getWorkItemProcess(processId, workName);
InternalProcessRuntime ksession = createProcessRuntime(process);
ksession.getWorkItemManager().registerWorkItemHandler(workName, new MockDataWorkItemHandler((input) -> {
Map<String, Object> output = new HashMap<String, Object>();
if ("John Doe".equals(input.get("Comment"))) {
output.put("Result", "one");
} else {
output.put("Result", "two");
}
return output;
}));
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Doe"));
ProcessInstance processInstance = ksession.startProcess("org.company.actions", parameters);
Object numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
assertNotNull(numberVariable);
assertEquals("one", numberVariable);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Deen"));
processInstance = ksession.startProcess("org.company.actions", parameters);
numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
assertNotNull(numberVariable);
assertEquals("two", numberVariable);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance in project automatiko-engine by automatiko-io.
the class WorkItemTest method testMockDataWorkItemHandler.
@Test
public void testMockDataWorkItemHandler() {
String processId = "org.company.actions";
String workName = "Unnexistent Task";
ExecutableProcess process = getWorkItemProcess(processId, workName);
InternalProcessRuntime ksession = createProcessRuntime(process);
Map<String, Object> output = new HashMap<String, Object>();
output.put("Result", "test");
ksession.getWorkItemManager().registerWorkItemHandler(workName, new MockDataWorkItemHandler(output));
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Doe"));
ProcessInstance processInstance = ksession.startProcess("org.company.actions", parameters);
Object numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
assertNotNull(numberVariable);
assertEquals("test", numberVariable);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance in project automatiko-engine by automatiko-io.
the class WorkflowProcessInstanceImpl method signalEvent.
@Override
@SuppressWarnings("unchecked")
public void signalEvent(String type, Object event) {
logger.debug("Signal {} received with data {} in process instance {}", type, event, getId());
synchronized (this) {
if (getState() != ProcessInstance.STATE_ACTIVE) {
return;
}
InternalProcessRuntime processRuntime = getProcessRuntime();
processRuntime.getProcessEventSupport().fireBeforeProcessSignaled(type, event, this, processRuntime);
if ("timerTriggered".equals(type)) {
TimerInstance timer = (TimerInstance) event;
if (timer.getId().equals(slaTimerId)) {
handleSLAViolation();
// no need to pass the event along as it was purely for SLA tracking
return;
}
}
if ("slaViolation".equals(type)) {
handleSLAViolation();
// no need to pass the event along as it was purely for SLA tracking
return;
}
List<NodeInstance> currentView = new ArrayList<>(this.nodeInstances);
try {
this.activatingNodeIds = new ArrayList<>();
List<EventListener> listeners = eventListeners.get(type);
if (listeners != null) {
for (EventListener listener : listeners) {
listener.signalEvent(type, event);
}
}
listeners = externalEventListeners.get(type);
if (listeners != null) {
for (EventListener listener : listeners) {
listener.signalEvent(type, event);
}
}
if (!type.startsWith("Compensation")) {
for (Node node : getWorkflowProcess().getNodes()) {
if (node instanceof EventNodeInterface && ((EventNodeInterface) node).acceptsEvent(type, event, getResolver(node, currentView))) {
if (node instanceof EventNode && ((EventNode) node).getFrom() == null) {
EventNodeInstance eventNodeInstance = (EventNodeInstance) getNodeInstance(node);
eventNodeInstance.signalEvent(type, event);
} else {
if (node instanceof EventSubProcessNode && (resolveVariables(((EventSubProcessNode) node).getEvents()).contains(type))) {
EventSubProcessNodeInstance eventNodeInstance = (EventSubProcessNodeInstance) getNodeInstance(node);
eventNodeInstance.signalEvent(type, event);
} else {
List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView);
if (nodeInstances != null && !nodeInstances.isEmpty()) {
for (NodeInstance nodeInstance : nodeInstances) {
((EventNodeInstanceInterface) nodeInstance).signalEvent(type, event);
}
}
}
}
} else if (node instanceof StartNode && ((StartNode) node).getTriggers() != null) {
boolean accepted = ((StartNode) node).getTriggers().stream().filter(EventTrigger.class::isInstance).anyMatch(t -> ((EventTrigger) t).getEventFilters().stream().anyMatch(e -> e.acceptsEvent(type, event)));
if (accepted && node.getMetaData().get("acceptStartSignal") != null) {
StartNodeInstance startNodeInstance = (StartNodeInstance) getNodeInstance(node);
startNodeInstance.signalEvent(type, event);
}
}
}
if (((io.automatiko.engine.workflow.process.core.WorkflowProcess) getWorkflowProcess()).isDynamic()) {
for (Node node : getWorkflowProcess().getNodes()) {
if (node.hasMatchingEventListner(type) && node.getIncomingConnections().isEmpty()) {
NodeInstance nodeInstance = getNodeInstance(node);
if (nodeInstance != null) {
if (event != null) {
Map<String, Object> dynamicParams = new HashMap<>(getVariables());
if (event instanceof Map) {
dynamicParams.putAll((Map<String, Object>) event);
} else if (event instanceof WorkflowProcessInstance) {
// ignore variables of process instance type
} else {
dynamicParams.put("Data", event);
}
nodeInstance.setDynamicParameters(dynamicParams);
}
nodeInstance.trigger(null, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
}
} else if (this instanceof ExecutableProcessInstance && node instanceof CompositeNode) {
Optional<NodeInstance> instance = this.nodeInstances.stream().filter(ni -> ni.getNodeId() == node.getId()).findFirst();
instance.ifPresent(n -> ((CompositeNodeInstance) n).signalEvent(type, event));
}
}
}
}
} finally {
processRuntime.getProcessEventSupport().fireAfterProcessSignaled(type, event, this, processRuntime);
if (this.activatingNodeIds != null) {
this.activatingNodeIds.clear();
this.activatingNodeIds = null;
}
}
}
}
Aggregations