public virtual void testDecisionInstancePropertiesOfDecisionLiteralExpression()
        {
            IDecisionDefinition decisionDefinition = repositoryService.CreateDecisionDefinitionQuery().First();

            decisionService.EvaluateDecisionByKey("decision").Variables(ESS.FW.Bpm.Engine.Variable.Variables.CreateVariables().PutValue("sum", 2205)).Evaluate();

            IQueryable <IHistoricDecisionInstance> query = historyService.CreateHistoricDecisionInstanceQuery() /*/*.IncludeInputs()*//*.IncludeOutputs()*/;

            Assert.That(query.Count(), Is.EqualTo(1L));

            IHistoricDecisionInstance historicDecisionInstance = query.First();

            Assert.That(historicDecisionInstance.DecisionDefinitionId, Is.EqualTo(decisionDefinition.Id));
            Assert.That(historicDecisionInstance.DecisionDefinitionKey, Is.EqualTo("decision"));
            Assert.That(historicDecisionInstance.DecisionDefinitionName, Is.EqualTo("Decision with Literal Expression"));
            Assert.That(historicDecisionInstance.EvaluationTime, Is.Not.Null);

            Assert.That(historicDecisionInstance.Inputs.Count, Is.EqualTo(0));

            IList <IHistoricDecisionOutputInstance> outputs = historicDecisionInstance.Outputs;

            Assert.That(outputs.Count, Is.EqualTo(1));

            IHistoricDecisionOutputInstance output = outputs[0];

            Assert.That(output.VariableName, Is.EqualTo("result"));
            Assert.That(output.TypeName, Is.EqualTo("string"));
            Assert.That((string)output.Value, Is.EqualTo("ok"));

            Assert.That(output.ClauseId, Is.EqualTo(null));
            Assert.That(output.ClauseName, Is.EqualTo(null));
            Assert.That(output.RuleId, Is.EqualTo(null));
            Assert.That(output.RuleOrder, Is.EqualTo(null));
        }
Esempio n. 2
0
        //protected internal virtual void SetReferenceToCaseInstance(HistoricDecisionInstanceEntity @event,
        //    CaseExecutionEntity execution)
        //{
        //    @event.CaseDefinitionKey = GetCaseDefinitionKey(execution);
        //    @event.CaseDefinitionId = execution.CaseDefinitionId;

        //    @event.CaseInstanceId = execution.CaseInstanceId;
        //    @event.ExecutionId = execution.Id;

        //    @event.ActivityId = execution.ActivityId;
        //    @event.ActivityInstanceId = execution.Id;
        //}

        //protected internal virtual string GetCaseDefinitionKey(CaseExecutionEntity execution)
        //{
        //    //CaseDefinitionEntity definition = (CaseDefinitionEntity) execution.CaseDefinition;
        //    //if (definition != null)
        //    //{
        //    //  return definition.Key;
        //    //}
        //    //else
        //    //{
        //    return null;
        //    //}
        //}

        protected internal virtual string ProvideTenantId(IDecisionDefinition decisionDefinition,
                                                          HistoricDecisionInstanceEntity @event)
        {
            var    tenantIdProvider = Context.ProcessEngineConfiguration.TenantIdProvider;
            string tenantId         = null;

            if (tenantIdProvider != null)
            {
                TenantIdProviderHistoricDecisionInstanceContext ctx = null;

                if (!ReferenceEquals(@event.ExecutionId, null))
                {
                    //ctx = new TenantIdProviderHistoricDecisionInstanceContext(decisionDefinition, getExecution(@event));
                }
                else if (!ReferenceEquals(@event.CaseExecutionId, null))
                {
                    //ctx = new TenantIdProviderHistoricDecisionInstanceContext(decisionDefinition, getCaseExecution(@event));
                }
                else
                {
                    ctx = new TenantIdProviderHistoricDecisionInstanceContext(decisionDefinition);
                }

                tenantId = tenantIdProvider.ProvideTenantIdForHistoricDecisionInstance(ctx);
            }

            return(tenantId);
        }
