public async Task<bool> Handle(UpdateHumanTaskDefInfoCommand request, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(request.Name))
            {
                _logger.LogError("the parameter 'name' is missing");
                throw new BadRequestException(string.Format(Global.MissingParameter, "name"));
            }

            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);
            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            var r = await _humanTaskDefQueryRepository.Search(new SearchHumanTaskDefParameter
            {
                Name = request.Name
            }, cancellationToken);
            r.Content = r.Content.Where(_ => _.AggregateId != request.Id).ToList();
            if (r != null && r.Content.Count() > 0)
            {
                _logger.LogError($"the human task '{request.Name}' already exists");
                throw new BadRequestException(string.Format(Global.HumanTaskDefExists, request.Name));
            }

            result.UpdateInfo(request.Name, request.Priority);
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);
            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);
            _logger.LogInformation($"Human task definition '{result.Name}', information has been updated");
            return true;
        }
Exemple #2
0
        public async Task <bool> Handle(AddHumanTaskDefPresentationElementCommand request, CancellationToken cancellationToken)
        {
            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            if (request.PresentationElement == null)
            {
                _logger.LogError($"The 'presentationElement' parameter is missing");
                throw new BadRequestException(string.Format(Global.MissingParameter, "parameter"));
            }

            var record = request.PresentationElement.ToDomain();

            if (result.PresentationElements.Any(_ => _.Usage == record.Usage && _.Language == record.Language))
            {
                _logger.LogError($"The presentation element already exists");
                throw new BadRequestException(Global.PresentationElementExists);
            }

            result.AddPresentationElement(record);
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Human task definition '{result.Name}', presentation element has been added");
            return(true);
        }
        public async Task <bool> Handle(UpdateHumanTaskDefDeadlineCommand request, CancellationToken cancellationToken)
        {
            if (request.DeadLineInfo == null)
            {
                _logger.LogError("the parameter 'deadLineInfo' is missing");
                throw new BadRequestException(string.Format(Global.MissingParameter, "deadLineInfo"));
            }

            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            result.UpdateDeadline(request.DeadLineId,
                                  request.DeadLineInfo.Name,
                                  request.DeadLineInfo.For,
                                  request.DeadLineInfo.Until);
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            return(true);
        }
Exemple #4
0
        public async Task <bool> Handle(DeleteHumanTaskDefDeadlineCommand request, CancellationToken cancellationToken)
        {
            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            result.DeleteDeadLine(request.DeadLineId);
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            return(true);
        }
Exemple #5
0
        public async Task <bool> Handle(DeleteHumanTaskDefParameterCommand request, CancellationToken cancellationToken)
        {
            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            result.RemoveParameter(request.ParameterId);
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Human task definition '{result.Name}', operation parameter '{request.ParameterId}' has been removed");
            return(true);
        }
        public async Task <bool> Handle(DeleteHumanTaskDefPresentationElementCommand request, CancellationToken cancellationToken)
        {
            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            result.DeletePresentationElement(request.Usage, request.Language);
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Human task definition '{result.Name}', presentation element has been remvoed");
            return(true);
        }
        public async Task <bool> Handle(AddHumanTaskDefPresentationParameterCommand request, CancellationToken cancellationToken)
        {
            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            if (request.PresentationParameter == null)
            {
                _logger.LogError($"The 'presentationParameter' parameter is missing");
                throw new BadRequestException(string.Format(Global.MissingParameter, "parameter"));
            }

            result.AddPresentationParameter(request.PresentationParameter.ToDomain());
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Human task definition '{result.Name}', presentation parameter '{request.PresentationParameter.Name}' has been added");
            return(true);
        }
Exemple #8
0
        public async Task <bool> Handle(UpdateHumanTaskDefEscalationDeadlineCommand request, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(request.Condition))
            {
                _logger.LogError("the parameter 'condition' is missing");
                throw new BadRequestException(string.Format(Global.MissingParameter, "condition"));
            }

            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            result.UpdateEscalationDeadline(request.DeadlineId, request.EscalationId, request.Condition, request.NotificationId);
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation("Escalation has been updated");
            return(true);
        }
Exemple #9
0
        public async Task <string> Handle(AddHumanTaskDefPeopleAssignmentCommand request, CancellationToken cancellationToken)
        {
            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            if (request.PeopleAssignment == null)
            {
                _logger.LogError($"The 'peopleAssignment' parameter is missing");
                throw new BadRequestException(string.Format(Global.MissingParameter, "peopleAssignment"));
            }

            var id = result.Assign(request.PeopleAssignment.ToDomain());
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Human task definition '{result.Name}', people is assigned");
            return(id);
        }
        public async Task <string> Handle(AddHumanTaskDefDeadLineCommand request, CancellationToken cancellationToken)
        {
            if (request.DeadLine == null)
            {
                _logger.LogError("the parameter 'deadLine' is missing");
                throw new BadRequestException(string.Format(Global.MissingParameter, "deadLine"));
            }

            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            var id = result.AddDeadLine(request.DeadLine.ToDomain());
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Human task definition '{result.Name}', deadline '{request.DeadLine.Name}' has been added");
            return(id);
        }
