Search in sources :

Example 1 with UserTaskInstanceDataEvent

use of io.automatiko.engine.services.event.UserTaskInstanceDataEvent in project automatiko-engine by automatiko-io.

the class PublishEventTest method assertUserTaskInstanceEvent.

protected UserTaskInstanceEventBody assertUserTaskInstanceEvent(DataEvent<?> event, String taskName, String taskDescription, String taskPriority, String taskState, String processId) {
    assertThat(event).isInstanceOf(UserTaskInstanceDataEvent.class);
    UserTaskInstanceEventBody body = ((UserTaskInstanceDataEvent) event).getData();
    assertThat(body).isNotNull();
    assertThat(body.getId()).isNotNull();
    assertThat(body.getTaskName()).isEqualTo(taskName);
    assertThat(body.getTaskDescription()).isEqualTo(taskDescription);
    assertThat(body.getTaskPriority()).isEqualTo(taskPriority);
    assertThat(body.getStartDate()).isNotNull();
    assertThat(body.getState()).isEqualTo(taskState);
    if (taskState.equals("Completed")) {
        assertThat(body.getCompleteDate()).isNotNull();
    } else {
        assertThat(body.getCompleteDate()).isNull();
    }
    assertThat(event.getSource()).isEqualTo("http://myhost/" + processId);
    assertThat(event.getTime()).doesNotContain("[");
    return body;
}
Also used : UserTaskInstanceEventBody(io.automatiko.engine.services.event.impl.UserTaskInstanceEventBody) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent)

Example 2 with UserTaskInstanceDataEvent

use of io.automatiko.engine.services.event.UserTaskInstanceDataEvent in project automatiko-engine by automatiko-io.

the class GraphQLUserTaskSubscriptionEventPublisher method process.

@Override
public void process(DataEvent<?> event) {
    if (event instanceof UserTaskInstanceDataEvent) {
        UserTaskInstanceDataEvent utEvent = (UserTaskInstanceDataEvent) event;
        userTasksProcessor.onNext(new UserTaskEventInput(utEvent.getData()), utEvent.getData().sourceInstance());
    }
}
Also used : UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent)

Example 3 with UserTaskInstanceDataEvent

use of io.automatiko.engine.services.event.UserTaskInstanceDataEvent in project automatiko-engine by automatiko-io.

the class ProcessInstanceEventBatch method events.

@Override
public Collection<DataEvent<?>> events() {
    Map<String, ProcessInstanceEventBody> processInstances = new LinkedHashMap<>();
    Map<String, UserTaskInstanceEventBody> userTaskInstances = new LinkedHashMap<>();
    Set<VariableInstanceEventBody> variables = new LinkedHashSet<>();
    for (ProcessEvent event : rawEvents) {
        ProcessInstanceEventBody body = processInstances.computeIfAbsent(event.getProcessInstance().getId(), key -> create(event));
        if (event instanceof ProcessNodeTriggeredEvent) {
            handleProcessNodeTriggeredEvent((ProcessNodeTriggeredEvent) event, body);
        } else if (event instanceof ProcessNodeLeftEvent) {
            handleProcessNodeLeftEvent((ProcessNodeLeftEvent) event, body);
        } else if (event instanceof ProcessCompletedEvent) {
            handleProcessCompletedEvent((ProcessCompletedEvent) event, body);
        } else if (event instanceof ProcessWorkItemTransitionEvent) {
            handleProcessWorkItemTransitionEvent((ProcessWorkItemTransitionEvent) event, userTaskInstances);
        } else if (event instanceof ProcessVariableChangedEvent) {
            handleProcessVariableChangedEvent((ProcessVariableChangedEvent) event, variables);
        }
    }
    Collection<DataEvent<?>> processedEvents = new ArrayList<>();
    processInstances.values().stream().map(pi -> new ProcessInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
    userTaskInstances.values().stream().map(pi -> new UserTaskInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
    variables.stream().map(pi -> new VariableInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
    return processedEvents;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) DataEvent(io.automatiko.engine.api.event.DataEvent) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) WorkUnit(io.automatiko.engine.api.uow.WorkUnit) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) Map(java.util.Map) LinkedHashSet(java.util.LinkedHashSet) ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) Addons(io.automatiko.engine.api.Addons) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) ProcessEvent(io.automatiko.engine.api.event.process.ProcessEvent) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) Collection(java.util.Collection) Tag(io.automatiko.engine.api.workflow.Tag) Set(java.util.Set) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) VariableInstanceDataEvent(io.automatiko.engine.services.event.VariableInstanceDataEvent) Base64(java.util.Base64) List(java.util.List) ProcessNodeEvent(io.automatiko.engine.api.event.process.ProcessNodeEvent) EventBatch(io.automatiko.engine.api.event.EventBatch) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) ProcessEvent(io.automatiko.engine.api.event.process.ProcessEvent) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) ArrayList(java.util.ArrayList) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) VariableInstanceDataEvent(io.automatiko.engine.services.event.VariableInstanceDataEvent) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) LinkedHashMap(java.util.LinkedHashMap) VariableInstanceDataEvent(io.automatiko.engine.services.event.VariableInstanceDataEvent) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent)