Esempio n. 3
0
        //public static CmmnCaseDefinition getCaseDefinitionToCall(IVariableScope execution, BaseCallableElement callableElement)
        //{
        //    string caseDefinitionKey = callableElement.getDefinitionKey(execution);
        //    string tenantId = callableElement.getDefinitionTenantId(execution);

        //    DeploymentCache deploymentCache = DeploymentCache;

        //    CmmnCaseDefinition caseDefinition = null;
        //    if (callableElement.LatestBinding)
        //    {
        //        caseDefinition = deploymentCache.findDeployedLatestCaseDefinitionByKeyAndTenantId(caseDefinitionKey, tenantId);

        //    }
        //    else if (callableElement.DeploymentBinding)
        //    {
        //        string deploymentId = callableElement.DeploymentId;
        //        caseDefinition = deploymentCache.findDeployedCaseDefinitionByDeploymentAndKey(deploymentId, caseDefinitionKey);

        //    }
        //    else if (callableElement.VersionBinding)
        //    {
        //        int? version = callableElement.getVersion(execution);
        //        caseDefinition = deploymentCache.findDeployedCaseDefinitionByKeyVersionAndTenantId(caseDefinitionKey, version, tenantId);
        //    }

        //    return caseDefinition;
        //}

        public static IDecisionDefinition GetDecisionDefinitionToCall(IVariableScope execution,
                                                                      BaseCallableElement callableElement)
        {
            var decisionDefinitionKey = callableElement.GetDefinitionKey(execution);
            var tenantId = callableElement.GetDefinitionTenantId(execution);

            DeploymentCache deploymentCache = DeploymentCache;

            IDecisionDefinition decisionDefinition = null;

            if (callableElement.LatestBinding)
            {
                decisionDefinition =
                    deploymentCache.FindDeployedLatestDecisionDefinitionByKeyAndTenantId(decisionDefinitionKey, tenantId);
            }
            else if (callableElement.DeploymentBinding)
            {
                var deploymentId = callableElement.DeploymentId;
                decisionDefinition = deploymentCache.FindDeployedDecisionDefinitionByDeploymentAndKey(deploymentId,
                                                                                                      decisionDefinitionKey);
            }
            else if (callableElement.VersionBinding)
            {
                var version = callableElement.GetVersion(execution);
                decisionDefinition =
                    deploymentCache.FindDeployedDecisionDefinitionByKeyVersionAndTenantId(decisionDefinitionKey, version,
                                                                                          tenantId);
            }

            return(decisionDefinition);
        }
