public IDictionary <int, IEnumerable <PageRoutingInfo> > Execute(GetPageRoutingInfoByCustomEntityIdRangeQuery query, IExecutionContext executionContext)
        {
            var idSets = IdSetQuery(query).ToList();

            if (!idSets.Any())
            {
                return(new Dictionary <int, IEnumerable <PageRoutingInfo> >());
            }

            var customEntityRoutesQueries = GetCustomEntityRoutingQuery(idSets);

            var customEntityRoutes = new Dictionary <int, CustomEntityRoute>();

            foreach (var customEntityRoutesQuery in customEntityRoutesQueries)
            {
                // Probably cached so should be quick
                var routes = _queryExecutor.Execute(customEntityRoutesQuery, executionContext);
                foreach (var route in routes)
                {
                    if (!customEntityRoutes.ContainsKey(route.CustomEntityId))
                    {
                        customEntityRoutes.Add(route.CustomEntityId, route);
                    }
                }
            }

            var pageRoutes = _queryExecutor.GetByIdRange <PageRoute>(idSets.Select(p => p.PageId), executionContext);

            return(Map(executionContext, idSets, customEntityRoutes, pageRoutes));
        }
Example #2
0
        public async Task <PagedQueryResult <CustomEntitySummary> > ExecuteAsync(SearchCustomEntitySummariesQuery query, IExecutionContext executionContext)
        {
            var definition = _queryExecutor.GetById <CustomEntityDefinitionSummary>(query.CustomEntityDefinitionCode);

            EntityNotFoundException.ThrowIfNull(definition, query.CustomEntityDefinitionCode);

            // Get Query
            var dbQuery = GetQuery(query, definition);

            // Execute Query
            var dbPagedResult = dbQuery.ToPagedResult(query);

            var routingsQuery = new GetPageRoutingInfoByCustomEntityIdRangeQuery(dbPagedResult.Items.Select(e => e.CustomEntityId));
            var routings      = await _queryExecutor.ExecuteAsync(routingsQuery);

            var allLocales = (await _queryExecutor.GetAllAsync <ActiveLocale>()).ToDictionary(l => l.LocaleId);

            // Map Items
            var entities = new List <CustomEntitySummary>(dbPagedResult.Items.Length);

            foreach (var dbVersion in dbPagedResult.Items)
            {
                PageRoutingInfo detailsRouting = null;

                if (routings.ContainsKey(dbVersion.CustomEntityId))
                {
                    detailsRouting = routings[dbVersion.CustomEntityId].FirstOrDefault(r => r.CustomEntityRouteRule != null);
                }

                var entity = Mapper.Map <CustomEntitySummary>(dbVersion);

                if (dbVersion.LocaleId.HasValue)
                {
                    entity.Locale = allLocales.GetOrDefault(dbVersion.LocaleId.Value);
                    EntityNotFoundException.ThrowIfNull(entity.Locale, dbVersion.LocaleId.Value);
                }

                if (detailsRouting != null)
                {
                    entity.FullPath = detailsRouting.CustomEntityRouteRule.MakeUrl(detailsRouting.PageRoute, detailsRouting.CustomEntityRoute);
                }

                entity.Model = (ICustomEntityVersionDataModel)_dbUnstructuredDataSerializer.Deserialize(dbVersion.SerializedData, definition.DataModelType);

                entity.AuditData.UpdateDate = dbVersion.VersionAuditData.CreateDate;
                entity.AuditData.Updater    = dbVersion.VersionAuditData.Creator;
                entities.Add(entity);
            }

            return(dbPagedResult.ChangeType(entities));
        }
 private IQueryable <IdQueryResult> IdSetQuery(GetPageRoutingInfoByCustomEntityIdRangeQuery query)
 {
     return(_dbContext
            .Pages
            .AsNoTracking()
            .FilterActive()
            .Join(_dbContext.CustomEntities, p => new { p.CustomEntityDefinitionCode, p.LocaleId }, e => new { e.CustomEntityDefinitionCode, e.LocaleId }, (p, e) => new
     {
         CustomEntity = e,
         Page = p
     })
            .Where(r => query.CustomEntityIds.Contains(r.CustomEntity.CustomEntityId))
            .Select(r => new IdQueryResult()
     {
         PageId = r.Page.PageId,
         CustomEntityId = r.CustomEntity.CustomEntityId,
         CustomEntityDefinitionCode = r.CustomEntity.CustomEntityDefinitionCode
     }));
 }
