Search in sources :

Example 1 with Tag

use of io.automatiko.engine.api.workflow.Tag in project automatiko-engine by automatiko-io.

the class TracingAdds method addTags.

public void addTags(io.automatiko.engine.api.runtime.process.ProcessInstance instance) {
    if (tracer.isResolvable()) {
        Tracer tracerInstance = tracer.get();
        tracerInstance.activeSpan().setTag("workflow.instance.id", instance.getId());
        tracerInstance.activeSpan().setTag("workflow.root.instance.id", instance.getRootProcessInstanceId() == null ? instance.getId() : instance.getRootProcessInstanceId());
        if (instance.getCorrelationKey() != null) {
            tracerInstance.activeSpan().setTag("workflow.business.key", instance.getCorrelationKey());
        }
        Collection<Tag> tags = ((WorkflowProcessInstance) instance).getTags();
        if (!tags.isEmpty()) {
            tracerInstance.activeSpan().setTag("workflow.instance.tags", tags.stream().map(t -> t.getValue()).collect(Collectors.joining(",")));
        }
    }
}
Also used : Tracer(io.opentracing.Tracer) Tag(io.automatiko.engine.api.workflow.Tag) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)

Example 2 with Tag

use of io.automatiko.engine.api.workflow.Tag 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 3 with Tag

use of io.automatiko.engine.api.workflow.Tag in project automatiko-engine by automatiko-io.

the class AbstractProtobufProcessInstanceMarshaller method writeProcessInstance.