Esempio n. 4
0
        protected internal virtual IDecisionDefinition FindByKey(DeploymentCache deploymentCache)
        {
            IDecisionDefinition decisionDefinition = null;

            if (Version == null && !IsTenandIdSet)
            {
                decisionDefinition = deploymentCache.FindDeployedLatestDecisionDefinitionByKey(DecisionDefinitionKey);
            }
            else if (Version == null && IsTenandIdSet)
            {
                decisionDefinition =
                    deploymentCache.FindDeployedLatestDecisionDefinitionByKeyAndTenantId(DecisionDefinitionKey,
                                                                                         DecisionDefinitionTenantId);
            }
            else if (Version != null && !IsTenandIdSet)
            {
                decisionDefinition = deploymentCache.FindDeployedDecisionDefinitionByKeyAndVersion(
                    DecisionDefinitionKey, Version);
            }
            else if (Version != null && IsTenandIdSet)
            {
                decisionDefinition =
                    deploymentCache.FindDeployedDecisionDefinitionByKeyVersionAndTenantId(DecisionDefinitionKey, Version,
                                                                                          DecisionDefinitionTenantId);
            }

            return(decisionDefinition);
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER WARNING: MethodInfo 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.camunda.bpm.dmn.engine.DmnDecisionResult evaluateDecision(org.camunda.bpm.engine.repository.DecisionDefinition decisionDefinition, org.camunda.bpm.engine.Variable.VariableMap variables) throws Exception
        public static IDmnDecisionResult EvaluateDecision(IDecisionDefinition decisionDefinition, IVariableMap variables)
        {
            var invocation = CreateInvocation(decisionDefinition, variables);

            Invoke(invocation);
            return((IDmnDecisionResult)invocation.InvocationResult);
        }
Esempio n. 6
0
 public virtual void CheckEvaluateDecision(IDecisionDefinition decisionDefinition)
 {
     if (!TenantManager.IsAuthenticatedTenant(decisionDefinition.TenantId))
     {
         throw Log.ExceptionCommandWithUnauthorizedTenant("evaluate the decision '" + decisionDefinition.Id + "'");
     }
 }
Esempio n. 7
0
        public virtual void evaluateDecisionTableById()
        {
            IDecisionDefinition decisionDefinition = repositoryService.CreateDecisionDefinitionQuery().First();

            IDmnDecisionTableResult decisionResult = decisionService.EvaluateDecisionTableById(decisionDefinition.Id, createVariables());

            AssertThatDecisionHasResult(decisionResult, RESULT_OF_FIRST_VERSION);
        }
Esempio n. 8
0
//JAVA TO C# CONVERTER WARNING: MethodInfo 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static org.camunda.bpm.dmn.engine.DmnDecisionTableResult evaluateDecisionTable(org.camunda.bpm.engine.repository.DecisionDefinition decisionDefinition, org.camunda.bpm.engine.Variable.VariableMap variables) throws Exception
        public static IDmnDecisionTableResult EvaluateDecisionTable(IDecisionDefinition decisionDefinition,
                                                                    IVariableMap variables)
        {
            // doesn't throw an exception if the decision definition is not implemented as decision table
            var decisionResult = EvaluateDecision(decisionDefinition, variables);

            return((IDmnDecisionTableResult)DmnDecisionTableResultImpl.Wrap(decisionResult));
        }
        public virtual void getDecisionDefinitionDisabledTenantCheck()
        {
            processEngineConfiguration.SetTenantCheckEnabled(false);
            identityService.SetAuthentication("user", null, null);

            IDecisionDefinition definition = repositoryService.GetDecisionDefinition(decisionDefinitionId);

            Assert.That(definition.TenantId, Is.EqualTo(TENANT_ONE));
        }
Esempio n. 10
0
 protected internal virtual void CreateDefaultAuthorizations(IDecisionDefinition decisionDefinition)
 {
     if (AuthorizationEnabled)
     {
         throw new NotImplementedException();
         //ResourceAuthorizationProvider provider = ResourceAuthorizationProvider;
         //AuthorizationEntity[] authorizations = provider.newDecisionDefinition(decisionDefinition);
         //saveDefaultAuthorizations(authorizations);
     }
 }
Esempio n. 11
0
        public virtual void evaluateDecisionByKeyWithNonExistingVersion()
        {
            IDecisionDefinition decisionDefinition = repositoryService.CreateDecisionDefinitionQuery().First();

            //thrown.Expect(typeof(NotFoundException));
            //thrown.ExpectMessage("no decision definition deployed with key = 'decision' and version = '42'");

            decisionService.EvaluateDecisionByKey(decisionDefinition.Key).Version(42).Evaluate();
            Assert.Fail("no decision definition deployed with key = 'decision' and version = '42'");
        }
        public virtual void getDecisionDefinitionWithAuthenticatedTenant()
        {
            identityService.SetAuthentication("user", null, new List <string>()
            {
                TENANT_ONE
            });

            IDecisionDefinition definition = repositoryService.GetDecisionDefinition(decisionDefinitionId);

            Assert.That(definition.TenantId, Is.EqualTo(TENANT_ONE));
        }
        public virtual void updateHistoryTimeToLiveDisabledTenantCheck()
        {
            processEngineConfiguration.SetTenantCheckEnabled(false);
            identityService.SetAuthentication("user", null, null);

            repositoryService.UpdateDecisionDefinitionHistoryTimeToLive(decisionDefinitionId, 6);

            IDecisionDefinition definition = repositoryService.GetDecisionDefinition(decisionDefinitionId);

            Assert.That(definition.TenantId, Is.EqualTo(TENANT_ONE));
            //Assert.That(definition.HistoryTimeToLive, Is.EqualTo(6));
        }
Esempio n. 14
0
        public virtual void testGetDecisionDefinition()
        {
            // given
            string decisionDefinitionId = selectDecisionDefinitionByKey(DECISION_DEFINITION_KEY).Id;

            createGrantAuthorization(Resources.DecisionDefinition, DECISION_DEFINITION_KEY, userId, Permissions.Read);

            // when
            IDecisionDefinition decisionDefinition = repositoryService.GetDecisionDefinition(decisionDefinitionId);

            // then
            Assert.NotNull(decisionDefinition);
        }
Esempio n. 15
0
 protected internal virtual IDmnDecisionResult DoEvaluateDecision(IDecisionDefinition decisionDefinition,
                                                                  IVariableMap variables)
 {
     try
     {
         return(DecisionEvaluationUtil.EvaluateDecision(decisionDefinition, variables));
     }
     catch (System.Exception e)
     {
         throw new ProcessEngineException(
                   "Exception while evaluating decision with key '" + DecisionDefinitionKey + "'", e);
     }
 }
        public virtual void updateHistoryTimeToLiveWithAuthenticatedTenant()
        {
            identityService.SetAuthentication("user", null, new List <string>()
            {
                TENANT_ONE
            });

            repositoryService.UpdateDecisionDefinitionHistoryTimeToLive(decisionDefinitionId, 6);

            IDecisionDefinition definition = repositoryService.GetDecisionDefinition(decisionDefinitionId);

            Assert.That(definition.TenantId, Is.EqualTo(TENANT_ONE));
            //Assert.That(definition.HistoryTimeToLive, Is.EqualTo(6));
        }
        [Test]   public virtual void testQueryByLatestWithoutTenantId()
        {
            // deploy a second version without tenant id
            Deployment(DMN);

            IQueryable <IDecisionDefinition> query = repositoryService.CreateDecisionDefinitionQuery(c => c.Key == DECISION_DEFINITION_KEY) /*.LatestVersion(c=>c.TenantId == null)*/;

            Assert.That(query.Count(), Is.EqualTo(1L));

            IDecisionDefinition decisionDefinition = query.First();

            Assert.That(decisionDefinition.TenantId, Is.EqualTo(null));
            Assert.That(decisionDefinition.Version, Is.EqualTo(2));
        }
        public virtual void testDeleteHistoricDecisionInstances()
        {
            IQueryable <IHistoricDecisionInstance> query = historyService.CreateHistoricDecisionInstanceQuery(c => c.DecisionDefinitionKey == DECISION_DEFINITION_KEY);

            startProcessInstanceAndEvaluateDecision();

            Assert.That(query.Count(), Is.EqualTo(1L));

            IDecisionDefinition decisionDefinition = repositoryService.CreateDecisionDefinitionQuery().First();

            historyService.DeleteHistoricDecisionInstanceByDefinitionId(decisionDefinition.Id);

            Assert.That(query.Count(), Is.EqualTo(0L));
        }
        [Test]   public virtual void testEvaluateDecisionByIdAuthenticatedTenant()
        {
            DeploymentForTenant(TENANT_ONE, DMN_FILE);

            IDecisionDefinition decisionDefinition = repositoryService.CreateDecisionDefinitionQuery().First();

            identityService.SetAuthentication("user", null, new List <string>()
            {
                TENANT_ONE
            });

            IDmnDecisionResult decisionResult = decisionService.EvaluateDecisionById(decisionDefinition.Id).Variables(createVariables()).Evaluate();

            AssertThatDecisionHasResult(decisionResult, RESULT_OF_FIRST_VERSION);
        }
Esempio n. 20
0
        public virtual void evaluateDecisionByKey()
        {
            // given
            IDecisionDefinition decisionDefinition = engineRule.RepositoryService.CreateDecisionDefinitionQuery().First();

            // when
            authRule.Init(scenario).WithUser("userId").BindResource("decisionDefinitionKey", DECISION_DEFINITION_KEY).Start();

            IDmnDecisionTableResult decisionResult = engineRule.DecisionService.EvaluateDecisionTableByKey(decisionDefinition.Key, createVariables());

            // then
            if (authRule.AssertScenario(scenario))
            {
                AssertThatDecisionHasExpectedResult(decisionResult);
            }
        }
Esempio n. 21
0
        public virtual void testQueryWithReadPermissionOnOneDecisionDefinition()
        {
            // given user gets read permission on the decision definition
            createGrantAuthorization(Resources.DecisionDefinition, DECISION_DEFINITION_KEY, userId, Permissions.Read);

            // when
            IQueryable <IDecisionDefinition> query = repositoryService.CreateDecisionDefinitionQuery();

            // then
            //verifyQueryResults(query, 1);

            IDecisionDefinition definition = query.First();

            Assert.NotNull(definition);
            Assert.AreEqual(DECISION_DEFINITION_KEY, definition.Key);
        }
        [Test]   public virtual void testFailToEvaluateDecisionByIdWithTenantId()
        {
            DeploymentForTenant(TENANT_ONE, DMN_FILE);

            IDecisionDefinition decisionDefinition = repositoryService.CreateDecisionDefinitionQuery().First();

            try
            {
                decisionService.EvaluateDecisionById(decisionDefinition.Id).Variables(createVariables()).DecisionDefinitionTenantId(TENANT_ONE).Evaluate();
                Assert.Fail("BadUserRequestException exception");
            }
            catch (BadUserRequestException e)
            {
                Assert.That(e.Message, Does.Contain("Cannot specify a tenant-id"));
            }
        }
        [Test]   public virtual void testFailToEvaluateDecisionByIdNoAuthenticatedTenants()
        {
            DeploymentForTenant(TENANT_ONE, DMN_FILE);

            IDecisionDefinition decisionDefinition = repositoryService.CreateDecisionDefinitionQuery().First();

            identityService.SetAuthentication("user", null, null);

            try
            {
                decisionService.EvaluateDecisionById(decisionDefinition.Id).Variables(createVariables()).Evaluate();

                Assert.Fail("expected exception");
            }
            catch (ProcessEngineException e)
            {
                Assert.That(e.Message, Does.Contain("Cannot evaluate the decision"));
            }
        }
        [Test]   public virtual void testQueryByLatestWithTenantId()
        {
            // deploy a second version for tenant one
            DeploymentForTenant(TENANT_ONE, DMN);

            IQueryable <IDecisionDefinition> query = repositoryService.CreateDecisionDefinitionQuery(c => c.Key == DECISION_DEFINITION_KEY) /*.LatestVersion(c=>c.TenantId == TENANT_ONE)*/;

            Assert.That(query.Count(), Is.EqualTo(1L));

            IDecisionDefinition decisionDefinition = query.First();

            Assert.That(decisionDefinition.TenantId, Is.EqualTo(TENANT_ONE));
            Assert.That(decisionDefinition.Version, Is.EqualTo(2));

            query = repositoryService.CreateDecisionDefinitionQuery(c => c.Key == DECISION_DEFINITION_KEY) /*.LatestVersion(c=>c.TenantId == TENANT_TWO)*/;

            Assert.That(query.Count(), Is.EqualTo(1L));

            decisionDefinition = query.First();
            Assert.That(decisionDefinition.TenantId, Is.EqualTo(TENANT_TWO));
            Assert.That(decisionDefinition.Version, Is.EqualTo(1));
        }
Esempio n. 25
0
 protected internal static DecisionInvocation CreateInvocation(IDecisionDefinition decisionDefinition,
                                                               IVariableMap variables)
 {
     return(CreateInvocation(decisionDefinition, variables.AsVariableContext()));
 }
Esempio n. 26
0
 protected internal static DecisionInvocation CreateInvocation(IDecisionDefinition decisionDefinition,
                                                               IVariableContext variableContext)
 {
     return(new DecisionInvocation(decisionDefinition, variableContext));
 }
Esempio n. 27
0
 protected internal static DecisionInvocation CreateInvocation(IDecisionDefinition decisionDefinition,
                                                               AbstractVariableScope variableScope)
 {
     return(CreateInvocation(decisionDefinition, VariableScopeContext.Wrap(variableScope)));
 }
 public TenantIdProviderHistoricDecisionInstanceContext(IDecisionDefinition decisionDefinition)
 {
     this.decisionDefinition = decisionDefinition;
 }
 public TenantIdProviderHistoricDecisionInstanceContext(IDecisionDefinition decisionDefinition,
                                                        IDelegateCaseExecution caseExecution) : this(decisionDefinition)
 {
     this.caseExecution = caseExecution;
 }
Esempio n. 30
0
 public DecisionInvocation(IDecisionDefinition decisionDefinition, IVariableContext variableContext)
     : base(null, (DecisionDefinitionEntity)decisionDefinition)
 {
     this.decisionDefinition = decisionDefinition;
     this.VariableContext    = variableContext;
 }