Search in sources :

Example 1 with SwimlaneContextInstance

use of io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance in project automatiko-engine by automatiko-io.

the class AbstractProtobufProcessInstanceMarshaller method readProcessInstance.

// Input methods
public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
    AutomatikoMessages.ProcessInstance _instance = (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.ProcessInstance) context.parameterObject;
    if (_instance == null) {
        // try to parse from the stream
        ExtensionRegistry registry = PersisterHelper.buildRegistry(context, null);
        Header _header;
        try {
            _header = PersisterHelper.readFromStreamWithHeaderPreloaded(context, registry);
        } catch (ClassNotFoundException e) {
            // Java 5 does not accept [new IOException(String, Throwable)]
            IOException ioe = new IOException("Error deserializing process instance.");
            ioe.initCause(e);
            throw ioe;
        }
        _instance = AutomatikoMessages.ProcessInstance.parseFrom(_header.getPayload(), registry);
    }
    WorkflowProcessInstanceImpl processInstance = createProcessInstance();
    processInstance.setId(_instance.getId());
    String processId = _instance.getProcessId();
    processInstance.setProcessId(processId);
    String processXml = _instance.getProcessXml();
    Process process = null;
    if (processXml != null && processXml.trim().length() > 0) {
        processInstance.setProcessXml(processXml);
        process = processInstance.getProcess();
    } else {
        process = context.processes.get(processId);
        if (process == null) {
            throw new RuntimeException("Could not find process " + processId + " when restoring process instance " + processInstance.getId());
        }
        processInstance.setProcess(process);
    }
    processInstance.setDescription(_instance.getDescription());
    processInstance.internalSetState(_instance.getState());
    processInstance.setParentProcessInstanceId(_instance.getParentProcessInstanceId());
    processInstance.setRootProcessInstanceId(_instance.getRootProcessInstanceId());
    processInstance.setRootProcessId(_instance.getRootProcessId());
    processInstance.setSignalCompletion(_instance.getSignalCompletion());
    processInstance.setInitiator(_instance.getInitiator());
    processInstance.setCorrelationKey(_instance.getCorrelationKey());
    processInstance.setStartDate(new Date(_instance.getStartDate()));
    processInstance.internalSetSlaCompliance(_instance.getSlaCompliance());
    if (_instance.getSlaDueDate() > 0) {
        processInstance.internalSetSlaDueDate(new Date(_instance.getSlaDueDate()));
    }
    processInstance.internalSetSlaTimerId(_instance.getSlaTimerId());
    processInstance.setProcessRuntime(context.getProcessRuntime());
    List<ExecutionsErrorInfo> errors = new ArrayList<>();
    for (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.ProcessInstance.Error error : _instance.getErrorsList()) {
        errors.add(new ExecutionsErrorInfo(error.getErrorNodeId(), error.getErrorId(), error.getErrorMessage(), error.getErrorDetails()));
    }
    processInstance.internalSetExecutionErrors(errors);
    processInstance.setReferenceId(_instance.getReferenceId());
    processInstance.internalSetReferenceFromRoot(_instance.getReferenceFromRoot());
    for (String completedNodeId : _instance.getCompletedNodeIdsList()) {
        processInstance.addCompletedNodeId(completedNodeId);
    }
    if (_instance.getChildrenCount() > 0) {
        _instance.getChildrenList().forEach(child -> processInstance.addChildren(child.getProcessId(), child.getIdsList()));
    }
    if (_instance.getTagsCount() > 0) {
        _instance.getTagsList().forEach(tag -> processInstance.internalAddTag(tag.getId(), tag.getValue()));
    }
    if (_instance.getSwimlaneContextCount() > 0) {
        Context swimlaneContext = ((io.automatiko.engine.workflow.base.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
        SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(swimlaneContext);
        for (AutomatikoMessages.ProcessInstance.SwimlaneContextInstance _swimlane : _instance.getSwimlaneContextList()) {
            swimlaneContextInstance.setActorId(_swimlane.getSwimlane(), _swimlane.getActorId());
        }
    }
    for (AutomatikoMessages.ProcessInstance.NodeInstance _node : _instance.getNodeInstanceList()) {
        context.parameterObject = _node;
        readNodeInstance(context, processInstance, processInstance);
    }
    if (processInstance.getState() == ProcessInstance.STATE_ACTIVE || processInstance.getState() == ProcessInstance.STATE_ERROR) {
        for (AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance _excl : _instance.getExclusiveGroupList()) {
            ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
            processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
            for (String nodeInstanceId : _excl.getGroupNodeInstanceIdList()) {
                NodeInstance nodeInstance = ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) processInstance).getNodeInstance(nodeInstanceId, true);
                if (nodeInstance == null) {
                    throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
                }
                exclusiveGroupInstance.addNodeInstance(nodeInstance);
            }
        }
    }
    readVariableScope(context, process, processInstance, _instance);
    if (_instance.getIterationLevelsCount() > 0) {
        for (AutomatikoMessages.IterationLevel _level : _instance.getIterationLevelsList()) {
            processInstance.getIterationLevels().put(_level.getId(), _level.getLevel());
        }
    }
    return processInstance;
}
Also used : ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList) Process(io.automatiko.engine.api.definition.process.Process) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) Context(io.automatiko.engine.workflow.base.core.Context) SwimlaneContext(io.automatiko.engine.workflow.base.core.context.swimlane.SwimlaneContext) ExclusiveGroupInstance(io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) IOException(java.io.IOException) Date(java.util.Date) Header(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Header) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) 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 2 with SwimlaneContextInstance