Example #4
0
        /// <summary>
        /// Maps a collection of EF CustomEntityVersion records from the db into CustomEntitySummary
        /// objects.
        /// </summary>
        /// <param name="dbStatusQueries">Collection of versions to map.</param>
        public async Task <List <CustomEntitySummary> > MapAsync(ICollection <CustomEntityPublishStatusQuery> dbStatusQueries, IExecutionContext executionContext)
        {
            var entities      = new List <CustomEntitySummary>(dbStatusQueries.Count);
            var routingsQuery = new GetPageRoutingInfoByCustomEntityIdRangeQuery(dbStatusQueries.Select(e => e.CustomEntityId));
            var routings      = await _queryExecutor.ExecuteAsync(routingsQuery, executionContext);

            Dictionary <int, ActiveLocale> allLocales = null;
            Dictionary <string, CustomEntityDefinitionSummary> customEntityDefinitions = new Dictionary <string, CustomEntityDefinitionSummary>();
            var hasCheckedQueryValid = false;

            foreach (var dbStatusQuery in dbStatusQueries)
            {
                // Validate the input data
                if (!hasCheckedQueryValid)
                {
                    ValidateQuery(dbStatusQuery);
                }
                hasCheckedQueryValid = true;

                // Easy mappings
                var entity = new CustomEntitySummary()
                {
                    AuditData = _auditDataMapper.MapUpdateAuditDataCreatorData(dbStatusQuery.CustomEntity),
                    CustomEntityDefinitionCode = dbStatusQuery.CustomEntity.CustomEntityDefinitionCode,
                    CustomEntityId             = dbStatusQuery.CustomEntityId,
                    HasDraft      = dbStatusQuery.CustomEntityVersion.WorkFlowStatusId == (int)WorkFlowStatus.Draft,
                    PublishStatus = PublishStatusMapper.FromCode(dbStatusQuery.CustomEntity.PublishStatusCode),
                    PublishDate   = DbDateTimeMapper.AsUtc(dbStatusQuery.CustomEntity.PublishDate),
                    Ordering      = dbStatusQuery.CustomEntity.Ordering,
                    Title         = dbStatusQuery.CustomEntityVersion.Title,
                    UrlSlug       = dbStatusQuery.CustomEntity.UrlSlug
                };

                entity.IsPublished = entity.PublishStatus == PublishStatus.Published && entity.PublishDate <= executionContext.ExecutionDate;
                _auditDataMapper.MapUpdateAuditDataUpdaterData(entity.AuditData, dbStatusQuery.CustomEntityVersion);


                // Routing data (if any)

                PageRoutingInfo detailsRouting = null;
                if (routings.ContainsKey(dbStatusQuery.CustomEntityId))
                {
                    detailsRouting  = routings[dbStatusQuery.CustomEntityId].FirstOrDefault(r => r.CustomEntityRouteRule != null);
                    entity.FullPath = detailsRouting?.CustomEntityRouteRule?.MakeUrl(detailsRouting.PageRoute, detailsRouting.CustomEntityRoute);
                }

                // Locale data

                var localeId = dbStatusQuery.CustomEntity.LocaleId;
                if (localeId.HasValue && detailsRouting != null)
                {
                    entity.Locale = detailsRouting.PageRoute.Locale;
                    EntityNotFoundException.ThrowIfNull(entity.Locale, localeId.Value);
                }
                else if (localeId.HasValue)
                {
                    // Lazy load locales, since they aren't always used
                    if (allLocales == null)
                    {
                        allLocales = await GetLocalesAsync(executionContext);
                    }

                    entity.Locale = allLocales.GetOrDefault(localeId.Value);
                    EntityNotFoundException.ThrowIfNull(entity.Locale, localeId.Value);
                }

                // Parse model data
                var definition = customEntityDefinitions.GetOrDefault(dbStatusQuery.CustomEntity.CustomEntityDefinitionCode);
                if (definition == null)
                {
                    // Load and cache definitions
                    var definitionQuery = new GetCustomEntityDefinitionSummaryByCodeQuery(dbStatusQuery.CustomEntity.CustomEntityDefinitionCode);
                    definition = await _queryExecutor.ExecuteAsync(definitionQuery, executionContext);

                    EntityNotFoundException.ThrowIfNull(definition, definition.CustomEntityDefinitionCode);
                    customEntityDefinitions.Add(dbStatusQuery.CustomEntity.CustomEntityDefinitionCode, definition);
                }

                entity.Model = (ICustomEntityDataModel)_dbUnstructuredDataSerializer.Deserialize(dbStatusQuery.CustomEntityVersion.SerializedData, definition.DataModelType);

                entities.Add(entity);
            }

            return(entities);
        }
        public async Task <IDictionary <int, ICollection <PageRoutingInfo> > > ExecuteAsync(GetPageRoutingInfoByCustomEntityIdRangeQuery query, IExecutionContext executionContext)
        {
            var idSets = await IdSetQuery(query).ToListAsync();

            if (!idSets.Any())
            {
                return(new Dictionary <int, ICollection <PageRoutingInfo> >());
            }

            var customEntityRoutesQueries = GetCustomEntityRoutingQuery(idSets);

            var customEntityRoutes = new Dictionary <int, CustomEntityRoute>();

            foreach (var customEntityRoutesQuery in customEntityRoutesQueries)
            {
                // Probably cached so should be quick
                var routes = await _queryExecutor.ExecuteAsync(customEntityRoutesQuery, executionContext);

                foreach (var route in routes)
                {
                    if (!customEntityRoutes.ContainsKey(route.CustomEntityId))
                    {
                        customEntityRoutes.Add(route.CustomEntityId, route);
                    }
                }
            }

            var pageRoutesQuery = new GetPageRoutesByIdRangeQuery(idSets.Select(p => p.PageId).Distinct());
            var pageRoutes      = await _queryExecutor.ExecuteAsync(pageRoutesQuery, executionContext);

            return(await MapAsync(executionContext, idSets, customEntityRoutes, pageRoutes));
        }
 public IEnumerable <IPermissionApplication> GetPermissions(GetPageRoutingInfoByCustomEntityIdRangeQuery query)
 {
     yield return(new PageReadPermission());
 }
