Exemple #1
0
 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
     }));
 }
Exemple #2
0
        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));
        }
Exemple #3
0
        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.FullUrlPath         = 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);
        }
Exemple #4
0
 public IEnumerable <IPermissionApplication> GetPermissions(GetPageRoutingInfoByCustomEntityIdRangeQuery query)
 {
     yield return(new PageReadPermission());
 }
        public IDomainRepositoryQueryContext <IDictionary <int, ICollection <PageRoutingInfo> > > AsRoutingInfo()
        {
            var query = new GetPageRoutingInfoByCustomEntityIdRangeQuery(_customEntityIds);

            return(DomainRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
        }