protected virtual IReadOnlyCollection <IncludeElementExpression> GetIncludeElements(IReadOnlyCollection <IncludeElementExpression> includeElements, ResourceContext resourceContext)
        {
            var resourceDefinition = _resourceDefinitionProvider.Get(resourceContext.ResourceType);

            if (resourceDefinition != null)
            {
                includeElements = resourceDefinition.OnApplyIncludes(includeElements);
            }

            return(includeElements);
        }
Пример #2
0
 /// <inheritdoc/>
 public List <SortQueryContext> Get()
 {
     if (_queries == null)
     {
         var requestResourceDefinition = _resourceDefinitionProvider.Get(_requestResource.ResourceType);
         if (requestResourceDefinition != null)
         {
             return(requestResourceDefinition.DefaultSort()?.Select(d => BuildQueryContext(new SortQuery(d.Item1.PublicAttributeName, d.Item2))).ToList());
         }
     }
     return(_queries.ToList());
 }
Пример #3
0
        /// <inheritdoc/>
        public List <AttrAttribute> GetAllowedAttributes(Type type, RelationshipAttribute relationship = null)
        {   // get the list of all exposed attributes for the given type.
            var allowed = _resourceGraph.GetAttributes(type);

            var resourceDefinition = _provider.Get(type);

            if (resourceDefinition != null)
            {
                // The set of allowed attributes to be exposed was defined on the resource definition
                allowed = allowed.Intersect(resourceDefinition.GetAllowedAttributes()).ToList();
            }

            var sparseFieldsSelection = _sparseFieldsService.Get(relationship);

            if (sparseFieldsSelection != null && sparseFieldsSelection.Any())
            {
                // from the allowed attributes, select the ones flagged by sparse field selection.
                allowed = allowed.Intersect(sparseFieldsSelection).ToList();
            }

            return(allowed);
        }
Пример #4
0
        private object GetQueryableHandler(string parameterName)
        {
            if (_request.Kind != EndpointKind.Primary)
            {
                throw new InvalidQueryStringParameterException(parameterName,
                                                               "Custom query string parameters cannot be used on nested resource endpoints.",
                                                               $"Query string parameter '{parameterName}' cannot be used on a nested resource endpoint.");
            }

            var resourceType       = _request.PrimaryResource.ResourceType;
            var resourceDefinition = _resourceDefinitionProvider.Get(resourceType);

            return(resourceDefinition?.GetQueryableHandlerForQueryStringParameter(parameterName));
        }
Пример #5
0
        /// <inheritdoc/>
        public List <SortQueryContext> Get()
        {
            if (_queries.Any())
            {
                return(_queries.ToList());
            }

            var requestResourceDefinition = _resourceDefinitionProvider.Get(_requestResource.ResourceType);
            var defaultSort = requestResourceDefinition?.DefaultSort();

            if (defaultSort != null)
            {
                return(defaultSort
                       .Select(d => BuildQueryContext(new SortQuery(d.Attribute.PublicAttributeName, d.SortDirection)))
                       .ToList());
            }

            return(new List <SortQueryContext>());
        }
        /// <inheritdoc />
        public IReadOnlyCollection <AttrAttribute> GetAttributes(Type resourceType, RelationshipAttribute relationship = null)
        {
            if (resourceType == null)
            {
                throw new ArgumentNullException(nameof(resourceType));
            }

            var sparseFieldSetAttributes = _constraintProviders
                                           .SelectMany(p => p.GetConstraints())
                                           .Where(expressionInScope => relationship == null
                    ? expressionInScope.Scope == null
                    : expressionInScope.Scope != null && expressionInScope.Scope.Fields.Last().Equals(relationship))
                                           .Select(expressionInScope => expressionInScope.Expression)
                                           .OfType <SparseFieldSetExpression>()
                                           .SelectMany(sparseFieldSet => sparseFieldSet.Attributes)
                                           .ToHashSet();

            if (!sparseFieldSetAttributes.Any())
            {
                sparseFieldSetAttributes = GetViewableAttributes(resourceType);
            }

            var resourceDefinition = _resourceDefinitionProvider.Get(resourceType);

            if (resourceDefinition != null)
            {
                var inputExpression  = sparseFieldSetAttributes.Any() ? new SparseFieldSetExpression(sparseFieldSetAttributes) : null;
                var outputExpression = resourceDefinition.OnApplySparseFieldSet(inputExpression);

                if (outputExpression == null)
                {
                    sparseFieldSetAttributes = GetViewableAttributes(resourceType);
                }
                else
                {
                    sparseFieldSetAttributes.IntersectWith(outputExpression.Attributes);
                }
            }

            return(sparseFieldSetAttributes);
        }
Пример #7
0
 public FilterService(IResourceDefinitionProvider resourceDefinitionProvider, IResourceGraph resourceGraph, ICurrentRequest currentRequest) : base(resourceGraph, currentRequest)
 {
     _requestResourceDefinition = resourceDefinitionProvider.Get(_requestResource.ResourceType);
     _filters = new List <FilterQueryContext>();
 }