/// <summary>
        ///   Executes the specified data query.
        /// </summary>
        /// <param name="dataQuery">The data query.</param>
        /// <returns>The result of execution.</returns>
        public NotificationRuleDto Execute([NotNull] GetNotificationQuery dataQuery)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException(nameof(dataQuery));
            }

            var notification = _notificationRuleRepository.GetById(dataQuery.Id);

            if (notification == null)
            {
                return(null);
            }

            if (!_userAuthorityValidator.HasUserAuthorities(
                    _userPrincipal.Info.Id,
                    new[]
            {
                Authorities.UI.Project.Settings.ViewNotifications
            },
                    notification.ProjectId))
            {
                throw new UnauthorizedAccessException();
            }

            var notificationDto = new NotificationRuleRenderer().GetSpec().Invoke(notification);

            return(notificationDto);
        }
        /// <summary>
        ///     Executes the job.
        /// </summary>
        /// <returns>
        ///     Positive value to repeat the task, negative value or 0 - to finish the task and to wait time interval before the
        ///     next run.
        /// </returns>
        protected override int Process()
        {
            var ruleId = (long)JobExecutionContext.MergedJobDataMap.Get("NotificationRuleId");
            var rule   = _notificationRuleRepository.GetById(ruleId);

            var parsedRule = _ruleParser.ParseNotificationRule(rule.Query);

            _ruleExecutorDirector.Execute <INotificationRule, NotificationRuleResult>(
                parsedRule,
                new Dictionary <string, string>
            {
                { Variables.ProjectId, rule.ProjectId.ToString() }
            });

            return(0);
        }
 protected override long?GetProjectIdForCommand(UpdateNotificationRuleCommand command) =>
 _notificationRuleRepository.GetById(command.RuleId)?.ProjectId;