// Output methods
public AutomatikoMessages.ProcessInstance writeProcessInstance(MarshallerWriteContext context, ProcessInstance processInstance) throws IOException {
    WorkflowProcessInstanceImpl workFlow = (WorkflowProcessInstanceImpl) processInstance;
    AutomatikoMessages.ProcessInstance.Builder _instance = AutomatikoMessages.ProcessInstance.newBuilder().setId(workFlow.getId()).setProcessId(workFlow.getProcessId()).setState(workFlow.getState()).setProcessType(workFlow.getProcess().getType()).setSignalCompletion(workFlow.isSignalCompletion()).setSlaCompliance(workFlow.getSlaCompliance()).setStartDate(workFlow.getStartDate().getTime());
    if (workFlow.getProcessXml() != null) {
        _instance.setProcessXml(workFlow.getProcessXml());
    }
    if (workFlow.getDescription() != null) {
        _instance.setDescription(workFlow.getDescription());
    }
    if (workFlow.getInitiator() != null) {
        _instance.setInitiator(workFlow.getInitiator());
    }
    _instance.addAllCompletedNodeIds(workFlow.getCompletedNodeIds());
    if (workFlow.getCorrelationKey() != null) {
        _instance.setCorrelationKey(workFlow.getCorrelationKey());
    }
    if (workFlow.getSlaDueDate() != null) {
        _instance.setSlaDueDate(workFlow.getSlaDueDate().getTime());
    }
    if (workFlow.getSlaTimerId() != null) {
        _instance.setSlaTimerId(workFlow.getSlaTimerId());
    }
    if (workFlow.getParentProcessInstanceId() != null) {
        _instance.setParentProcessInstanceId(workFlow.getParentProcessInstanceId());
    }
    if (workFlow.getRootProcessInstanceId() != null) {
        _instance.setRootProcessInstanceId(workFlow.getRootProcessInstanceId());
    }
    if (workFlow.getRootProcessId() != null) {
        _instance.setRootProcessId(workFlow.getRootProcessId());
    }
    if (workFlow.getReferenceFromRoot() != null) {
        _instance.setReferenceFromRoot(workFlow.getReferenceFromRoot());
    }
    if (workFlow.getProcess().getVersion() != null) {
        _instance.setProcessVersion(workFlow.getProcess().getVersion());
    }
    List<ExecutionsErrorInfo> errors = workFlow.errors();
    if (errors != null) {
        for (ExecutionsErrorInfo error : errors) {
            _instance.addErrors(AutomatikoMessages.ProcessInstance.Error.newBuilder().setErrorNodeId(error.getFailedNodeId()).setErrorId(error.getErrorId()).setErrorMessage(error.getErrorMessage() == null ? "" : error.getErrorMessage()).setErrorDetails(error.getErrorDetails() == null ? "" : error.getErrorDetails()));
        }
    }
    if (workFlow.getReferenceId() != null) {
        _instance.setReferenceId(workFlow.getReferenceId());
    }
    Map<String, List<String>> children = workFlow.getChildren();
    if (children != null) {
        for (Entry<String, List<String>> entry : children.entrySet()) {
            _instance.addChildren(AutomatikoMessages.ProcessInstance.ProcessInstanchChildren.newBuilder().setProcessId(entry.getKey()).addAllIds(entry.getValue()).build());
        }
    }
    Collection<Tag> tags = workFlow.getTags();
    if (tags != null) {
        for (Tag tag : tags) {
            _instance.addTags(AutomatikoMessages.ProcessInstance.Tag.newBuilder().setId(tag.getId()).setValue(tag.getValue()));
        }
    }
    SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) workFlow.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
    if (swimlaneContextInstance != null) {
        Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
        for (Map.Entry<String, String> entry : swimlaneActors.entrySet()) {
            _instance.addSwimlaneContext(AutomatikoMessages.ProcessInstance.SwimlaneContextInstance.newBuilder().setSwimlane(entry.getKey()).setActorId(entry.getValue()).build());
        }
    }
    List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(workFlow.getNodeInstances());
    Collections.sort(nodeInstances, new Comparator<NodeInstance>() {

        public int compare(NodeInstance o1, NodeInstance o2) {
            return (int) (o1.getId().compareTo(o2.getId()));
        }
    });
    for (NodeInstance nodeInstance : nodeInstances) {
        _instance.addNodeInstance(writeNodeInstance(context, nodeInstance));
    }
    List<ContextInstance> exclusiveGroupInstances = workFlow.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP);
    if (exclusiveGroupInstances != null) {
        for (ContextInstance contextInstance : exclusiveGroupInstances) {
            AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance.Builder _exclusive = AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance.newBuilder();
            ExclusiveGroupInstance exclusiveGroupInstance = (ExclusiveGroupInstance) contextInstance;
            Collection<NodeInstance> groupNodeInstances = exclusiveGroupInstance.getNodeInstances();
            for (NodeInstance nodeInstance : groupNodeInstances) {
                _exclusive.addGroupNodeInstanceId(nodeInstance.getId());
            }
            _instance.addExclusiveGroup(_exclusive.build());
        }
    }
    if (!(boolean) context.env.getOrDefault("_ignore_vars_", false)) {
        writeVariableScope(context, workFlow, _instance);
    }
    List<Map.Entry<String, Integer>> iterationlevels = new ArrayList<Map.Entry<String, Integer>>(workFlow.getIterationLevels().entrySet());
    Collections.sort(iterationlevels, new Comparator<Map.Entry<String, Integer>>() {

        public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            return o1.getKey().compareTo(o2.getKey());
        }
    });
    for (Map.Entry<String, Integer> level : iterationlevels) {
        if (level.getValue() != null) {
            _instance.addIterationLevels(AutomatikoMessages.IterationLevel.newBuilder().setId(level.getKey()).setLevel(level.getValue()));
        }
    }
    return _instance.build();
}
Also used : ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList) Entry(java.util.Map.Entry) List(java.util.List) ArrayList(java.util.ArrayList) ExclusiveGroupInstance(io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) Tag(io.automatiko.engine.api.workflow.Tag) Map(java.util.Map) HashMap(java.util.HashMap) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) StateNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateNodeInstance) ForEachNodeInstance(io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance) MilestoneNodeInstance(io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) SubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.SubProcessNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) DynamicNodeInstance(io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) RuleSetNodeInstance(io.automatiko.engine.workflow.process.instance.node.RuleSetNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)

Example 4 with Tag

use of io.automatiko.engine.api.workflow.Tag in project automatiko-engine by automatiko-io.

the class WorkflowProcessInstanceImpl method evaluateTags.