Exemple #11
0
        public async Task <bool> Handle(DeleteHumanTaskDefPresentationParameterCommand request, CancellationToken cancellationToken)
        {
            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            if (string.IsNullOrWhiteSpace(request.Name))
            {
                _logger.LogError($"The 'name' parameter is missing");
                throw new BadRequestException(string.Format(Global.MissingParameter, "name"));
            }

            result.DeletePresentationParameter(request.Name);
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Human task definition '{result.AggregateId}', presentation parameter '{request.Name}' has been removed");
            return(true);
        }
        public async Task <bool> Handle(UpdateHumanTaskDefRenderingCommand request, CancellationToken cancellationToken)
        {
            if (request.Rendering == null)
            {
                _logger.LogError("the parameter 'rendering' is missing");
                throw new BadRequestException(string.Format(Global.MissingParameter, "rendering"));
            }

            var result = await _humanTaskDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The human task definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.Id));
            }

            result.UpdateRendering(request.Rendering.ToString());
            await _humanTaskDefCommandRepository.Update(result, cancellationToken);

            await _humanTaskDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation("The rendering has been updated");
            return(true);
        }
        public async Task <TaskInstanceCreatedResult> Handle(CreateHumanTaskInstanceCommand request, CancellationToken cancellationToken)
        {
            if (request.Claims == null || !request.Claims.Any())
            {
                _logger.LogError("User is not authenticated");
                throw new NotAuthenticatedException(Global.UserNotAuthenticated);
            }

            var humanTaskDef = await _humanTaskDefQueryRepository.GetLatest(request.HumanTaskName, cancellationToken);

            if (humanTaskDef == null)
            {
                _logger.LogError($"Human task definition '{request.HumanTaskName}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownHumanTaskDef, request.HumanTaskName));
            }

            var operationParameters = request.OperationParameters == null ? new Dictionary <string, string>() : request.OperationParameters;
            var parameters          = _parameterParser.ParseOperationParameters(humanTaskDef.InputParameters, operationParameters);
            var assignment          = EnrichAssignment(humanTaskDef, request);
            var priority            = EnrichPriority(humanTaskDef, request);
            var assignmentInstance  = _parameterParser.ParsePeopleAssignments(assignment, parameters);

            if (!request.IgnorePermissions)
            {
                var roles = await _authorizationHelper.GetRoles(assignmentInstance, request.Claims, cancellationToken);

                if (!roles.Any(r => r == UserRoles.TASKINITIATOR))
                {
                    _logger.LogError("User is not a task initiator");
                    throw new NotAuthorizedException(Global.UserNotAuthorized);
                }
            }

            _logger.LogInformation($"Create human task '{request.HumanTaskName}'");
            var userPrincipal        = request.NameIdentifier;
            var id                   = Guid.NewGuid().ToString();
            var deadLines            = _deadlineParser.Evaluate(humanTaskDef.DeadLines, parameters);
            var presentationElements = _parameterParser.ParsePresentationElements(humanTaskDef.PresentationElements, humanTaskDef.PresentationParameters, operationParameters);
            var humanTaskInstance    = HumanTaskInstanceAggregate.New(
                id,
                userPrincipal,
                request.HumanTaskName,
                humanTaskDef.ValidatorFullQualifiedName,
                parameters,
                assignmentInstance,
                priority,
                request.ActivationDeferralTime,
                request.ExpirationTime,
                deadLines,
                presentationElements,
                humanTaskDef.Type,
                humanTaskDef.InstantiationPattern,
                humanTaskDef.SubTasks.Select(_ => new HumanTaskInstanceSubTask
            {
                HumanTaskName = _.TaskName,
                ToParts       = _.ToParts
            }).ToList(),
                humanTaskDef.OperationParameters,
                humanTaskDef.CompletionAction,
                humanTaskDef.Completions,
                humanTaskDef.Rendering,
                request.CallbackUrls == null ? new List <CallbackOperation>() : request.CallbackUrls.Select(_ => new CallbackOperation
            {
                Id  = Guid.NewGuid().ToString(),
                Url = _
            }).ToList());
            await _humanTaskInstanceCommandRepository.Add(humanTaskInstance, cancellationToken);

            await _humanTaskInstanceCommandRepository.SaveChanges(cancellationToken);

            humanTaskDef.IncrementInstance();
            await _humanTaskDefCommandRepository.Update(humanTaskDef, cancellationToken);

            return(new TaskInstanceCreatedResult
            {
                Id = humanTaskInstance.AggregateId,
                DefId = humanTaskDef.AggregateId
            });
        }