public async Task QueryListWithSkip()
        {
            IQueryable <BookModel> eventsList = new List <BookModel>
            {
                new BookModel
                {
                    Id = "1"
                },
                new BookModel
                {
                    Id = "2"
                },
                new BookModel
                {
                    Id = "3"
                }
            }.AsQueryable();

            var oDataModel = new ODataModel
            {
                Skip    = 1,
                OrderBy = "created"
            };

            var events = eventsList.FilterWithODataAsync(oDataModel);
            var query  = await events.query;

            Assert.Equal(2, query.Count);
            Assert.Equal("2", query[0].Id);
            Assert.Equal("3", query[1].Id);
        }
示例#2
0
        public bool HasViewableRight(Guid idDocumentUnit, string username, string domain)
        {
            string       odataFilter   = $"/DocumentUnitService.HasViewableDocument(idDocumentUnit={idDocumentUnit},username='******',domain='{domain}')";
            IBaseAddress webApiAddress = DocSuiteContext.Current.CurrentTenant.WebApiClientConfig.Addresses.Single(x => x.AddressName.Eq(WebApiHttpClient.ODATA_ADDRESS_NAME));
            TenantEntityConfiguration documentUnitEndpoint = DocSuiteContext.Current.CurrentTenant.Entities.Single(x => x.Key.Eq(ODATA_DOCUMENTUNIT_ENDPOINT_NAME)).Value;

            HttpClientConfiguration customHttpConfiguration = new HttpClientConfiguration();

            customHttpConfiguration.Addresses.Add(webApiAddress);
            WebApiControllerEndpoint endpoint = new WebApiControllerEndpoint
            {
                AddressName    = webApiAddress.AddressName,
                ControllerName = documentUnitEndpoint.ODATAControllerName,
                EndpointName   = ODATA_DOCUMENTUNIT_ENDPOINT_NAME
            };

            customHttpConfiguration.EndPoints.Add(endpoint);

            ODataModel <bool> result = WebAPIImpersonatorFacade.ImpersonateRawRequest <DocumentUnitEntities.DocumentUnit, ODataModel <bool> >(WebAPIHelper, odataFilter, customHttpConfiguration);

            if (result != null)
            {
                return(result.Value);
            }
            else
            {
                FileLogger.Warn(LogName.FileLog, string.Concat("HasViewableRight -> Document unit con id ", idDocumentUnit, " non trovata."));
                return(false);
            }
        }
        public async Task QueryListWithCriteria()
        {
            IQueryable <BookModel> eventsList = new List <BookModel>
            {
                new BookModel
                {
                    Id = "123"
                },
                new BookModel
                {
                    Id = "abc"
                }
            }.AsQueryable();

            var oDataModel = new ODataModel
            {
                Filter = new List <ODataFilterModel>
                {
                    new ODataFilterModel
                    {
                        Key          = "Id",
                        OperatorType = ODataOperatorType.eq,
                        Value        = "123"
                    }
                },
                OrderBy = "created"
            };


            var events = eventsList.FilterWithODataAsync(oDataModel);
            var query  = await events.query;

            Assert.Single(query);
            Assert.Equal("123", query[0].Id);
        }
