public virtual void testTreeCompactionWithVariablesOnScopeAndConcurrentExecution()
        {
            // given
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("process");

            ITask task1 = taskService.CreateTaskQuery(c => c.TaskDefinitionKey == "task1").First();

            IExecution task2Execution = runtimeService.CreateExecutionQuery(c => c.ActivityId == "task2").First();

            // when
            runtimeService.SetVariable(processInstance.Id, "foo", "baz");
            runtimeService.SetVariableLocal(task2Execution.Id, "foo", "bar");
            // and completing the other task, thereby pruning the concurrent execution
            taskService.Complete(task1.Id);

            // then something happens
            IVariableInstance variable = runtimeService.CreateVariableInstanceQuery().First();

            Assert.NotNull(variable);
            Assert.AreEqual("foo", variable.Name);
            Assert.AreEqual(processInstance.Id, variable.ExecutionId);
        }
        public virtual void testTreeCompactionNestedForkParallelGateway()
        {
            // given
            runtimeService.StartProcessInstanceByKey("process");

            ITask task1 = taskService.CreateTaskQuery(c => c.TaskDefinitionKey == "task1").First();

            IExecution task2Execution             = runtimeService.CreateExecutionQuery(c => c.ActivityId == "task2").First();
            string     subProcessScopeExecutionId = ((ExecutionEntity)task2Execution).ParentId;

            // when
            runtimeService.SetVariableLocal(task2Execution.Id, "foo", "bar");
            // and completing the other task, thereby pruning the concurrent execution
            taskService.Complete(task1.Id);

            // then the variable still exists on the subprocess scope execution
            IVariableInstance variable = runtimeService.CreateVariableInstanceQuery().First();

            Assert.NotNull(variable);
            Assert.AreEqual("foo", variable.Name);
            Assert.AreEqual(subProcessScopeExecutionId, variable.ExecutionId);
        }
        public virtual void testTreeCompactionWithLocalVariableOnConcurrentExecution()
        {
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("process");

            IExecution innerTaskExecution = runtimeService.CreateExecutionQuery(c => c.ActivityId == "innerTask").First();

            IExecution subProcessConcurrentExecution = runtimeService.CreateExecutionQuery(c => c.Id == ((ExecutionEntity)innerTaskExecution).ParentId).First();

            ITask task = taskService.CreateTaskQuery(c => c.TaskDefinitionKey == "task").First();

            // when
            runtimeService.SetVariableLocal(subProcessConcurrentExecution.Id, "foo", "bar");
            // and completing the concurrent task, thereby pruning the sub process concurrent execution
            taskService.Complete(task.Id);

            // then the variable still exists
            IVariableInstance variable = runtimeService.CreateVariableInstanceQuery().First();

            Assert.NotNull(variable);
            Assert.AreEqual("foo", variable.Name);
            Assert.AreEqual(processInstance.Id, variable.ExecutionId);
        }
        public virtual void testStableVariableInstanceIdsOnCompactionAndExpansion()
        {
            IProcessInstance processInstance = runtimeService.StartProcessInstanceByKey("process");

            IExecution task1Execution = runtimeService.CreateExecutionQuery(c => c.ActivityId == "task1").First();

            ITask task2 = taskService.CreateTaskQuery(c => c.TaskDefinitionKey == "task2").First();

            // when
            runtimeService.SetVariableLocal(task1Execution.Id, "foo", "bar");
            IVariableInstance variableBeforeCompaction = runtimeService.CreateVariableInstanceQuery().First();

            // compacting the tree
            taskService.Complete(task2.Id);

            // expanding the tree
            runtimeService.CreateProcessInstanceModification(processInstance.Id).StartBeforeActivity("task2").Execute();

            // then the variable still exists
            IVariableInstance variableAfterCompaction = runtimeService.CreateVariableInstanceQuery().First();

            Assert.AreEqual(variableBeforeCompaction.Id, variableAfterCompaction.Id);
        }
        //JAVA TO C# CONVERTER TODO Resources.Task: Most Java annotations will not have direct .NET equivalent attributes:
        //ORIGINAL LINE: @Deployment public void testScriptConditionExecutesCommandAfterUserCompletesTask()
        public virtual void testScriptConditionExecutesCommandAfterUserCompletesTask()
        {
            // given
            string ProcessInstanceId = StartProcessInstanceByKey(DEFAULT_PROCESS_KEY).Id;
            string taskId            = selectSingleTask().Id;

            createGrantAuthorization(Resources.Task, taskId, userId, Permissions.Update);

            // when
            taskService.Complete(taskId);

            // then
            disableAuthorization();

            IVariableInstance variableUser = runtimeService.CreateVariableInstanceQuery(c => c.ProcessInstanceId == ProcessInstanceId) /*.VariableName("userId")*/.First();

            Assert.NotNull(variableUser);
            Assert.AreEqual(userId, variableUser.Value);

            Assert.AreEqual(2, runtimeService.CreateProcessInstanceQuery().Count());

            enableAuthorization();
        }
        protected virtual void Setup()
        {
            _instanceReady = true;

            // Variables
            _variables = new IVariableInstance[_provider.Variables.Length];
            for (int i = 0; i < _variables.Length; i++)
            {
                _variables[i] = _provider.Variables[i].GetInstance(this, _typeLinker);
                ObjectScope.AddNativeVariable(_variables[i]);
            }

            // Static variables
            foreach (var variable in _provider.StaticVariables)
            {
                variable.AddInstance(this, _typeLinker);
            }

            // Functions
            foreach (var method in _provider.Methods)
            {
                method.AddInstance(this, _typeLinker);
            }
        }
