예제 #1
0
        public void Parse_Parameter()
        {
            // ARRANGE
            var message        = "Please update the password by clicking on the website {{configuration.Get('humanTaskUrl')}}/humantasks/{{messages.Get('humanTaskCreated', 'humanTaskInstance.fileId')}}/instances/{{messages.Get('humanTaskCreated', 'humanTaskInstance.id')}}?auth=email";
            var incomingTokens = new List <MessageToken>
            {
                MessageToken.NewMessage(Guid.NewGuid().ToString(), "humanTaskCreated", new JObject
                {
                    { "humanTaskInstance", new JObject
                      {
                          { "id", "id" },
                          { "fileId", "fileId" }
                      } }
                }.ToString())
            };
            var configuration = new DelegateConfigurationAggregate();

            configuration.AddRecord("humanTaskUrl", "http://localhost:4200");

            // ACT
            var result = DelegateHelper.Parse(configuration, incomingTokens, message);

            // ASSERT
            Assert.Equal("Please update the password by clicking on the website http://localhost:4200/humantasks/fileId/instances/id?auth=email", result);
        }
예제 #2
0
        public async Task <ICollection <MessageToken> > Execute(BPMNExecutionContext context, ICollection <MessageToken> incoming, DelegateConfigurationAggregate delegateConfiguration, CancellationToken cancellationToken)
        {
            var user = incoming.FirstOrDefault(i => i.Name == "user");

            if (user == null)
            {
                throw new BPMNProcessorException("user must be passed in the request");
            }

            var userId = user.GetProperty("userId");

            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new BPMNProcessorException("userId is not passed in the request");
            }

            var parameter = GenerateOTPPasswordParameter.Create(delegateConfiguration);

            using (var httpClient = new HttpClient())
            {
                var tokenResponse = await httpClient.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
                {
                    Address      = parameter.TokenUrl,
                    ClientId     = parameter.ClientId,
                    ClientSecret = parameter.ClientSecret,
                    Scope        = parameter.Scope
                }, cancellationToken);

                if (tokenResponse.IsError)
                {
                    throw new BPMNProcessorException(tokenResponse.Error);
                }

                var url     = parameter.UserUrl.Replace("{id}", userId);
                var request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Get,
                    RequestUri = new Uri(url)
                };
                request.Headers.Add("Authorization", $"Bearer {tokenResponse.AccessToken}");
                var httpResponse = await httpClient.SendAsync(request, cancellationToken);

                httpResponse.EnsureSuccessStatusCode();
                var content = await httpResponse.Content.ReadAsStringAsync();

                var otp = long.Parse(content);
                ICollection <MessageToken> result = new List <MessageToken>
                {
                    MessageToken.NewMessage(context.Pointer.InstanceFlowNodeId, "otp", new JObject
                    {
                        { "otpCode", otp }
                    }.ToString())
                };
                return(result);
            }
        }
        public Task <ICollection <MessageToken> > Execute(BPMNExecutionContext context, ICollection <MessageToken> incoming, DelegateConfigurationAggregate delegateConfiguration, CancellationToken cancellationToken)
        {
            ICollection <MessageToken> result = new List <MessageToken>();

            result.Add(MessageToken.NewMessage(context.Pointer.InstanceFlowNodeId, "weatherInformation", new JObject
            {
                { "city", "Bruxelles" },
                { "degree", "31" }
            }.ToString()));
            return(Task.FromResult(result));
        }
예제 #4
0
        public Task <ICollection <MessageToken> > Execute(ICollection <MessageToken> incoming, CancellationToken cancellationToken)
        {
            ICollection <MessageToken> result = new List <MessageToken>();

            result.Add(MessageToken.NewMessage("weatherInformation", new JObject
            {
                { "city", "Bruxelles" },
                { "degree", "31" }
            }.ToString()));
            return(Task.FromResult(result));
        }
예제 #5
0
        public async Task <ICollection <MessageToken> > Execute(BPMNExecutionContext executionContext, UserTask userTask, CancellationToken token)
        {
            var pointer  = executionContext.Pointer;
            var instance = executionContext.Instance.GetInstance(pointer.InstanceFlowNodeId);

            if (!instance.Metadata.ContainsKey(HUMANTASK_INSTANCE_ID_NAME))
            {
                using (var httpClient = _httpClientFactory.Build())
                {
                    var operationParameters = new JObject
                    {
                        { "nameIdentifier", executionContext.Instance.NameIdentifier }
                    };
                    var ctx = new ConditionalExpressionContext(pointer.Incoming);
                    if (userTask.InputParameters != null && userTask.InputParameters.Any())
                    {
                        foreach (var inputParameter in userTask.InputParameters)
                        {
                            if (string.IsNullOrWhiteSpace(inputParameter.Value))
                            {
                                continue;
                            }

                            var value = ExpressionParser.GetString(inputParameter.Value, ctx);
                            operationParameters.Add(inputParameter.Key, value);
                        }
                    }

                    var jArr = new JArray();
                    var link = _options.CallbackUrl.Replace("{id}", executionContext.Instance.AggregateId);
                    link = link.Replace("{eltId}", pointer.InstanceFlowNodeId);
                    jArr.Add(link);
                    var tokenResponse = await httpClient.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
                    {
                        Address      = _options.OAuthTokenEndpoint,
                        ClientId     = _options.ClientId,
                        ClientSecret = _options.ClientSecret,
                        Scope        = "create_humantaskinstance"
                    }, token);

                    if (tokenResponse.IsError)
                    {
                        throw new BPMNProcessorException(tokenResponse.Error);
                    }

                    var obj = new JObject
                    {
                        { "humanTaskName", userTask.HumanTaskName },
                        { "operationParameters", operationParameters },
                        { "callbackUrls", jArr }
                    };
                    var content = new StringContent(obj.ToString(), Encoding.UTF8, "application/json");
                    var request = new HttpRequestMessage
                    {
                        Method     = HttpMethod.Post,
                        Content    = content,
                        RequestUri = new Uri($"{_options.WSHumanTaskAPI}/humantaskinstances")
                    };
                    request.Headers.Add("Authorization", $"Bearer {tokenResponse.AccessToken}");
                    var httpResult = await httpClient.SendAsync(request, token);

                    var str = await httpResult.Content.ReadAsStringAsync();

                    var o = JObject.Parse(str);
                    var humanTaskInstancId = o["id"].ToString();
                    executionContext.Instance.UpdateMetadata(pointer.InstanceFlowNodeId, HUMANTASK_INSTANCE_ID_NAME, humanTaskInstancId);
                    throw new FlowNodeInstanceBlockedException();
                }
            }

            var stateTransition = executionContext.Instance.StateTransitions.FirstOrDefault(_ => _.State == "COMPLETED" && _.FlowNodeInstanceId == pointer.InstanceFlowNodeId);

            if (stateTransition == null)
            {
                throw new FlowNodeInstanceBlockedException();
            }

            var result = new List <MessageToken>();

            if (stateTransition.Content == null)
            {
                result.Add(MessageToken.EmptyMessage());
            }
            else
            {
                result.Add(MessageToken.NewMessage(userTask.Id, stateTransition.Content));
            }

            return(result);
        }