示例#4
0
        public async Task Should_Convert_LambdaExpression_With_OrJoinType()
        {
            //Arrange
            var oDataExpressionList = new List <ODataFilterModel>
            {
                new ODataFilterModel
                {
                    Key          = "Label",
                    OperatorType = ODataOperatorType.eq,
                    Value        = "label",
                    JoinType     = FilterJoinType.Or
                },
                new ODataFilterModel
                {
                    Key          = "Id",
                    OperatorType = ODataOperatorType.contains,
                    Value        = "1"
                }
            };

            var oDataModel = new ODataModel
            {
                Filter = oDataExpressionList
            };

            //Act
            var orExpression = oDataModel.GetFilterAsExpression <BookModel>();

            //Assert
            Assert.Equal("((x.Label == \"label\") OrElse Invoke(x => x.Id.Contains(\"1\"), x))", orExpression.Body.ToString());
        }
        public async Task QueryListWithOrderByAndReverse()
        {
            IQueryable <BookModel> eventsList = new List <BookModel>
            {
                new BookModel
                {
                    Id = "1"
                },
                new BookModel
                {
                    Id = "3"
                },
                new BookModel
                {
                    Id = "2"
                }
            }.AsQueryable();

            var oDataModel = new ODataModel
            {
                OrderBy = "Id",
                Reverse = true
            };


            var events = eventsList.FilterWithODataAsync(oDataModel);
            var query  = await events.query;

            Assert.Equal("3", query[0].Id);
            Assert.Equal("2", query[1].Id);
            Assert.Equal("1", query[2].Id);
        }
        public void Process(string fullPath, SegmentOp operation, ODataModel model,
                            string contentType = "application/atom+xml",
                            string accept      = "application/atom+xml",
                            Stream inputStream = null)
        {
            _body = new StringBuilder();

            var segments = SegmentParser.parse(fullPath, String.Empty, model);

            _response = new ResponseParameters(null, Encoding.UTF8, new StringWriter(_body), 200);

            var callbacks = new ProcessorCallbacks(
                (rt, item) =>
            {
                _accessSingle.Add(new Tuple <ResourceType, object>(rt, item));
                return(true);
            },
                (rt, items) =>
            {
                _accessMany.Add(new Tuple <ResourceType, IEnumerable>(rt, items));
                return(true);
            },
                (rt, item) =>
            {
                _created.Add(new Tuple <ResourceType, object>(rt, item));
                return(true);
            },
                (rt, item) =>
            {
                _updated.Add(new Tuple <ResourceType, object>(rt, item));
                return(true);
            },
                (rt, item) =>
            {
                _removed.Add(new Tuple <ResourceType, object>(rt, item));
                return(true);
            }
                );

            SegmentProcessor.Process(operation, segments,

                                     callbacks,

                                     new RequestParameters(
                                         model,
                                         model as IDataServiceMetadataProvider,
                                         new DataServiceMetadataProviderWrapper(model),
                                         contentType,
                                         Encoding.UTF8,
                                         inputStream,
                                         new Uri("http://localhost/base/"),
                                         new [] { accept }
                                         ),

                                     _response
                                     );
        }
        public void Process(string fullPath, SegmentOp operation, ODataModel model, 
							string contentType = "application/atom+xml", 
							string accept = "application/atom+xml", 
							Stream inputStream = null)
        {
            _body = new StringBuilder();

            var segments = SegmentParser.parse(fullPath, String.Empty, model);
            _response = new ResponseParameters(null, Encoding.UTF8, new StringWriter(_body), 200);

            var callbacks = new ProcessorCallbacks(
                    (rt, item) =>
                    {
                        _accessSingle.Add(new Tuple<ResourceType, object>(rt, item));
                        return true;
                    },
                    (rt, items) =>
                    {
                        _accessMany.Add(new Tuple<ResourceType, IEnumerable>(rt, items));
                        return true;
                    },
                    (rt, item) =>
                    {
                        _created.Add(new Tuple<ResourceType, object>(rt, item));
                        return true;
                    },
                    (rt, item) =>
                    {
                        _updated.Add(new Tuple<ResourceType, object>(rt, item));
                        return true;
                    },
                    (rt, item) =>
                    {
                        _removed.Add(new Tuple<ResourceType, object>(rt, item));
                        return true;
                    }
                );

            SegmentProcessor.Process(operation, segments,

                callbacks,

                new RequestParameters(
                    model,
                    model as IDataServiceMetadataProvider,
                    new DataServiceMetadataProviderWrapper(model),
                    contentType,
                    Encoding.UTF8,
                    inputStream,
                    new Uri("http://localhost/base/"),
                    new [] { accept }
                ),

                _response
            );
        }