示例#7
0
 public ObjectVariable(ClassType classType, IVariableInstance variable)
 {
     _classType = classType;
     Variable   = variable;
 }
 public ParameterInstance(CodeParameter parameter, IVariableInstance variableInstance)
 {
     Parameter = parameter;
     Variable  = variableInstance;
 }
 void IScopeAppender.AddStaticBasedScope(IVariableInstance variable) => RulesetScope.AddNativeVariable(variable);
 public void Call(ParseInfo parseInfo, DocRange callRange)
 {
     IVariableInstance.Call(this, parseInfo, callRange);
     parseInfo.Script.AddDefinitionLink(callRange, Var.DefinedAt);
 }
示例#11
0
        public virtual IDictionary <string, IDataObject> Execute(ICommandContext commandContext)
        {
            // Verify existance of execution
            if (executionId is null)
            {
                throw new ActivitiIllegalArgumentException("executionId is null");
            }

            IExecutionEntity execution = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(executionId);

            if (execution == null)
            {
                throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", typeof(IExecution));
            }

            IDictionary <string, IVariableInstance> variables;

            if ((dataObjectNames?.Count()).GetValueOrDefault(0) == 0)
            {
                // Fetch all
                if (isLocal)
                {
                    variables = execution.VariableInstancesLocal;
                }
                else
                {
                    variables = execution.VariableInstances;
                }
            }
            else
            {
                // Fetch specific collection of variables
                if (isLocal)
                {
                    variables = execution.GetVariableInstancesLocal(dataObjectNames, false);
                }
                else
                {
                    variables = execution.GetVariableInstances(dataObjectNames, false);
                }
            }

            IDictionary <string, IDataObject> dataObjects = null;

            if (variables != null)
            {
                dataObjects = new Dictionary <string, IDataObject>(variables.Count);

                foreach (KeyValuePair <string, IVariableInstance> entry in variables.SetOfKeyValuePairs())
                {
                    string            name           = entry.Key;
                    IVariableInstance variableEntity = entry.Value;

                    IExecutionEntity executionEntity = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(variableEntity.ExecutionId);
                    while (!executionEntity.IsScope)
                    {
                        executionEntity = executionEntity.Parent;
                    }

                    BpmnModel        bpmnModel       = ProcessDefinitionUtil.GetBpmnModel(execution.ProcessDefinitionId);
                    ValuedDataObject foundDataObject = null;
                    if (executionEntity.ParentId is null)
                    {
                        foreach (ValuedDataObject dataObject in bpmnModel.MainProcess.DataObjects)
                        {
                            if (dataObject.Name.Equals(variableEntity.Name))
                            {
                                foundDataObject = dataObject;
                                break;
                            }
                        }
                    }
                    else
                    {
                        SubProcess subProcess = (SubProcess)bpmnModel.GetFlowElement(execution.ActivityId);
                        foreach (ValuedDataObject dataObject in subProcess.DataObjects)
                        {
                            if (dataObject.Name.Equals(variableEntity.Name))
                            {
                                foundDataObject = dataObject;
                                break;
                            }
                        }
                    }

                    string localizedName        = null;
                    string localizedDescription = null;

                    if (locale is object && foundDataObject is object)
                    {
                        JToken languageNode = Context.GetLocalizationElementProperties(locale, foundDataObject.Id, execution.ProcessDefinitionId, withLocalizationFallback);

                        if (languageNode != null)
                        {
                            JToken nameNode = languageNode[DynamicBpmnConstants.LOCALIZATION_NAME];
                            if (nameNode != null)
                            {
                                localizedName = nameNode.ToString();
                            }
                            JToken descriptionNode = languageNode[DynamicBpmnConstants.LOCALIZATION_DESCRIPTION];
                            if (descriptionNode != null)
                            {
                                localizedDescription = descriptionNode.ToString();
                            }
                        }
                    }

                    if (foundDataObject != null)
                    {
                        dataObjects[name] = new DataObjectImpl(variableEntity.Name, variableEntity.Value, foundDataObject.Documentation, foundDataObject.Type, localizedName, localizedDescription, foundDataObject.Id);
                    }
                }
            }

            return(dataObjects);
        }
        public virtual IDataObject Execute(ICommandContext commandContext)
        {
            if (ReferenceEquals(taskId, null))
            {
                throw new ActivitiIllegalArgumentException("taskId is null");
            }
            if (ReferenceEquals(variableName, null))
            {
                throw new ActivitiIllegalArgumentException("variableName is null");
            }

            ITaskEntity task = commandContext.TaskEntityManager.FindById <ITaskEntity>(new KeyValuePair <string, object>("id", taskId));

            if (task == null)
            {
                throw new ActivitiObjectNotFoundException("task " + taskId + " doesn't exist", typeof(TaskActivity));
            }

            IDataObject       dataObject     = null;
            IVariableInstance variableEntity = task.GetVariableInstance(variableName, false);

            string localizedName        = null;
            string localizedDescription = null;

            if (variableEntity != null)
            {
                IExecutionEntity executionEntity = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(variableEntity.ExecutionId);
                while (!executionEntity.IsScope)
                {
                    executionEntity = executionEntity.Parent;
                }

                BpmnModel        bpmnModel       = ProcessDefinitionUtil.GetBpmnModel(executionEntity.ProcessDefinitionId);
                ValuedDataObject foundDataObject = null;
                if (ReferenceEquals(executionEntity.ParentId, null))
                {
                    foreach (ValuedDataObject dataObjectDefinition in bpmnModel.MainProcess.DataObjects)
                    {
                        if (dataObjectDefinition.Name.Equals(variableEntity.Name))
                        {
                            foundDataObject = dataObjectDefinition;
                            break;
                        }
                    }
                }
                else
                {
                    SubProcess subProcess = (SubProcess)bpmnModel.GetFlowElement(executionEntity.ActivityId);
                    foreach (ValuedDataObject dataObjectDefinition in subProcess.DataObjects)
                    {
                        if (dataObjectDefinition.Name.Equals(variableEntity.Name))
                        {
                            foundDataObject = dataObjectDefinition;
                            break;
                        }
                    }
                }

                if (!ReferenceEquals(locale, null) && foundDataObject != null)
                {
                    JToken languageNode = Context.GetLocalizationElementProperties(locale, foundDataObject.Id, task.ProcessDefinitionId, withLocalizationFallback);

                    if (languageNode != null)
                    {
                        JToken nameNode = languageNode[DynamicBpmnConstants.LOCALIZATION_NAME];
                        if (nameNode != null)
                        {
                            localizedName = nameNode.ToString();
                        }
                        JToken descriptionNode = languageNode[DynamicBpmnConstants.LOCALIZATION_DESCRIPTION];
                        if (descriptionNode != null)
                        {
                            localizedDescription = descriptionNode.ToString();
                        }
                    }
                }

                if (foundDataObject != null)
                {
                    dataObject = new DataObjectImpl(variableEntity.Name, variableEntity.Value, foundDataObject.Documentation, foundDataObject.Type, localizedName, localizedDescription, foundDataObject.Id);
                }
            }

            return(dataObject);
        }
示例#13
0
 public virtual void AssertVariableMigratedToExecution(IVariableInstance variableBefore, string executionId)
 {
     AssertVariableMigratedToExecution(variableBefore, executionId, variableBefore.ActivityInstanceId);
 }
 void IScopeAppender.AddObjectBasedScope(IVariableInstance variable)
 {
     _operationalObjectScope.AddNativeVariable(variable);
     _conflictScope.AddNative(variable);
 }
示例#15
0
 void IScopeAppender.AddStaticBasedScope(IVariableInstance variable) => _variableNames.Add(variable.Name);
示例#16
0
 public void AddVariable(IVariableInstance variableInstance) => _staticVariables.Add(variableInstance);
 public void MakeUnsettable(DeltinScript deltinScript, IVariableInstance variableInstance)
 {
     _unsettable.Add(variableInstance);
     variableInstance.CodeType.GetCodeType(deltinScript).TypeSemantics.MakeUnsettable(deltinScript, this);
 }
 public bool IsSettable(IVariableInstance variableInstance) => !_unsettable.Contains(variableInstance);