public QueryDto Execute(QueryByNameQuery dataQuery)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException(nameof(dataQuery));
            }

            var query = _queryStorage.Get(dataQuery.ProjectId, dataQuery.Name);

            return(query?.ToDto());
        }
        public PolicyRuleResult Execute([NotNull] IPolicyRule rule, IDictionary <string, string> parameters)
        {
            if (rule == null)
            {
                throw new ArgumentNullException(nameof(rule));
            }

            var queriedData = new Dictionary <string, QueryResult>();

            foreach (var dataParameterExpr in rule.Expression.Data)
            {
                var query = _queryStorage.Get(rule.Rule.ProjectId, dataParameterExpr.Value);

                var result = _queryExecutor.Execute(query.Id, _userPrincipal.Info.Id, parameters.ToArray());

                queriedData.Add(dataParameterExpr.Name, result);
            }

            // ReSharper disable once LoopCanBePartlyConvertedToQuery
            foreach (var queryResult in queriedData)
            {
                if (queryResult.Value.Exceptions != null &&
                    queryResult.Value.Exceptions.Any())
                {
                    throw new PolicyRuleQueryException(queryResult.Value);
                }

                if (queryResult.Value.Items == null ||
                    !queryResult.Value.Items.Any())
                {
                    continue;
                }

                _log.Info($"SDL policy failed. Policy name='{rule.Rule.Name}', Query key='{queryResult.Key}'");

                return(new PolicyRuleResult
                {
                    Success = false,
                    FailedRule = rule.Rule.Name,
                    FailedKey = queryResult.Key
                });
            }

            _log.Info($"SDL policy succeed. Policy name='{rule.Rule.Name}'");

            return(new PolicyRuleResult
            {
                Success = true
            });
        }