示例#1
0
        public async Task <bool> Handle(StartHumanTaskInstanceCommand 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 roles = await _authorizationHelper.GetRoles(humanTaskInstance, request.Claims, cancellationToken);

            if (!roles.Contains(UserRoles.POTENTIALOWNER))
            {
                _logger.LogError("User is not a potentiel owner");
                throw new NotAuthorizedException(Global.UserNotAuthorized);
            }

            if (humanTaskInstance.Status != HumanTaskInstanceStatus.READY && humanTaskInstance.Status != HumanTaskInstanceStatus.RESERVED)
            {
                _logger.LogError("Claim operation can be performed only on READY / RESERVED human task instance");
                throw new BadOperationExceptions(string.Format(Global.OperationCanBePerformed, "Claim", "Ready/Reserved"));
            }

            var userPrincipal = request.Claims.GetUserNameIdentifier();

            humanTaskInstance.Start(userPrincipal);
            await _humanTaskInstanceCommandRepository.Update(humanTaskInstance, cancellationToken);

            await _humanTaskInstanceCommandRepository.SaveChanges(cancellationToken);

            if (humanTaskInstance.InstantiationPattern == InstantiationPatterns.AUTOMATIC && humanTaskInstance.SubTasks.Any())
            {
                if (humanTaskInstance.Type == CompositionTypes.PARALLEL)
                {
                    foreach (var subTask in humanTaskInstance.SubTasks)
                    {
                        await _mediator.Send(new InstantiateSubTaskCommand
                        {
                            Claims = request.Claims,
                            HumanTaskInstanceId = humanTaskInstance.AggregateId,
                            SubTaskName         = subTask.HumanTaskName
                        }, cancellationToken);
                    }
                }
            }

            return(true);
        }
        private async Task Complete(HumanTaskInstanceAggregate humanTaskInstance, Dictionary <string, string> parameters, string nameIdentifier, CancellationToken token)
        {
            humanTaskInstance.Complete(parameters, nameIdentifier);
            await _humanTaskInstanceCommandRepository.Update(humanTaskInstance, token);

            var subTasks = await _humanTaskInstanceQueryRepository.GetSubTasks(humanTaskInstance.AggregateId, token);

            foreach (var subTask in subTasks)
            {
                if (subTask.Status == HumanTaskInstanceStatus.CREATED ||
                    subTask.Status == HumanTaskInstanceStatus.READY ||
                    subTask.Status == HumanTaskInstanceStatus.RESERVED ||
                    subTask.Status == HumanTaskInstanceStatus.INPROGRESS)
                {
                    subTask.Skip(nameIdentifier);
                    await _humanTaskInstanceCommandRepository.Update(subTask, token);
                }
            }

            await _humanTaskInstanceCommandRepository.SaveChanges(token);
        }
示例#3
0
        public async Task <bool> Handle(NominateHumanTaskInstanceCommand request, CancellationToken cancellationToken)
        {
            if (request.Claims == null || !request.Claims.Any())
            {
                _logger.LogError("User is not authenticated");
                throw new NotAuthenticatedException(Global.UserNotAuthenticated);
            }

            if (request.GroupNames != null && request.GroupNames.Any() && request.UserIdentifiers != null && request.UserIdentifiers.Any())
            {
                _logger.LogError("GroupNames and UserIdentifiers parameters cannot be specified at the same time");
                throw new BadRequestException(Global.GroupNamesAndUserIdentifiersSpecified);
            }

            if ((request.GroupNames == null || !request.GroupNames.Any()) && (request.UserIdentifiers == null || !request.UserIdentifiers.Any()))
            {
                _logger.LogError("GroupNames or UserIdentifiers parameters must be specified");
                throw new BadRequestException(string.Format(Global.MissingParameters, "GroupNames,UserIdentifiers"));
            }

            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 roles = await _authorizationHelper.GetRoles(humanTaskInstance, request.Claims, cancellationToken);

            if (!roles.Contains(UserRoles.BUSINESSADMINISTRATOR))
            {
                _logger.LogError("User is not a business administrator");
                throw new NotAuthorizedException(Global.UserNotAuthorized);
            }

            if (humanTaskInstance.Status != HumanTaskInstanceStatus.CREATED)
            {
                _logger.LogError("Nomination can be performed only on created human task instance");
                throw new BadOperationExceptions(string.Format(Global.OperationCanBePerformed, "Nominate", "Created"));
            }

            var userPrincipal = request.Claims.GetUserNameIdentifier();

            humanTaskInstance.Nominate(userPrincipal, request.GroupNames, request.UserIdentifiers);
            await _humanTaskInstanceCommandRepository.Update(humanTaskInstance, cancellationToken);

            await _humanTaskInstanceCommandRepository.SaveChanges(cancellationToken);

            return(true);
        }
