Example #1
0
        public async Task <string> Handle(CreateNotificationInstanceCommand request, CancellationToken cancellationToken)
        {
            var notificationDef = await _notificationDefQueryRepository.Get(request.NotificationId, cancellationToken);

            if (notificationDef == null)
            {
                throw new UnknownNotificationException(string.Format(Global.UnknownNotification, request.NotificationId));
            }

            var operationParameters = request.Parameters == null ? new Dictionary <string, string>() : request.Parameters;
            var parameters          = _parameterParser.ParseOperationParameters(notificationDef.InputParameters, operationParameters);

            _logger.LogInformation($"Create notification '{notificationDef.Name}'");
            var presentationElt = _parameterParser.ParsePresentationElements(notificationDef.PresentationElements,
                                                                             notificationDef.PresentationParameters,
                                                                             parameters);
            var assignmentInstance = _parameterParser.ParsePeopleAssignments(
                notificationDef.PeopleAssignments,
                parameters);
            var id = Guid.NewGuid().ToString();
            var notificationInstance = NotificationInstanceAggregate.New(id,
                                                                         notificationDef.Priority,
                                                                         notificationDef.Name,
                                                                         parameters,
                                                                         presentationElt,
                                                                         assignmentInstance,
                                                                         notificationDef.Rendering);
            await _notificationInstanceCommandRepository.Add(notificationInstance, cancellationToken);

            await _notificationInstanceCommandRepository.SaveChanges(cancellationToken);

            return(notificationInstance.AggregateId);
        }
        public async Task <NotificationDefResult> Handle(GetNotificationDefQuery request, CancellationToken cancellationToken)
        {
            var result = await _notificationDefQueryRepository.Get(request.Id, cancellationToken);

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

            return(NotificationDefResult.ToDto(result));
        }
        public async Task <bool> Handle(DeleteNotificationDefPeopleAssignmentCommand request, CancellationToken cancellationToken)
        {
            var result = await _notificationDefQueryRepository.Get(request.Id, cancellationToken);

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

            result.RemoveAssignment(request.AssignmentId);
            await _notificationDefCommandRepository.Update(result, cancellationToken);

            await _notificationDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Notification definition '{result.Name}', people assignment is removed");
            return(true);
        }
Example #4
0
        public async Task <bool> Handle(DeleteNotificationDefParameterCommand request, CancellationToken cancellationToken)
        {
            var result = await _notificationDefQueryRepository.Get(request.Id, cancellationToken);

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

            result.DeleteOperationParameter(request.ParameterId);
            await _notificationDefCommandRepository.Update(result, cancellationToken);

            await _notificationDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Notification definition '{result.Name}', operation parameter '{request.ParameterId}' has been removed");
            return(true);
        }
Example #5
0
        public async Task <bool> Handle(DeleteNotificationDefPresentationElementCommand request, CancellationToken cancellationToken)
        {
            var result = await _notificationDefQueryRepository.Get(request.Id, cancellationToken);

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

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

            await _notificationDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Notification definition '{result.Name}', presentation element has been remvoed");
            return(true);
        }
Example #6
0
        public async Task <bool> Handle(AddNotificationDefPresentationParameterCommand request, CancellationToken cancellationToken)
        {
            var result = await _notificationDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The notification definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownNotification, 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 _notificationDefCommandRepository.Update(result, cancellationToken);

            await _notificationDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Notification definition '{result.Name}', presentation parameter '{request.PresentationParameter.Name}' has been added");
            return(true);
        }
        public async Task <bool> Handle(DeleteNotificationDefPresentationParameterCommand request, CancellationToken cancellationToken)
        {
            var result = await _notificationDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The notification definition '{request.Id}' doesn't exist");
                throw new UnknownNotificationDefException(string.Format(Global.UnknownNotification, 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 _notificationDefCommandRepository.Update(result, cancellationToken);

            await _notificationDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Notification definition '{result.AggregateId}', presentation parameter '{request.Name}' has been removed");
            return(true);
        }
Example #8
0
        public async Task <bool> Handle(UpdateNotificationDefInfoCommand 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 _notificationDefQueryRepository.Get(request.Id, cancellationToken);

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

            var r = await _notificationDefQueryRepository.Search(new SearchNotificationDefParameter
            {
                Name = request.Name
            }, cancellationToken);

            r.Content = r.Content.Where(_ => _.AggregateId != request.Id).ToList();
            if (r != null && r.Content.Count() > 0)
            {
                _logger.LogError($"the notification '{request.Name}' already exists");
                throw new BadRequestException(string.Format(Global.NotificationDefExists, request.Name));
            }

            result.UpdateInfo(request.Name, request.Priority);
            await _notificationDefCommandRepository.Update(result, cancellationToken);

            await _notificationDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Notification definition '{result.Name}', information has been updated");
            return(true);
        }
Example #9
0
        public async Task <string> Handle(AddNotificationDefPeopleAssignmentCommand request, CancellationToken cancellationToken)
        {
            var result = await _notificationDefQueryRepository.Get(request.Id, cancellationToken);

            if (result == null)
            {
                _logger.LogError($"The notification definition '{request.Id}' doesn't exist");
                throw new UnknownHumanTaskDefException(string.Format(Global.UnknownNotification, 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 _notificationDefCommandRepository.Update(result, cancellationToken);

            await _notificationDefCommandRepository.SaveChanges(cancellationToken);

            _logger.LogInformation($"Notification definition '{result.Name}', people is assigned");
            return(id);
        }