public Collection<Tag> evaluateTags() {
    if (this.tags == null) {
        this.tags = new LinkedHashSet<Tag>();
    }
    Collection<Tag> evaluatedTags = new LinkedHashSet<Tag>();
    Collection<TagDefinition> tagDefinitions = ((Process) getProcess()).getTagDefinitions();
    for (TagDefinition def : tagDefinitions) {
        String tag = def.get(this, getVariables());
        if (tag != null) {
            Tag tagInstance = new TagInstance(def.getId(), tag);
            evaluatedTags.add(tagInstance);
            this.tags.remove(tagInstance);
        }
    }
    // append all remaining tasks that didn't have definition - added manually on the instance
    evaluatedTags.addAll(this.tags);
    // replace existing ones
    this.tags = evaluatedTags;
    return evaluatedTags;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TagDefinition(io.automatiko.engine.workflow.base.core.TagDefinition) TagInstance(io.automatiko.engine.workflow.base.instance.TagInstance) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) Process(io.automatiko.engine.workflow.base.core.Process) Tag(io.automatiko.engine.api.workflow.Tag)

Example 5 with Tag

use of io.automatiko.engine.api.workflow.Tag in project automatiko-engine by automatiko-io.

the class ProcessInstanceEventBatch method create.

protected ProcessInstanceEventBody create(ProcessEvent event) {
    WorkflowProcessInstance pi = (WorkflowProcessInstance) event.getProcessInstance();
    ProcessInstanceEventBody.Builder eventBuilder = ProcessInstanceEventBody.create().id(pi.getId()).parentInstanceId(pi.getParentProcessInstanceId()).rootInstanceId(pi.getRootProcessInstanceId()).processId(pi.getProcessId()).rootProcessId(pi.getRootProcessId()).processName(pi.getProcessName()).startDate(pi.getStartDate()).endDate(pi.getEndDate()).state(pi.getState()).businessKey(pi.getCorrelationKey()).variables(pi.getPublicVariables()).milestones(createMilestones(pi));
    if (pi.getState() == ProcessInstance.STATE_ERROR) {
        for (ExecutionsErrorInfo error : pi.errors()) {
            eventBuilder.error(ProcessErrorEventBody.create().nodeDefinitionId(error.getFailedNodeId()).errorMessage(error.getErrorMessage()).build());
        }
    }
    String securityRoles = (String) pi.getProcess().getMetaData().get("securityRoles");
    if (securityRoles != null) {
        eventBuilder.roles(securityRoles.split(","));
    }
    Collection<Tag> tags = pi.getTags();
    if (tags != null) {
        eventBuilder.tags(tags.stream().map(t -> t.getValue()).toArray(String[]::new));
    }
    io.automatiko.engine.api.workflow.ProcessInstance<?> instance = (io.automatiko.engine.api.workflow.ProcessInstance<?>) pi.getMetaData("AutomatikProcessInstance");
    if (instance != null) {
        Set<String> visibleTo = instance.process().accessPolicy().visibleTo(instance);
        if (visibleTo != null) {
            eventBuilder.visibleTo(visibleTo.toArray(String[]::new));
        }
        eventBuilder.instance(instance);
    }
    return eventBuilder.build();
}
Also used : ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) Tag(io.automatiko.engine.api.workflow.Tag) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)

Aggregations

Tag (io.automatiko.engine.api.workflow.Tag)6 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)3 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)2 ExecutionsErrorInfo (io.automatiko.engine.api.workflow.ExecutionsErrorInfo)2 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)2 HashMap (java.util.HashMap)2 Application (io.automatiko.engine.api.Application)1 Model (io.automatiko.engine.api.Model)1 WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)1 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)1 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)1 Tags (io.automatiko.engine.api.workflow.Tags)1 WorkItem (io.automatiko.engine.api.workflow.WorkItem)1 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)1 Process (io.automatiko.engine.workflow.base.core.Process)1 TagDefinition (io.automatiko.engine.workflow.base.core.TagDefinition)1 ContextInstance (io.automatiko.engine.workflow.base.instance.ContextInstance)1 TagInstance (io.automatiko.engine.workflow.base.instance.TagInstance)1 ExclusiveGroupInstance (io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance)1 SwimlaneContextInstance (io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance)1