Ejemplo n.º 1
0
        /// <summary>
        /// Returns a list of dynamic rows and optionally their count as per the specifications in <paramref name="args"/>.
        /// </summary>
        public virtual async Task <FactResult> GetFact(FactArguments args, CancellationToken cancellation)
        {
            await Initialize(cancellation);

            // Parse the parameters
            var filter  = ExpressionFilter.Parse(args.Filter);
            var orderby = ExpressionOrderBy.Parse(args.OrderBy);
            var select  = ExpressionFactSelect.Parse(args.Select);

            // Prepare the query
            var query = QueryFactory().FactQuery <TEntity>();

            // Apply read permissions
            var permissionsFilter = await UserPermissionsFilter(PermissionActions.Read, cancellation);

            query = query.Filter(permissionsFilter);

            // Apply filter
            query = query.Filter(filter);

            // Apply orderby
            orderby ??= await DefaultOrderBy(cancellation);

            query = query.OrderBy(orderby);

            // Apply the paging (Protect against DOS attacks by enforcing a maximum page size)
            var top  = args.Top;
            var skip = args.Skip;

            top   = Math.Min(top, MaximumPageSize());
            query = query.Skip(skip).Top(top);

            // Apply the select
            query = query.Select(select);

            // Load the data and count in memory
            List <DynamicRow> data;
            int?count = null;

            if (args.CountEntities)
            {
                (data, count) = await query.ToListAndCountAsync(MaximumCount, QueryContext, cancellation);
            }
            else
            {
                data = await query.ToListAsync(QueryContext, cancellation);
            }

            // Return
            return(new FactResult(data, count));
        }
Ejemplo n.º 2
0
        protected override ExpressionOrderBy DefaultOrderBy()
        {
            // By default: Order currencies by name
            var    tenantInfo   = _repo.GetTenantInfo();
            string nameProperty = nameof(Currency.Name);

            if (tenantInfo.SecondaryLanguageId == CultureInfo.CurrentUICulture.Name)
            {
                nameProperty = $"{nameof(Currency.Name2)},{nameof(Currency.Name)}";
            }
            else if (tenantInfo.TernaryLanguageId == CultureInfo.CurrentUICulture.Name)
            {
                nameProperty = $"{nameof(Currency.Name3)},{nameof(Currency.Name)}";
            }

            return(ExpressionOrderBy.Parse(nameProperty));
        }