示例#8
0
        /// <summary>
        /// Applica le espressioni di trasformata del risultato
        /// </summary>
        public virtual IEnumerable <THeader> SetProjectionsHeaders(WebApiHttpClient httpClient, IODATAQueryManager odataQuery)
        {
            ODataModel <ICollection <THeader> > foundResults = httpClient.GetAsync <T>().WithRowQuery(odataQuery.Compile()).ResponseToModel <ODataModel <ICollection <THeader> > >();

            if (foundResults == null || foundResults.Value == null)
            {
                return(Enumerable.Empty <THeader>());
            }
            return(foundResults.Value);
        }
        public ODataModel ParseQuery(List <KeyValuePair <string, StringValues> > queryList)
        {
            var oDataModel = new ODataModel
            {
                OrderBy = "created"
            };

            foreach (var query in queryList)
            {
                var key = query.Key.ToLowerInvariant();

                if (key.Equals(TOP))
                {
                    oDataModel.Top = int.Parse(query.Value);
                }

                else if (key.Equals(SKIP))
                {
                    oDataModel.Skip = int.Parse(query.Value);
                }

                else if (key.Equals(ORDERBY))
                {
                    oDataModel.OrderBy = query.Value;

                    var sort = query.Value.ToString().Split((char[])null, StringSplitOptions.RemoveEmptyEntries);

                    if (sort.Count() == 2)
                    {
                        if (sort[1].ToLower().Equals(ASC))
                        {
                            oDataModel.Reverse = false;
                        }

                        else
                        {
                            oDataModel.Reverse = true;
                        }

                        oDataModel.OrderBy = sort[0];
                    }
                }

                else if (key.Equals(EXPAND))
                {
                    var propertiesToExpand = regexUtilizer.SplitOnCommasAndRemoveWhiteSpace(query.Value);

                    oDataModel.ExpandProperties = propertiesToExpand;
                }
            }

            return(oDataModel);
        }
示例#10
0
        public async Task Should_Convert_Sort()
        {
            //Arrange
            var oDataModel = new ODataModel
            {
                OrderBy = "Label"
            };

            //Act
            var sortExpression = oDataModel.GetOrderByAsExpression <BookModel>();

            //Assert
            Assert.Equal("Convert(x.Label, Object)", sortExpression.Body.ToString());
        }
示例#11
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();
            // OData routes
            config.MapODataServiceRoute("ODataRoute", "odata", ODataModel.GetEdmModel());

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
示例#12
0
        public bool HasCollaborationViewableRight(int idCollaboration)
        {
            string       odataFilter   = $"/CollaborationService.HasViewableRight(idCollaboration={idCollaboration})";
            IBaseAddress webApiAddress = DocSuiteContext.Current.CurrentTenant.WebApiClientConfig.Addresses.Single(x => x.AddressName.Eq(WebApiHttpClient.ODATA_ADDRESS_NAME));
            TenantEntityConfiguration collaborationEndpoint = DocSuiteContext.Current.CurrentTenant.Entities.Single(x => x.Key.Eq(ODATA_COLLABORATION_ENDPOINT_NAME)).Value;

            HttpClientConfiguration customHttpConfiguration = new HttpClientConfiguration();

            customHttpConfiguration.Addresses.Add(webApiAddress);
            WebApiControllerEndpoint endpoint = new WebApiControllerEndpoint
            {
                AddressName    = webApiAddress.AddressName,
                ControllerName = collaborationEndpoint.ODATAControllerName,
                EndpointName   = ODATA_COLLABORATION_ENDPOINT_NAME
            };

            customHttpConfiguration.EndPoints.Add(endpoint);

            ODataModel <bool> result = WebAPIImpersonatorFacade.ImpersonateRawRequest <Collaboration, ODataModel <bool> >(WebAPIHelper, odataFilter, customHttpConfiguration);

            return(result.Value);
        }
示例#13
0
        public bool HasProcedureDistributionInsertRight(int idCategory)
        {
            string       odataFilter   = $"/FascicleService.HasProcedureDistributionInsertRight(idCategory={idCategory})";
            IBaseAddress webApiAddress = DocSuiteContext.Current.CurrentTenant.WebApiClientConfig.Addresses.Single(x => x.AddressName.Eq(WebApiHttpClient.ODATA_ADDRESS_NAME));
            TenantEntityConfiguration fascicleEndpoint = DocSuiteContext.Current.CurrentTenant.Entities.Single(x => x.Key.Eq(ODATA_FASCICLE_ENDPOINT_NAME)).Value;

            HttpClientConfiguration customHttpConfiguration = new HttpClientConfiguration();

            customHttpConfiguration.Addresses.Add(webApiAddress);
            WebApiControllerEndpoint endpoint = new WebApiControllerEndpoint
            {
                AddressName    = webApiAddress.AddressName,
                ControllerName = fascicleEndpoint.ODATAControllerName,
                EndpointName   = ODATA_FASCICLE_ENDPOINT_NAME
            };

            customHttpConfiguration.EndPoints.Add(endpoint);

            ODataModel <bool> result = WebAPIImpersonatorFacade.ImpersonateRawRequest <Fascicle, ODataModel <bool> >(WebAPIHelper, odataFilter, customHttpConfiguration);

            return(result.Value);
        }
