private async Task <CompletionBehaviorResult> CheckCompletionBehavior(HumanTaskInstanceAggregate humanTaskInstance, Dictionary <string, string> parameters, CancellationToken token, bool raiseException = true) { if (humanTaskInstance.Completions == null || !humanTaskInstance.Completions.Any()) { return(new CompletionBehaviorResult { IsSatisfied = false }); } var subTasks = await _humanTaskInstanceQueryRepository.GetSubTasks(humanTaskInstance.AggregateId, token); var executionContext = new HumanTaskInstanceExpressionContext(humanTaskInstance, parameters, subTasks); var result = new Dictionary <string, string>(); foreach (var completion in humanTaskInstance.Completions) { if (string.IsNullOrWhiteSpace(completion.Condition) || ExpressionParser.IsValid(completion.Condition, executionContext)) { foreach (var copy in completion.CopyLst) { result.Add(copy.To, ExpressionParser.GetString(copy.From, executionContext)); } break; } } if (raiseException && !result.Any()) { _logger.LogError("At least one completion behavior must be satisfied"); throw new BadOperationExceptions(Global.CompletionBehaviorMustBeSatisfied); } return(new CompletionBehaviorResult { IsSatisfied = true, Content = result }); }
public async Task <string> Handle(InstantiateSubTaskCommand request, CancellationToken cancellationToken) { if (request.Claims == null || !request.Claims.Any()) { _logger.LogError("User is not authenticated"); throw new NotAuthenticatedException(Global.UserNotAuthenticated); } var humanTaskInstance = await _humanTaskInstanceQueryRepository.Get(request.HumanTaskInstanceId, cancellationToken); if (humanTaskInstance == null) { _logger.LogError($"HumanTask '{request.HumanTaskInstanceId}' doesn't exist"); throw new UnknownHumanTaskInstanceException(string.Format(Global.UnknownHumanTaskInstance, request.HumanTaskInstanceId)); } var subTask = humanTaskInstance.SubTasks.FirstOrDefault(_ => _.HumanTaskName == request.SubTaskName); if (subTask == null) { _logger.LogError($"'{request.SubTaskName}' is not a subtask of '{humanTaskInstance.HumanTaskDefName}'"); throw new BadRequestException(string.Format(Global.NotSubTask, request.SubTaskName, humanTaskInstance.HumanTaskDefName)); } var subTasks = await _humanTaskInstanceQueryRepository.GetSubTasks(humanTaskInstance.AggregateId, cancellationToken); if (subTasks.Any(_ => _.HumanTaskDefName == request.SubTaskName)) { _logger.LogError($"The sub task '{request.SubTaskName}' is already created"); throw new BadRequestException(string.Format(Global.SubTaskAlreadyCreated, request.SubTaskName)); } var operationParameters = _parameterParser.ParseToPartParameters(subTask.ToParts, humanTaskInstance.InputParameters); var result = await _mediator.Send(new CreateHumanTaskInstanceCommand { Claims = request.Claims, HumanTaskName = request.SubTaskName, OperationParameters = operationParameters, IgnorePermissions = true }, cancellationToken); var hi = await _humanTaskInstanceQueryRepository.Get(result, cancellationToken); hi.SetParent(humanTaskInstance.HumanTaskDefName, humanTaskInstance.AggregateId); await _humanTaskInstanceCommandRepository.Update(hi, cancellationToken); await _humanTaskInstanceCommandRepository.SaveChanges(cancellationToken); return(result); }
public async Task <SubTasksResults> Handle(GetHumanTaskInstanceSubTasksQuery request, CancellationToken cancellationToken) { var humanTaskInstance = await _humanTaskInstanceQueryRepository.Get(request.HumanTaskInstanceId, cancellationToken); if (humanTaskInstance == null) { _logger.LogError($"HumanTask '{request.HumanTaskInstanceId}' doesn't exist"); throw new UnknownHumanTaskInstanceException(string.Format(Global.UnknownHumanTaskInstance, request.HumanTaskInstanceId)); } var callbackTxt = new Func <ICollection <PresentationElementInstance>, Localization.Translation>((t) => { if (t == null || !t.Any()) { return(null); } try { return(_translationHelper.Translate(t)); } catch (BadOperationExceptions) { return(null); } }); var result = await _humanTaskInstanceQueryRepository.GetSubTasks(humanTaskInstance.AggregateId, cancellationToken); ICollection <TaskInstanceDetailsResult> content = result.Select(_ => { var name = callbackTxt(_.Names); var subject = callbackTxt(_.Subjects); return(TaskInstanceDetailsResult.ToDto(_, name, subject, null, null)); }).ToList(); return(new SubTasksResults { Content = content }); }