示例#4
0
        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);
        }
示例#5
0
        public async Task <bool> Handle(ForceClaimHumanTaskInstanceCommand 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));
            }

            humanTaskInstance.Claim(request.UserId);
            await _humanTaskInstanceCommandRepository.Update(humanTaskInstance, cancellationToken);

            await _humanTaskInstanceCommandRepository.SaveChanges(cancellationToken);

            return(true);
        }
示例#6
0
        protected override async Task Execute(CancellationToken token)
        {
            var humanTaskListInstances = await _humanTaskInstanceQueryRepository.GetPendingLst(token);

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                foreach (var instance in humanTaskListInstances)
                {
                    instance.Activate("ProcessActivationTimer");
                    await _humanTaskInstanceCommandRepository.Update(instance, token);

                    await _humanTaskInstanceCommandRepository.SaveChanges(token);
                }

                transaction.Complete();
            }
        }
        protected override async Task Execute(CancellationToken token)
        {
            try
            {
                var currentDateTime      = DateTime.UtcNow;
                var humanTaskInstanceLst = await _humanTaskInstanceQueryRepository.GetPendingDeadLines(token, currentDateTime);

                foreach (var humanTaskInstance in humanTaskInstanceLst)
                {
                    var deadLines        = humanTaskInstance.DeadLines.Where(d => currentDateTime >= d.EndDateTime);
                    var executionContext = new BaseExpressionContext(humanTaskInstance.InputParameters);
                    var deadLineIds      = deadLines.Select(_ => _.Id).ToList();
                    foreach (var id in deadLineIds)
                    {
                        var deadLine = deadLines.First(_ => _.Id == id);
                        if (deadLine.Escalations != null && deadLine.Escalations.Any())
                        {
                            foreach (var escalation in deadLine.Escalations)
                            {
                                if (!string.IsNullOrWhiteSpace(escalation.Condition) && !ExpressionParser.IsValid(escalation.Condition, executionContext))
                                {
                                    continue;
                                }

                                if (!string.IsNullOrWhiteSpace(escalation.NotificationId))
                                {
                                    var parameters = _parameterParser.ParseToPartParameters(escalation.ToParts, humanTaskInstance.InputParameters);
                                    await _mediator.Send(new CreateNotificationInstanceCommand { NotificationId = escalation.NotificationId, Parameters = parameters }, token);
                                }
                            }
                        }

                        humanTaskInstance.RemoveDeadLine(deadLine.Name, deadLine.Usage);
                    }

                    await _humanTaskInstanceCommandRepository.Update(humanTaskInstance, token);
                }

                await _humanTaskInstanceCommandRepository.SaveChanges(token);
            }
            catch (Exception)
            {
            }
        }
示例#8
0
        public async Task <bool> Handle(ClaimHumanTaskInstanceCommand 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 roles = await _authorizationHelper.GetRoles(humanTaskInstance, request.Claims, cancellationToken);

            if (!roles.Contains(UserRoles.POTENTIALOWNER))
            {
                _logger.LogError("User is not a potentiel owner");
                throw new NotAuthorizedException(Global.UserNotAuthorized);
            }

            if (humanTaskInstance.Status != HumanTaskInstanceStatus.READY)
            {
                _logger.LogError("Claim operation can be performed only on READY human task instance");
                throw new BadOperationExceptions(string.Format(Global.OperationCanBePerformed, "Claim", "Ready"));
            }

            var userPrincipal = request.Claims.GetUserNameIdentifier();

            humanTaskInstance.Claim(userPrincipal);
            await _humanTaskInstanceCommandRepository.Update(humanTaskInstance, cancellationToken);

            await _humanTaskInstanceCommandRepository.SaveChanges(cancellationToken);

            return(true);
        }