示例#14
0
        public bool HasFascicleDocumentViewableRight(Guid idFascicle, string username, string domain)
        {
            string       odataFilter   = string.Concat("/FascicleService.HasViewableDocument(idFascicle=", idFascicle, ",username='******',domain='", domain, "')");
            IBaseAddress webApiAddress = DocSuiteContext.Current.CurrentTenant.WebApiClientConfig.Addresses.Single(x => x.AddressName.Eq(WebApiHttpClient.ODATA_ADDRESS_NAME));
            TenantEntityConfiguration fascicleEndpoint = DocSuiteContext.Current.CurrentTenant.Entities.Single(x => x.Key.Eq(ODATA_FASCICLE_ENDPOINT_NAME)).Value;

            HttpClientConfiguration customHttpConfiguration = new HttpClientConfiguration();

            customHttpConfiguration.Addresses.Add(webApiAddress);
            WebApiControllerEndpoint endpoint = new WebApiControllerEndpoint
            {
                AddressName    = webApiAddress.AddressName,
                ControllerName = fascicleEndpoint.ODATAControllerName,
                EndpointName   = ODATA_FASCICLE_ENDPOINT_NAME
            };

            customHttpConfiguration.EndPoints.Add(endpoint);

            ODataModel <bool> result = WebAPIHelper.GetRawRequest <Fascicle, ODataModel <bool> >(customHttpConfiguration, customHttpConfiguration, odataFilter);

            return(result.Value);
        }
示例#15
0
        /// <summary>
        /// Crea la DoSearch con i metodi standard.
        /// Se non implementati, vengono usati quelli standard
        /// </summary>
        public ICollection <WebAPIDto <T> > DoSearch()
        {
            ICollection <WebAPIDto <T> > elements = CurrentTenantExecutionWebAPI <T>((tenant, results) =>
            {
                WebApiHttpClient httpClient   = GetWebAPIClient(tenant);
                IODATAQueryManager odataQuery = GetODataQuery();
                odataQuery = DecorateFinder(odataQuery);
                if (EnableTopOdata)
                {
                    odataQuery = odataQuery.Top(DocSuiteContext.Current.DefaultODataTopQuery);
                }
                odataQuery = AttachFilterExpressions(odataQuery);
                ODataModel <ICollection <T> > foundResults = httpClient.GetAsync <T>().WithRowQuery(odataQuery.Compile()).ResponseToModel <ODataModel <ICollection <T> > >();
                if (foundResults == null || foundResults.Value == null)
                {
                    return(new List <WebAPIDto <T> >());
                }
                foundResults.Value.ToList().ForEach(x => results.Add(_mapper.TransformDTO(x, tenant)));
                return(results);
            }, FinalizeDoSearch, "DoSearch");

            return(elements);
        }
示例#16
0
        public async Task Should_Convert_EqLambdaExpression()
        {
            //Arrange
            var criteria = new List <ODataFilterModel>
            {
                new ODataFilterModel
                {
                    Key          = "Label",
                    OperatorType = ODataOperatorType.eq,
                    Value        = "lxabel2",
                }
            };

            var oDataModel = new ODataModel
            {
                Filter = criteria
            };

            //Act
            var expression = oDataModel.GetFilterAsExpression <BookModel>();

            //Assert
            Assert.Equal("(x.Label == \"lxabel2\")", expression.Body.ToString());
        }
示例#17
0
        public async Task Should_Convert_LeLambdaExpression()
        {
            //Arrange
            var criteria = new List <ODataFilterModel>
            {
                new ODataFilterModel
                {
                    Key          = "Age",
                    OperatorType = ODataOperatorType.le,
                    Value        = "7"
                }
            };

            var oDataModel = new ODataModel
            {
                Filter = criteria
            };

            //Act
            var expression = oDataModel.GetFilterAsExpression <ReaderModel>();

            //Assert
            Assert.Equal("(x.Age <= 7)", expression.Body.ToString());
        }