Example 4 with UserTaskInstanceDataEvent

use of io.automatiko.engine.services.event.UserTaskInstanceDataEvent in project automatiko-engine by automatiko-io.

the class WebSocketEventPublisher method publish.

@Override
public void publish(DataEvent<?> event) {
    if (event instanceof ProcessInstanceDataEvent && !config.instance().orElse(true)) {
        LOGGER.debug("Skipping process instance event as the publisher should not deal with instances");
        return;
    } else if (event instanceof UserTaskInstanceDataEvent && !config.tasks().orElse(true)) {
        LOGGER.debug("Skipping user task event as the publisher should not deal with tasks");
        return;
    }
    String text;
    try {
        text = json.writeValueAsString(event);
        for (Session session : sessions.values()) {
            String filter = (String) session.getUserProperties().get("atk_filter");
            if (filter != null && !filter.matches(event.getType())) {
                continue;
            }
            boolean allowed = true;
            IdentityProvider identityProvider = (IdentityProvider) session.getUserProperties().get("atk_identity");
            if (event instanceof ProcessInstanceDataEvent) {
                List<String> visibleTo = ((ProcessInstanceDataEvent) event).getData().getVisibleTo();
                allowed = visibleTo.isEmpty() || visibleTo.contains(identityProvider.getName()) || visibleTo.stream().anyMatch(item -> identityProvider.getRoles().contains(item));
            } else if (event instanceof UserTaskInstanceDataEvent) {
                HumanTaskWorkItem workItem = ((UserTaskInstanceDataEvent) event).getData().sourceInstance();
                allowed = workItem.enforce(SecurityPolicy.of(identityProvider));
            }
            if (allowed) {
                session.getAsyncRemote().sendText(text);
            }
        }
    } catch (Exception e) {
        LOGGER.error("Unexpected error when publishing websocket event", e);
    }
}
Also used : HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) Session(javax.websocket.Session)

Example 5 with UserTaskInstanceDataEvent

use of io.automatiko.engine.services.event.UserTaskInstanceDataEvent in project automatiko-engine by automatiko-io.

the class ElasticEventPublisher method publish.