Ejemplo n.º 3
0
        protected override ExpressionOrderBy DefaultOrderBy()
        {
            // By default: Order dashboard definitions by name
            var    tenantInfo = _repo.GetTenantInfo();
            string orderby    = $"{nameof(DashboardDefinition.Title)},{nameof(DashboardDefinition.Id)}";

            if (tenantInfo.SecondaryLanguageId == CultureInfo.CurrentUICulture.Name)
            {
                orderby = $"{nameof(DashboardDefinition.Title2)},{nameof(DashboardDefinition.Title)},{nameof(DashboardDefinition.Id)}";
            }
            else if (tenantInfo.TernaryLanguageId == CultureInfo.CurrentUICulture.Name)
            {
                orderby = $"{nameof(DashboardDefinition.Title3)},{nameof(DashboardDefinition.Title)},{nameof(DashboardDefinition.Id)}";
            }

            return(ExpressionOrderBy.Parse(orderby));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a list of entities as per the specifications in the <see cref="GetChildrenArguments{TKey}"/>
        /// </summary>
        public virtual async Task <(List <TEntity>, Extras)> GetChildrenOf(GetChildrenArguments <TKey> args, CancellationToken cancellation)
        {
            // Parse the parameters
            var expand  = ExpressionExpand.Parse(args.Expand);
            var select  = ParseSelect(args.Select);
            var filter  = ExpressionFilter.Parse(args.Filter);
            var orderby = ExpressionOrderBy.Parse("Node");
            var ids     = args.I ?? new List <TKey>();

            // Load the data
            var data = await GetEntitiesByCustomQuery(q => q.FilterByParentIds(ids, args.Roots).Filter(filter), expand, select, orderby, null, cancellation);

            var extras = await GetExtras(data, cancellation);

            // Transform and Return
            return(data, extras);
        }
        protected override async Task <ExpressionOrderBy> DefaultOrderBy(CancellationToken cancellation)
        {
            // By default: Order dashboard definitions by title
            var settings = await _behavior.Settings(cancellation);

            string orderby = $"{nameof(DashboardDefinition.Title)},{nameof(DashboardDefinition.Id)}";

            if (settings.SecondaryLanguageId == CultureInfo.CurrentUICulture.Name)
            {
                orderby = $"{nameof(DashboardDefinition.Title2)},{nameof(DashboardDefinition.Title)},{nameof(DashboardDefinition.Id)}";
            }
            else if (settings.TernaryLanguageId == CultureInfo.CurrentUICulture.Name)
            {
                orderby = $"{nameof(DashboardDefinition.Title3)},{nameof(DashboardDefinition.Title)},{nameof(DashboardDefinition.Id)}";
            }

            return(ExpressionOrderBy.Parse(orderby));
        }
Ejemplo n.º 6
0
 protected override ExpressionOrderBy DefaultOrderBy()
 {
     return(ExpressionOrderBy.Parse(nameof(ExchangeRate.ValidAsOf) + " desc"));
 }
Ejemplo n.º 7
0
        protected override Task <ExpressionOrderBy> DefaultOrderBy(CancellationToken _)
        {
            var result = ExpressionOrderBy.Parse(nameof(PrintingTemplate.Name));

            return(Task.FromResult(result));
        }
Ejemplo n.º 8
0
        protected override Task <ExpressionOrderBy> DefaultOrderBy(CancellationToken _)
        {
            var result = ExpressionOrderBy.Parse("CreatedAt desc");

            return(Task.FromResult(result));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns an <see cref="List{TEntity}"/> based on a custom <paramref name="filterFunc"/> applied to the query, as well as
        /// optional <paramref name="expand"/> and <paramref name="select"/> arguments, checking the user's READ permissions along the way.
        /// </summary>
        /// <param name="filterFunc">Allows any kind of filtering on the query</param>
        /// <param name="expand">Optional expand argument.</param>
        /// <param name="select">Optional select argument.</param>
        /// <param name="orderby">Optional orderby argument.</param>
        /// <param name="permissionsFilter">Optional filter argument, if null is passed the query uses the read permissions filter of the current user.</param>
        /// <param name="cancellation">The cancellation instruction.</param>
        protected async Task <List <TEntity> > GetEntitiesByCustomQuery(
            Func <EntityQuery <TEntity>, EntityQuery <TEntity> > filterFunc,
            ExpressionExpand expand,
            ExpressionSelect select,
            ExpressionOrderBy orderby,
            ExpressionFilter permissionsFilter,
            CancellationToken cancellation)
        {
            // Prepare a query of the result, and clone it
            var factory = QueryFactory();
            var query   = factory.EntityQuery <TEntity>();

            // Apply custom filter function
            query = filterFunc(query);

            // Apply read permissions
            permissionsFilter ??= await UserPermissionsFilter(PermissionActions.Read, cancellation);

            query = query.Filter(permissionsFilter);

            // Expand, Select and Order the result as specified in the Queryex agruments
            var expandedQuery = query.Expand(expand).Select(select).OrderBy(orderby ?? ExpressionOrderBy.Parse("Id")); // Required

            // Load the result into memory
            var data = await expandedQuery.ToListAsync(QueryContext(), cancellation); // this is potentially unordered, should that be a concern?

            // Return
            return(data);
        }
Ejemplo n.º 10
0
        protected override Task <ExpressionOrderBy> DefaultOrderBy(CancellationToken _)
        {
            var result = ExpressionOrderBy.Parse(nameof(DetailsEntry.AccountId));

            return(Task.FromResult(result));
        }
Ejemplo n.º 11
0
        protected override Task <ExpressionOrderBy> DefaultOrderBy(CancellationToken _)
        {
            var result = ExpressionOrderBy.Parse(nameof(ExchangeRate.ValidAsOf) + " desc");

            return(Task.FromResult(result));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Returns a list of entities and optionally their count as per the specifications in <paramref name="args"/>.
        /// </summary>
        public virtual async Task <TEntitiesResult> GetEntities(GetArguments args, CancellationToken cancellation)
        {
            await Initialize(cancellation);

            // Parse the parameters
            var filter  = ExpressionFilter.Parse(args.Filter);
            var orderby = ExpressionOrderBy.Parse(args.OrderBy);
            var expand  = ExpressionExpand.Parse(args.Expand);
            var select  = ParseSelect(args.Select);

            // Prepare the query
            var query = QueryFactory().EntityQuery <TEntity>();

            // Apply read permissions
            var permissionsFilter = await UserPermissionsFilter(PermissionActions.Read, cancellation);

            query = query.Filter(permissionsFilter);

            // Apply search
            query = await Search(query, args, cancellation);

            // Apply filter
            query = query.Filter(filter);

            // Apply orderby
            orderby ??= await DefaultOrderBy(cancellation);

            query = query.OrderBy(orderby);

            // Apply the paging (Protect against DOS attacks by enforcing a maximum page size)
            var top  = args.Top;
            var skip = args.Skip;

            top   = Math.Min(top, MaximumPageSize());
            query = query.Skip(skip).Top(top);

            // Apply the expand, which has the general format 'Expand=A,B.C,D'
            query = query.Expand(expand);

            // Apply the select, which has the general format 'Select=A,B.C,D'
            query = query.Select(select);

            // Load the data and count in memory
            List <TEntity> data;
            int?           count = null;

            if (args.CountEntities)
            {
                var output = await query.ToListAndCountAsync(MaximumCount, QueryContext, cancellation);

                data  = output.Entities;
                count = output.Count;
            }
            else
            {
                data = await query.ToListAsync(QueryContext, cancellation);
            }

            // Return
            return(await ToEntitiesResult(data, count, cancellation));
        }
Ejemplo n.º 13
0
 protected override Task <ExpressionOrderBy> DefaultOrderBy(CancellationToken _)
 {
     return(Task.FromResult(ExpressionOrderBy.Parse("Id desc")));
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Returns an <see cref="List{TEntity}"/> based on a custom filtering function applied to the query, as well as
        /// optional select and expand arguments, checking the user READ permissions along the way
        /// </summary>
        /// <param name="filterFunc">Allows any kind of filtering on the query</param>
        /// <param name="expand">Optional expand argument</param>
        /// <param name="select">Optional select argument</param>
        /// <param name="orderby">Optional select argument</param>
        /// <param name="permissionsFilter">Optional filter argument, if null is passed the q</param>
        /// <param name="cancellation">Optional select argument</param>
        protected async Task <List <TEntity> > GetEntitiesByCustomQuery(
            Func <Query <TEntity>, Query <TEntity> > filterFunc,
            ExpressionExpand expand,
            ExpressionSelect select,
            ExpressionOrderBy orderby,
            ExpressionFilter permissionsFilter,
            CancellationToken cancellation)
        {
            // Prepare a query of the result, and clone it
            var repo  = GetRepository();
            var query = repo.Query <TEntity>();

            // Apply custom filter function
            query = filterFunc(query);

            // Apply read permissions
            permissionsFilter ??= await UserPermissionsFilter(Constants.Read, cancellation);

            query = query.Filter(permissionsFilter);

            // Expand, Select and Order the result as specified in the OData agruments
            var expandedQuery = query.Expand(expand).Select(select).OrderBy(orderby ?? ExpressionOrderBy.Parse("Id")); // Required

            // Load the result into memory
            var data = await expandedQuery.ToListAsync(cancellation); // this is potentially unordered, should that be a concern?

            // TODO: This is slow and unused
            // Apply the permission masks (setting restricted fields to null) and adjust the metadata accordingly
            // await ApplyReadPermissionsMask(data, query, permissions, GetDefaultMask(), cancellation);

            // Return
            return(data);
        }
Ejemplo n.º 15
0
 protected override ExpressionOrderBy DefaultOrderBy()
 {
     return(ExpressionOrderBy.Parse(nameof(Account.Code)));
 }
Ejemplo n.º 16
0
 protected override ExpressionOrderBy DefaultOrderBy()
 {
     return(ExpressionOrderBy.Parse("Id desc"));
 }
Ejemplo n.º 17
0
 protected override ExpressionOrderBy DefaultOrderBy()
 {
     return(ExpressionOrderBy.Parse(nameof(DetailsEntry.AccountId)));
 }