Esempio n. 1
0
            public static CasePlanItemInstanceResult ToDto(CaseEltInstance casePlanItemInstance)
            {
                string stateStr = null, formId = null;

                if (casePlanItemInstance.IsTaskOrStage())
                {
                    stateStr = casePlanItemInstance.TakeStageState == null ? null : Enum.GetName(typeof(TaskStageStates), casePlanItemInstance.TakeStageState);
                }

                if (casePlanItemInstance.IsMilestone())
                {
                    stateStr = casePlanItemInstance.MilestoneState == null ? null : Enum.GetName(typeof(MilestoneEventStates), casePlanItemInstance.MilestoneState);
                }

                if (casePlanItemInstance.Type == CasePlanElementInstanceTypes.HUMANTASK)
                {
                    formId = casePlanItemInstance.GetFormId();
                }

                return(new CasePlanItemInstanceResult
                {
                    Id = casePlanItemInstance.Id,
                    Name = casePlanItemInstance.Name,
                    NbOccurrence = casePlanItemInstance.NbOccurrence,
                    EltId = casePlanItemInstance.EltId,
                    State = stateStr,
                    FormId = formId,
                    Type = Enum.GetName(typeof(CasePlanElementInstanceTypes), casePlanItemInstance.Type).ToUpperInvariant(),
                    TransitionHistories = casePlanItemInstance.TransitionHistories.Select(_ => TransitionHistoryResult.ToDto(_)).ToList()
                });
            }
Esempio n. 2
0
        public async Task <string> Create(CMMNExecutionContext executionContext, CaseEltInstance humanTaskElt, CancellationToken token)
        {
            using (var httpClient = _httpClientFactory.Build())
            {
                var operationParameters = new JObject
                {
                    { "nameIdentifier", executionContext.Instance.NameIdentifier }
                };

                var inputParameters = humanTaskElt.GetInputParameters();
                if (inputParameters != null && inputParameters.Any())
                {
                    foreach (var inputParameter in inputParameters)
                    {
                        if (string.IsNullOrWhiteSpace(inputParameter.Value))
                        {
                            continue;
                        }

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

                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 CMMNProcessorException(tokenResponse.Error);
                }

                var jArr = new JArray();
                var link = _options.CallbackUrl.Replace("{id}", executionContext.Instance.AggregateId);
                link = link.Replace("{eltId}", humanTaskElt.Id);
                jArr.Add(link);
                var obj = new JObject
                {
                    { "humanTaskName", humanTaskElt.GetFormId() },
                    { "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();
                return(humanTaskInstancId);
            }
        }