@Override
public void publish(DataEvent<?> event) {
    try {
        Request request;
        Map<String, Object> payload;
        if (event instanceof ProcessInstanceDataEvent) {
            ProcessInstanceDataEvent pevent = (ProcessInstanceDataEvent) event;
            if (config.instance().orElse(true)) {
                Map<String, Object> metadata = new LinkedHashMap<>();
                metadata.put("instanceId", pevent.getData().getId());
                metadata.put("processId", pevent.getData().getProcessId());
                metadata.put("rootInstanceId", pevent.getData().getRootInstanceId());
                metadata.put("rootProcessId", pevent.getData().getRootProcessId());
                metadata.put("parentInstanceId", pevent.getData().getParentInstanceId());
                metadata.put("businessKey", pevent.getData().getBusinessKey());
                metadata.put("state", pevent.getData().getState());
                metadata.put("tags", pevent.getData().getTags());
                if (pevent.getData().getRoles() != null) {
                    metadata.put("roles", pevent.getData().getRoles());
                }
                if (pevent.getData().getVisibleTo() != null) {
                    metadata.put("visibleTo", pevent.getData().getVisibleTo());
                }
                metadata.put("startDate", pevent.getData().getStartDate());
                metadata.put("endDate", pevent.getData().getEndDate());
                payload = new LinkedHashMap<>(pevent.getData().getVariables());
                payload.put("_metadata", metadata);
                request = new Request("PUT", "/" + pevent.getData().sourceInstance().process().id() + "/_doc/" + pevent.getData().getId());
                request.setJsonEntity(mapper.writeValueAsString(payload));
                sendRequest(request, event);
            }
            if (config.audit().orElse(false)) {
                String index = config.auditIndex().orElse("atk_audit");
                StringBuilder bulkRequestBody = new StringBuilder();
                for (NodeInstanceEventBody nevent : pevent.getData().getNodeInstances()) {
                    String actionMetaData = String.format("{ \"index\" : { \"_index\" : \"%s\", \"_id\" : \"%s\" } }%n", index, nevent.getId());
                    Map<String, Object> audit = new LinkedHashMap<>();
                    audit.put("instanceId", pevent.getData().getId());
                    audit.put("processId", pevent.getData().getProcessId());
                    audit.put("rootInstanceId", pevent.getData().getRootInstanceId());
                    audit.put("rootProcessId", pevent.getData().getRootProcessId());
                    audit.put("parentInstanceId", pevent.getData().getParentInstanceId());
                    audit.put("businessKey", pevent.getData().getBusinessKey());
                    audit.put("nodeDefinitionId", nevent.getNodeDefinitionId());
                    audit.put("nodeId", nevent.getNodeId());
                    audit.put("nodeName", nevent.getNodeName());
                    audit.put("nodeType", nevent.getNodeType());
                    audit.put("triggerTime", nevent.getTriggerTime());
                    audit.put("leaveTime", nevent.getLeaveTime());
                    bulkRequestBody.append(actionMetaData);
                    bulkRequestBody.append(mapper.writeValueAsString(audit));
                    bulkRequestBody.append("\n");
                }
                request = new Request("POST", "/" + index + "/_bulk");
                request.setJsonEntity(bulkRequestBody.toString());
                sendRequest(request, event);
            }
        } else if (event instanceof UserTaskInstanceDataEvent && config.tasks().orElse(true)) {
            UserTaskInstanceDataEvent uevent = (UserTaskInstanceDataEvent) event;
            Set<String> potentialOwners = new LinkedHashSet<String>();
            if (uevent.getData().getPotentialUsers() != null) {
                potentialOwners.addAll(uevent.getData().getPotentialUsers());
            }
            if (uevent.getData().getPotentialGroups() != null) {
                potentialOwners.addAll(uevent.getData().getPotentialGroups());
            }
            if (uevent.getData().getAdminUsers() != null) {
                potentialOwners.addAll(uevent.getData().getAdminUsers());
            }
            if (uevent.getData().getAdminGroups() != null) {
                potentialOwners.addAll(uevent.getData().getAdminUsers());
            }
            // remove any excluded users known
            if (uevent.getData().getExcludedUsers() != null) {
                potentialOwners.removeAll(uevent.getData().getExcludedUsers());
            }
            Map<String, Object> metadata = new LinkedHashMap<>();
            metadata.put("processInstanceId", uevent.getData().getProcessInstanceId());
            metadata.put("processId", uevent.getData().getProcessId());
            metadata.put("rootInstanceId", uevent.getData().getRootProcessInstanceId());
            metadata.put("rootProcessId", uevent.getData().getRootProcessId());
            metadata.put("referenceName", uevent.getData().getReferenceName());
            payload = new LinkedHashMap<>();
            payload.put("instanceId", uevent.getData().getId());
            payload.put("name", uevent.getData().getTaskName());
            payload.put("description", uevent.getData().getTaskDescription());
            payload.put("state", uevent.getData().getState());
            payload.put("owner", uevent.getData().getActualOwner());
            payload.put("potentialOwners", potentialOwners);
            payload.put("excludedUsers", uevent.getData().getExcludedUsers());
            payload.put("startDate", uevent.getData().getStartDate());
            payload.put("endDate", uevent.getData().getCompleteDate());
            payload.put("inputs", uevent.getData().getInputs());
            payload.put("outputs", uevent.getData().getOutputs());
            payload.put("_metadata", metadata);
            request = new Request("PUT", "/tasks/_doc/" + uevent.getData().getId());
            request.setJsonEntity(mapper.writeValueAsString(payload));
            sendRequest(request, event);
        } else {
            return;
        }
    } catch (IOException e) {
        LOGGER.error("Error when publishing event to elastic", e);
    }
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Request(org.elasticsearch.client.Request) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) NodeInstanceEventBody(io.automatiko.engine.services.event.impl.NodeInstanceEventBody) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

UserTaskInstanceDataEvent (io.automatiko.engine.services.event.UserTaskInstanceDataEvent)5 ProcessInstanceDataEvent (io.automatiko.engine.services.event.ProcessInstanceDataEvent)3 HumanTaskWorkItem (io.automatiko.engine.api.runtime.process.HumanTaskWorkItem)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 Addons (io.automatiko.engine.api.Addons)1 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)1 DataEvent (io.automatiko.engine.api.event.DataEvent)1 EventBatch (io.automatiko.engine.api.event.EventBatch)1 ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)1 ProcessEvent (io.automatiko.engine.api.event.process.ProcessEvent)1 ProcessNodeEvent (io.automatiko.engine.api.event.process.ProcessNodeEvent)1 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)1 ProcessNodeTriggeredEvent (io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent)1 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)1 ProcessWorkItemTransitionEvent (io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent)1 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)1 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)1