Search in sources :

Example 6 with WorkflowProcessInstanceImpl

use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl 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;
}
Also used : HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) SecurityPolicy(io.automatiko.engine.api.auth.SecurityPolicy) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) Set(java.util.Set) AccessPolicy(io.automatiko.engine.api.auth.AccessPolicy) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)

Example 7 with WorkflowProcessInstanceImpl

use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.

the class ProcessMetricsEventListener method afterProcessCompleted.

@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
    final WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) event.getProcessInstance();
    Counter counter;
    if (processInstance.getState() == ProcessInstance.STATE_COMPLETED) {
        // Displays total count of completed process instances
        counter = registry.counter("automatiko.process.completed.count", Arrays.asList(Tag.of("application", application.orElse("")), Tag.of("version", version.orElse("")), Tag.of("processId", processInstance.getProcessId()), Tag.of("processVersion", processInstance.getProcess().getVersion() == null ? "unknown" : processInstance.getProcess().getVersion())));
    } else {
        // Displays total count of aborted process instances
        counter = registry.counter("automatiko.process.aborted.count", Arrays.asList(Tag.of("application", application.orElse("")), Tag.of("version", version.orElse("")), Tag.of("processId", processInstance.getProcessId()), Tag.of("processVersion", processInstance.getProcess().getVersion() == null ? "unknown" : processInstance.getProcess().getVersion())));
    }
    counter.increment();
    if (processInstance.getStartDate() != null) {
        // Displays duration of process instances - from start to completion
        Timer instanceDuration = registry.timer("automatiko.process.instances.duration", Arrays.asList(Tag.of("application", application.orElse("")), Tag.of("version", version.orElse("")), Tag.of("processId", processInstance.getProcessId()), Tag.of("processVersion", processInstance.getProcess().getVersion() == null ? "unknown" : processInstance.getProcess().getVersion())));
        final long duration = millisToSeconds(processInstance.getEndDate().getTime() - processInstance.getStartDate().getTime());
        instanceDuration.record(Duration.ofSeconds(duration));
    }
}
Also used : Counter(io.micrometer.core.instrument.Counter) Timer(io.micrometer.core.instrument.Timer) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)

Example 8 with WorkflowProcessInstanceImpl

use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.

the class EndNodeInstance method internalTrigger.

public void internalTrigger(final NodeInstance from, String type) {
    super.internalTrigger(from, type);
    if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("An EndNode only accepts default incoming connections!");
    }
    leaveTime = new Date();
    boolean hidden = false;
    if (getNode().getMetaData().get(HIDDEN) != null) {
        hidden = true;
    }
    if (getProcessInstance().isFunctionFlow(this) && getNodeInstanceContainer() instanceof ProcessInstance) {
        // only when running as function flow and node is in the top level node container meaning process instance
        // and not subprocesses
        getProcessInstance().getMetaData().compute("ATK_FUNC_FLOW_NEXT", (k, v) -> {
            if (v == null) {
                v = new ArrayList<String>();
            }
            Process process = getProcessInstance().getProcess();
            String version = "";
            if (process.getVersion() != null && !process.getVersion().trim().isEmpty()) {
                version = ".v" + process.getVersion().replaceAll("\\.", "_");
            }
            String defaultNextNode = process.getPackageName() + "." + process.getId() + version + "." + getNodeName().toLowerCase();
            ((List<String>) v).add((String) getNode().getMetaData().getOrDefault("functionType", defaultNextNode));
            return v;
        });
    }
    InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
    if (!hidden) {
        runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
    }
    ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
    if (getEndNode().isTerminate()) {
        if (getNodeInstanceContainer() instanceof CompositeNodeInstance) {
            if (getEndNode().getScope() == PROCESS_SCOPE) {
                getProcessInstance().setState(STATE_COMPLETED);
            } else {
                while (!getNodeInstanceContainer().getNodeInstances().isEmpty()) {
                    ((io.automatiko.engine.workflow.process.instance.NodeInstance) getNodeInstanceContainer().getNodeInstances().iterator().next()).cancel();
                }
                ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
            }
        } else {
            ((NodeInstanceContainer) getNodeInstanceContainer()).setState(STATE_COMPLETED);
        }
    } else {
        ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
    }
    if (!hidden) {
        runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
    }
    String uniqueId = (String) getNode().getMetaData().get(UNIQUE_ID);
    if (uniqueId == null) {
        uniqueId = ((NodeImpl) getNode()).getUniqueId();
    }
    ((WorkflowProcessInstanceImpl) getProcessInstance()).addCompletedNodeId(uniqueId);
}
Also used : NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) Process(io.automatiko.engine.api.definition.process.Process) Date(java.util.Date) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ArrayList(java.util.ArrayList) List(java.util.List) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance)

Example 9 with WorkflowProcessInstanceImpl

use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.

the class AbstractProcessInstance method buildTags.

protected Tags buildTags() {
    return new Tags() {

        Collection<String> values = ((WorkflowProcessInstanceImpl) processInstance()).getTags().stream().map(t -> t.getValue()).collect(Collectors.toList());

        @Override
        public Collection<String> values() {
            return values;
        }

        @Override
        public boolean remove(String id) {
            WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) processInstance();
            boolean removed = pi.removedTag(id);
            removeOnFinish();
            return removed;
        }

        @Override
        public Tag get(String id) {
            WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) processInstance();
            return pi.getTags().stream().filter(t -> t.getId().equals(id)).findFirst().orElse(null);
        }

        @Override
        public void add(String value) {
            WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) processInstance();
            pi.addTag(value);
            removeOnFinish();
        }

        @Override
        public Collection<Tag> get() {
            WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) processInstance();
            return pi.getTags();
        }
    };
}
Also used : WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) Collection(java.util.Collection) Tag(io.automatiko.engine.api.workflow.Tag) Tags(io.automatiko.engine.api.workflow.Tags)

Example 10 with WorkflowProcessInstanceImpl

use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.

the class AbstractProcessInstance method populateChildProcesses.

@SuppressWarnings("unchecked")
protected void populateChildProcesses(Process<?> process, Collection<ProcessInstance<? extends Model>> collection, ProcessInstanceReadMode mode) {
    WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) processInstance();
    List<String> children = instance.getChildren().get(process.id());
    if (children != null && !children.isEmpty()) {
        for (String id : children) {
            process.instances().findById(id, mode).ifPresent(pi -> collection.add((ProcessInstance<? extends Model>) pi));
        }
    }
}
Also used : WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) Model(io.automatiko.engine.api.Model) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)

Aggregations

WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)36 ArrayList (java.util.ArrayList)10 EventSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)8 Node (io.automatiko.engine.api.definition.process.Node)7 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)7 HumanTaskNodeInstance (io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance)7 Process (io.automatiko.engine.api.definition.process.Process)6 NodeInstance (io.automatiko.engine.workflow.process.instance.NodeInstance)6 CompositeContextNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)5 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)5 NodeInstanceContainer (io.automatiko.engine.workflow.process.instance.NodeInstanceContainer)5 LambdaSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)5 WorkItemNodeInstance (io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance)5 Date (java.util.Date)5 ExpirationTime (io.automatiko.engine.api.jobs.ExpirationTime)4 JobsService (io.automatiko.engine.api.jobs.JobsService)4