Example #7
0
        public IContentRepositoryQueryContext <IDictionary <int, ICollection <PageRoutingInfo> > > AsRoutingInfo()
        {
            var query = new GetPageRoutingInfoByCustomEntityIdRangeQuery(_customEntityIds);

            return(ContentRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
        }
        public Task <IDictionary <int, ICollection <PageRoutingInfo> > > AsRoutingInfoAsync()
        {
            var query = new GetPageRoutingInfoByCustomEntityIdRangeQuery(_customEntityIds);

            return(ExtendableContentRepository.ExecuteQueryAsync(query));
        }
        /// <summary>
        /// Maps a collection of EF CustomEntityPublishStatusQuery records from the db
        /// into CustomEntitySummary objects. The records must include data for the the
        /// CustomEntity, CustomEntityVersion, CustomEntity.Creator and CustomEntityVersion.Creator
        /// properties.
        /// </summary>
        /// <param name="dbCustomEntities">Collection of CustomEntityPublishStatusQuery records to map.</param>
        /// <param name="executionContext">Execution context to pass down when executing child queries.</param>
        public async Task <List <CustomEntitySummary> > MapAsync(ICollection <CustomEntityPublishStatusQuery> dbCustomEntities, IExecutionContext executionContext)
        {
            var entities      = new List <CustomEntitySummary>(dbCustomEntities.Count);
            var routingsQuery = new GetPageRoutingInfoByCustomEntityIdRangeQuery(dbCustomEntities.Select(e => e.CustomEntityId));
            var routings      = await _queryExecutor.ExecuteAsync(routingsQuery, executionContext);

            Dictionary <int, ActiveLocale> allLocales = null;
            var customEntityDefinitions = new Dictionary <string, CustomEntityDefinitionSummary>();
            var hasCheckedQueryValid    = false;

            foreach (var dbCustomEntity in dbCustomEntities)
            {
                // Validate the input data
                if (!hasCheckedQueryValid)
                {
                    ValidateQuery(dbCustomEntity);
                }
                hasCheckedQueryValid = true;

                // Easy mappings
                var entity = MapBasicProperties(dbCustomEntity);

                // Routing data (if any)
                var detailsRouting = FindRoutingData(routings, dbCustomEntity);

                if (detailsRouting != null)
                {
                    entity.FullPath            = detailsRouting.CustomEntityRouteRule.MakeUrl(detailsRouting.PageRoute, detailsRouting.CustomEntityRoute);
                    entity.HasPublishedVersion = detailsRouting.CustomEntityRoute.HasPublishedVersion;
                }

                // Locale data

                var localeId = dbCustomEntity.CustomEntity.LocaleId;
                if (localeId.HasValue && detailsRouting != null)
                {
                    entity.Locale = detailsRouting.PageRoute.Locale;
                    EntityNotFoundException.ThrowIfNull(entity.Locale, localeId.Value);
                }
                else if (localeId.HasValue)
                {
                    // Lazy load locales, since they aren't always used
                    if (allLocales == null)
                    {
                        allLocales = await GetLocalesAsync(executionContext);
                    }

                    entity.Locale = allLocales.GetOrDefault(localeId.Value);
                    EntityNotFoundException.ThrowIfNull(entity.Locale, localeId.Value);
                }

                // Parse model data
                var definition = customEntityDefinitions.GetOrDefault(dbCustomEntity.CustomEntity.CustomEntityDefinitionCode);
                if (definition == null)
                {
                    // Load and cache definitions
                    var definitionQuery = new GetCustomEntityDefinitionSummaryByCodeQuery(dbCustomEntity.CustomEntity.CustomEntityDefinitionCode);
                    definition = await _queryExecutor.ExecuteAsync(definitionQuery, executionContext);

                    EntityNotFoundException.ThrowIfNull(definition, definition.CustomEntityDefinitionCode);
                    customEntityDefinitions.Add(dbCustomEntity.CustomEntity.CustomEntityDefinitionCode, definition);
                }

                entity.Model = (ICustomEntityDataModel)_dbUnstructuredDataSerializer.Deserialize(dbCustomEntity.CustomEntityVersion.SerializedData, definition.DataModelType);

                entities.Add(entity);
            }

            await EnsureHasPublishedVersionSet(entities);

            return(entities);
        }