use of io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance in project automatiko-engine by automatiko-io.

the class HumanTaskNodeInstance method getSwimlaneContextInstance.

private SwimlaneContextInstance getSwimlaneContextInstance(String swimlaneName) {
    if (this.swimlaneContextInstance == null) {
        if (swimlaneName == null) {
            return null;
        }
        SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) resolveContextInstance(SwimlaneContext.SWIMLANE_SCOPE, swimlaneName);
        if (swimlaneContextInstance == null) {
            throw new IllegalArgumentException("Could not find swimlane context instance");
        }
        this.swimlaneContextInstance = swimlaneContextInstance;
    }
    return this.swimlaneContextInstance;
}
Also used : SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance)

Example 3 with SwimlaneContextInstance

use of io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance 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 SwimlaneContextInstance

use of io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance in project automatiko-engine by automatiko-io.

the class HumanTaskNodeInstance method triggerCompleted.

public void triggerCompleted(WorkItem workItem) {
    String swimlaneName = getHumanTaskNode().getSwimlane();
    SwimlaneContextInstance swimlaneContextInstance = getSwimlaneContextInstance(swimlaneName);
    if (swimlaneContextInstance != null) {
        String newActorId = (workItem instanceof HumanTaskWorkItem) ? ((HumanTaskWorkItem) workItem).getActualOwner() : (String) workItem.getParameter(ACTOR_ID);
        if (newActorId != null) {
            swimlaneContextInstance.setActorId(swimlaneName, newActorId);
        }
    }
    super.triggerCompleted(workItem);
}
Also used : HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance)

Example 5 with SwimlaneContextInstance

use of io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance in project automatiko-engine by automatiko-io.

the class HumanTaskNodeInstance method assignWorkItem.

protected String assignWorkItem(WorkItem workItem) {
    String actorId = null;
    // if this human task node is part of a swimlane, check whether an actor
    // has already been assigned to this swimlane
    String swimlaneName = getHumanTaskNode().getSwimlane();
    SwimlaneContextInstance swimlaneContextInstance = getSwimlaneContextInstance(swimlaneName);
    if (swimlaneContextInstance != null) {
        actorId = swimlaneContextInstance.getActorId(swimlaneName);
        ((WorkItemImpl) workItem).setParameter("SwimlaneActorId", actorId);
    }
    // actor is specified for this human task
    if (actorId == null) {
        actorId = (String) workItem.getParameter(ACTOR_ID);
        if (actorId != null && swimlaneContextInstance != null && actorId.split(separator).length == 1) {
            swimlaneContextInstance.setActorId(swimlaneName, actorId);
            ((WorkItemImpl) workItem).setParameter("SwimlaneActorId", actorId);
        }
    }
    processAssigment(ACTOR_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getPotentialUsers());
    processAssigment(GROUP_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getPotentialGroups());
    processAssigment(GROUPS, workItem, ((HumanTaskWorkItemImpl) workItem).getPotentialGroups());
    processAssigment(EXCLUDED_OWNER_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getExcludedUsers());
    processAssigment(BUSINESSADMINISTRATOR_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getAdminUsers());
    processAssigment(BUSINESSADMINISTRATOR_GROUP_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getAdminGroups());
    // parameter
    return (String) workItem.getParameter(ACTOR_ID);
}
Also used : SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) HumanTaskWorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemImpl)

Aggregations

SwimlaneContextInstance (io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance)5 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)2 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)2 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)2 ExecutionsErrorInfo (io.automatiko.engine.api.workflow.ExecutionsErrorInfo)2 ExclusiveGroupInstance (io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance)2 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)2 CompositeContextNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance)2 DynamicNodeInstance (io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance)2 EventNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)2 EventSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)2 ForEachNodeInstance (io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance)2 HumanTaskNodeInstance (io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance)2 LambdaSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)2 MilestoneNodeInstance (io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance)2 RuleSetNodeInstance (io.automatiko.engine.workflow.process.instance.node.RuleSetNodeInstance)2 StateNodeInstance (io.automatiko.engine.workflow.process.instance.node.StateNodeInstance)2 SubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.SubProcessNodeInstance)2 TimerNodeInstance (io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance)2 WorkItemNodeInstance (io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance)2