示例#1
0
        private CustomEntityDetails MapInitialData(CustomEntityVersion dbVersion, IExecutionContext executionContext)
        {
            var entity = new CustomEntityDetails()
            {
                CustomEntityId = dbVersion.CustomEntity.CustomEntityId,
                UrlSlug        = dbVersion.CustomEntity.UrlSlug,
                PublishStatus  = PublishStatusMapper.FromCode(dbVersion.CustomEntity.PublishStatusCode),
                PublishDate    = DbDateTimeMapper.AsUtc(dbVersion.CustomEntity.PublishDate),
            };

            entity.IsPublished = entity.PublishStatus == PublishStatus.Published && entity.PublishDate <= executionContext.ExecutionDate;
            entity.AuditData   = _auditDataMapper.MapCreateAuditData(dbVersion.CustomEntity);

            entity.LatestVersion = new CustomEntityVersionDetails()
            {
                CustomEntityVersionId = dbVersion.CustomEntityVersionId,
                Title          = dbVersion.Title,
                WorkFlowStatus = (WorkFlowStatus)dbVersion.WorkFlowStatusId
            };

            entity.LatestVersion.AuditData = _auditDataMapper.MapCreateAuditData(dbVersion);
            entity.HasDraft = entity.LatestVersion.WorkFlowStatus == WorkFlowStatus.Draft;

            return(entity);
        }
        private CustomEntityRenderSummary MapCore(CustomEntityVersion dbResult)
        {
            var entity = new CustomEntityRenderSummary()
            {
                CreateDate = DbDateTimeMapper.AsUtc(dbResult.CreateDate),
                CustomEntityDefinitionCode = dbResult.CustomEntity.CustomEntityDefinitionCode,
                CustomEntityId             = dbResult.CustomEntityId,
                CustomEntityVersionId      = dbResult.CustomEntityVersionId,
                Ordering       = dbResult.CustomEntity.Ordering,
                Title          = dbResult.Title,
                UrlSlug        = dbResult.CustomEntity.UrlSlug,
                WorkFlowStatus = (WorkFlowStatus)dbResult.WorkFlowStatusId,
                PublishDate    = DbDateTimeMapper.AsUtc(dbResult.CustomEntity.PublishDate)
            };

            entity.PublishStatus = PublishStatusMapper.FromCode(dbResult.CustomEntity.PublishStatusCode);
            entity.Model         = _customEntityDataModelMapper.Map(dbResult.CustomEntity.CustomEntityDefinitionCode, dbResult.SerializedData);

            return(entity);
        }
        private CustomEntitySummary MapBasicProperties(CustomEntityPublishStatusQuery dbStatusQuery)
        {
            var entity = new CustomEntitySummary()
            {
                AuditData = _auditDataMapper.MapUpdateAuditDataCreatorData(dbStatusQuery.CustomEntity),
                CustomEntityDefinitionCode = dbStatusQuery.CustomEntity.CustomEntityDefinitionCode,
                CustomEntityId             = dbStatusQuery.CustomEntityId,
                HasDraftVersion            = dbStatusQuery.CustomEntityVersion.WorkFlowStatusId == (int)WorkFlowStatus.Draft,
                // note that if this is not a published version, we do further checks on this later in the process
                HasPublishedVersion = dbStatusQuery.CustomEntityVersion.WorkFlowStatusId == (int)WorkFlowStatus.Published,
                PublishStatus       = PublishStatusMapper.FromCode(dbStatusQuery.CustomEntity.PublishStatusCode),
                PublishDate         = DbDateTimeMapper.AsUtc(dbStatusQuery.CustomEntity.PublishDate),
                Ordering            = dbStatusQuery.CustomEntity.Ordering,
                Title   = dbStatusQuery.CustomEntityVersion.Title,
                UrlSlug = dbStatusQuery.CustomEntity.UrlSlug
            };

            _auditDataMapper.MapUpdateAuditDataUpdaterData(entity.AuditData, dbStatusQuery.CustomEntityVersion);
            return(entity);
        }
示例#4
0
        private CustomEntityRenderDetails MapCustomEntity(CustomEntityVersion dbResult, IExecutionContext executionContext)
        {
            _permissionValidationService.EnforceCustomEntityPermission <CustomEntityReadPermission>(dbResult.CustomEntity.CustomEntityDefinitionCode, executionContext.UserContext);

            var entity = new CustomEntityRenderDetails()
            {
                CreateDate = DbDateTimeMapper.AsUtc(dbResult.CreateDate),
                CustomEntityDefinitionCode = dbResult.CustomEntity.CustomEntityDefinitionCode,
                CustomEntityId             = dbResult.CustomEntityId,
                CustomEntityVersionId      = dbResult.CustomEntityVersionId,
                Ordering       = dbResult.CustomEntity.Ordering,
                Title          = dbResult.Title,
                UrlSlug        = dbResult.CustomEntity.UrlSlug,
                WorkFlowStatus = (WorkFlowStatus)dbResult.WorkFlowStatusId,
                PublishDate    = DbDateTimeMapper.AsUtc(dbResult.CustomEntity.PublishDate)
            };

            entity.PublishStatus = PublishStatusMapper.FromCode(dbResult.CustomEntity.PublishStatusCode);
            entity.Model         = _customEntityDataModelMapper.Map(dbResult.CustomEntity.CustomEntityDefinitionCode, dbResult.SerializedData);

            return(entity);
        }
示例#5
0
        private async Task<CustomEntityRenderDetails> MapCustomEntityAsync(CustomEntityVersion dbResult)
        {
            await _permissionValidationService.EnforceCustomEntityPermissionAsync<CustomEntityReadPermission>(dbResult.CustomEntity.CustomEntityDefinitionCode);

            var entity = new CustomEntityRenderDetails()
            {
                CreateDate = DbDateTimeMapper.AsUtc(dbResult.CreateDate),
                CustomEntityDefinitionCode = dbResult.CustomEntity.CustomEntityDefinitionCode,
                CustomEntityId = dbResult.CustomEntityId,
                CustomEntityVersionId = dbResult.CustomEntityVersionId,
                Ordering = dbResult.CustomEntity.Ordering,
                Title = dbResult.Title,
                UrlSlug = dbResult.CustomEntity.UrlSlug,
                WorkFlowStatus = (WorkFlowStatus)dbResult.WorkFlowStatusId,
                PublishDate = DbDateTimeMapper.AsUtc(dbResult.CustomEntity.PublishDate)
            };

            entity.PublishStatus = PublishStatusMapper.FromCode(dbResult.CustomEntity.PublishStatusCode);
            entity.Model = _customEntityDataModelMapper.Map(dbResult.CustomEntity.CustomEntityDefinitionCode, dbResult.SerializedData);
            
            return entity;
        }
        private IQueryable <PageQueryResult> QueryPages()
        {
            var dbPages = _dbContext
                          .Pages
                          .AsNoTracking()
                          .FilterActive()
                          .Select(p => new PageQueryResult()
            {
                RoutingInfo = new PageRoute()
                {
                    PageId   = p.PageId,
                    UrlPath  = p.UrlPath,
                    PageType = (PageType)p.PageTypeId,
                    CustomEntityDefinitionCode = p.CustomEntityDefinitionCode,
                    PublishDate   = p.PublishDate,
                    PublishStatus = PublishStatusMapper.FromCode(p.PublishStatusCode)
                },
                LocaleId        = p.LocaleId,
                PageDirectoryId = p.PageDirectoryId
            });

            return(dbPages);
        }
示例#7
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);
        }