コード例 #1
0
        /// <summary>
        /// Maps a batch of the same type of page module data to a collection
        /// of display models ready for rendering.
        /// </summary>
        /// <param name="typeName">The module type name e.g. 'PlainText', 'RawHtml'.</param>
        /// <param name="versionModule">The version data to get the serialized model from.</param>
        /// <param name="workflowStatus">
        /// The workflow status of the parent page or custom entity
        /// being mapped. This is provided so dependent entities can use
        /// the same workflow status.
        /// </param>
        /// <returns>
        /// Collection of mapped display models, wrapped in an output class that
        /// can be used to identify them.
        /// </returns>
        public List <PageModuleDisplayModelMapperOutput> MapDisplayModel(
            string typeName,
            IEnumerable <IEntityVersionPageModule> versionModules,
            WorkFlowStatusQuery workflowStatus
            )
        {
            // Find the data-provider class for this type of module
            Type modelType = _moduleDataModelTypeFactory.CreateByPageModuleTypeFileName(typeName);

            if (typeof(IPageModuleDisplayModel).IsAssignableFrom(modelType))
            {
                // We can serialize directly to the display model
                var displayModels = new List <PageModuleDisplayModelMapperOutput>();
                foreach (var pageModule in versionModules)
                {
                    var mapperModel = new PageModuleDisplayModelMapperOutput();
                    mapperModel.DisplayModel    = (IPageModuleDisplayModel)_dbUnstructuredDataSerializer.Deserialize(pageModule.SerializedData, modelType);
                    mapperModel.VersionModuleId = pageModule.GetVersionModuleId();
                    displayModels.Add(mapperModel);
                }

                return(displayModels);
            }
            else
            {
                var moduleWorkflowStatus = TranslateWorkFlowStatusForModules(workflowStatus);

                // We have to use a mapping class to do some custom mapping
                var displayModels = (List <PageModuleDisplayModelMapperOutput>)_mapGenericMethod
                                    .MakeGenericMethod(modelType)
                                    .Invoke(this, new object[] { versionModules, moduleWorkflowStatus });

                return(displayModels);
            }
        }
コード例 #2
0
 public GetCustomEntityRenderSummariesByDefinitionCodeQuery(
     string customEntityDefinitionCode,
     WorkFlowStatusQuery workflowStatus = WorkFlowStatusQuery.Latest
     )
 {
     CustomEntityDefinitionCode = customEntityDefinitionCode;
     WorkFlowStatus             = workflowStatus;
 }
コード例 #3
0
        /// <summary>
        /// When working with child entities, the WorkFlosStatus we apply to
        /// them is not neccessarily the status used to query the parent. If we are
        /// loading a page using the Draft status, then we cannot expect that all
        /// dependencies should have a draft version, so we re-write it to Latest.
        /// The same applies if we're loading a specific version.
        /// </summary>
        /// <param name="workflowStatus">The original workflow status of the parent entity.</param>
        private WorkFlowStatusQuery TranslateWorkFlowStatusForModules(WorkFlowStatusQuery workflowStatus)
        {
            if (workflowStatus == WorkFlowStatusQuery.Draft || workflowStatus == WorkFlowStatusQuery.SpecificVersion)
            {
                workflowStatus = WorkFlowStatusQuery.Latest;
            }

            return(workflowStatus);
        }
        public GetCustomEntityRenderSummariesByIdRangeQuery(
            IEnumerable <int> customEntityIds,
            WorkFlowStatusQuery workflowStatus = WorkFlowStatusQuery.Latest
            )
        {
            Condition.Requires(customEntityIds).IsNotNull();

            CustomEntityIds = customEntityIds.ToArray();
            WorkFlowStatus  = workflowStatus;
        }
コード例 #5
0
 /// <summary>
 /// Maps a single page module data model to a concrete
 /// display model.
 /// </summary>
 /// <param name="typeName">The module type name e.g. 'PlainText', 'RawHtml'.</param>
 /// <param name="versionModule">The version data to get the serialized model from.</param>
 /// <param name="workflowStatus">
 /// The workflow status of the parent page or custom entity
 /// being mapped. This is provided so dependent entities can use
 /// the same workflow status.
 /// </param>
 /// <returns>Mapped display model.</returns>
 public IPageModuleDisplayModel MapDisplayModel(
     string typeName,
     IEntityVersionPageModule versionModule,
     WorkFlowStatusQuery workflowStatus
     )
 {
     return(MapDisplayModel(typeName, new IEntityVersionPageModule[] { versionModule }, workflowStatus)
            .Select(m => m.DisplayModel)
            .SingleOrDefault());
 }
コード例 #6
0
        /// <summary>
        /// Gets version routing info for the specified WorkFlowStatus query
        /// </summary>
        public static T GetVersionRouting <T>(this IEnumerable <T> versions, WorkFlowStatusQuery status, int?versionId = null)
            where T : IVersionRoute
        {
            T result;

            switch (status)
            {
            case WorkFlowStatusQuery.Draft:
                result = versions
                         .SingleOrDefault(v => v.WorkFlowStatus == WorkFlowStatus.Draft);
                break;

            case WorkFlowStatusQuery.Published:
                result = versions
                         .SingleOrDefault(v => v.WorkFlowStatus == WorkFlowStatus.Published);
                break;

            case WorkFlowStatusQuery.Latest:
                result = versions
                         .Where(v => v.WorkFlowStatus == WorkFlowStatus.Draft || v.WorkFlowStatus == WorkFlowStatus.Published)
                         .OrderByDescending(v => v.WorkFlowStatus == WorkFlowStatus.Draft)
                         .FirstOrDefault();
                break;

            case WorkFlowStatusQuery.PreferPublished:
                result = versions
                         .Where(v => v.WorkFlowStatus == WorkFlowStatus.Draft || v.WorkFlowStatus == WorkFlowStatus.Published)
                         .OrderByDescending(v => v.WorkFlowStatus == WorkFlowStatus.Published)
                         .FirstOrDefault();
                break;

            case WorkFlowStatusQuery.SpecificVersion:
                if (!versionId.HasValue)
                {
                    throw new InvalidOperationException("WorkFlowStatusQuery.SpecificVersion requires a specific VersionId");
                }
                result = versions
                         .SingleOrDefault(v => v.VersionId == versionId);
                break;

            default:
                throw new InvalidOperationException("Unrecognised WorkFlowStatusQuery: " + status);
            }

            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Gets an IVersionRoute that matches the specified workFlowStatusQuery and version number.
        /// </summary>
        /// <param name="preferCustomEntity">Look for the CustomEntityRouting if its available.</param>
        public IVersionRoute GetVersionRoute(bool preferCustomEntity, WorkFlowStatusQuery workFlowStatusQuery, int?versionId)
        {
            IEnumerable <IVersionRoute> versions = null;

            if (preferCustomEntity && CustomEntityRoute != null)
            {
                versions = CustomEntityRoute.Versions;
            }
            else if (PageRoute != null)
            {
                versions = PageRoute.Versions;
            }

            if (versions != null)
            {
                return(versions.GetVersionRouting(workFlowStatusQuery, versionId));
            }

            return(null);
        }
コード例 #8
0
        public void MapSections <TModuleRenderDetails>(
            IEnumerable <IEntityVersionPageModule> dbModules,
            IEnumerable <IEntitySectionRenderDetails <TModuleRenderDetails> > sections,
            IEnumerable <PageModuleTypeSummary> allModuleTypes,
            WorkFlowStatusQuery workflowStatus
            )
            where TModuleRenderDetails : IEntityVersionPageModuleRenderDetails, new()
        {
            var mappedModules = ToModuleMappingData(dbModules, allModuleTypes, workflowStatus);

            // Map Sections

            foreach (var section in sections)
            {
                var sectionMappedModules = mappedModules
                                           .Where(m => m.PageModule.PageTemplateSectionId == section.PageTemplateSectionId)
                                           .OrderBy(m => m.PageModule.Ordering);

                section.Modules = ToModuleRenderDetails <TModuleRenderDetails>(sectionMappedModules).ToArray();
            }
        }
コード例 #9
0
        /// <summary>
        /// Filters by workflow status query. Note that this may contain a group by clause and you therefore
        /// will need to apply any includes after you have called this statement otherwise they may be ignored.
        /// </summary>
        public static IQueryable <CustomEntityVersion> FilterByWorkFlowStatusQuery(
            this IQueryable <CustomEntityVersion> dbQuery,
            WorkFlowStatusQuery workFlowStatusQuery,
            int?versionId = null)
        {
            switch (workFlowStatusQuery)
            {
            case WorkFlowStatusQuery.Draft:
                dbQuery = dbQuery.Where(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Draft);
                break;

            case WorkFlowStatusQuery.Published:
                dbQuery = dbQuery.Where(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Published);
                break;

            case WorkFlowStatusQuery.Latest:
                dbQuery = dbQuery
                          .Where(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Draft || v.WorkFlowStatusId == (int)WorkFlowStatus.Published)
                          .GroupBy(e => e.CustomEntityId, (key, g) => g.OrderByDescending(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Draft).FirstOrDefault());
                break;

            case WorkFlowStatusQuery.PreferPublished:
                dbQuery = dbQuery
                          .Where(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Draft || v.WorkFlowStatusId == (int)WorkFlowStatus.Published)
                          .GroupBy(e => e.CustomEntityId, (key, g) => g.OrderByDescending(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Published).FirstOrDefault());
                break;

            case WorkFlowStatusQuery.SpecificVersion:
                dbQuery = dbQuery.Where(v => v.CustomEntityVersionId == versionId);
                break;

            default:
                throw new ArgumentException("Unknown WorkFlowStatusQuery: " + workFlowStatusQuery);
            }

            return(dbQuery);
        }
コード例 #10
0
 public GetCustomEntityRenderSummaryByIdQuery(int customEntityId, WorkFlowStatusQuery workFlowStatus = WorkFlowStatusQuery.Latest)
 {
     CustomEntityId = customEntityId;
     WorkFlowStatus = workFlowStatus;
 }
コード例 #11
0
        public IEnumerable <PageModuleDisplayModelMapperOutput> Map(IEnumerable <PageModuleDisplayModelMapperInput <ImageDataModel> > inputs, WorkFlowStatusQuery workflowStatus)
        {
            var images = _queryExecutor.GetByIdRange <ImageAssetRenderDetails>(inputs.Select(i => i.DataModel.ImageId));

            foreach (var input in inputs)
            {
                var output = Mapper.Map <ImageDisplayModel>(input.DataModel);

                var image = images.GetOrDefault(input.DataModel.ImageId);
                output.Source = _imageAssetRouteLibrary.ImageAsset(image);

                yield return(input.CreateOutput(output));
            }
        }
コード例 #12
0
        public IEnumerable <PageModuleDisplayModelMapperOutput> Map(IEnumerable <PageModuleDisplayModelMapperInput <RichTextDataModel> > inputs, WorkFlowStatusQuery workflowStatus)
        {
            foreach (var input in inputs)
            {
                var output = new RichTextDisplayModel();
                output.RawHtml = new HtmlString(input.DataModel.RawHtml);

                yield return(input.CreateOutput(output));
            }
        }
        private CustomEntityVersionPageModuleRenderDetails Map(CustomEntityVersionPageModule versionModule, string moduleTypeFileName, string customEntityDefinitionCode, WorkFlowStatusQuery workflowStatus)
        {
            _permissionValidationService.EnforceCustomEntityPermission <CustomEntityReadPermission>(customEntityDefinitionCode);

            var moduleType = _queryExecutor.GetById <PageModuleTypeSummary>(versionModule.PageModuleTypeId);

            EntityNotFoundException.ThrowIfNull(moduleType, versionModule.PageModuleTypeId);

            var result = new CustomEntityVersionPageModuleRenderDetails();

            result.CustomEntityVersionPageModuleId = versionModule.CustomEntityVersionPageModuleId;
            result.ModuleType   = moduleType;
            result.DisplayModel = _pageVersionModuleModelMapper.MapDisplayModel(moduleTypeFileName, versionModule, workflowStatus);

            return(result);
        }
コード例 #14
0
        private List <MappedPageModule> ToModuleMappingData(IEnumerable <IEntityVersionPageModule> entityModules, IEnumerable <PageModuleTypeSummary> moduleTypes, WorkFlowStatusQuery workflowStatus)
        {
            var mappedModules = new List <MappedPageModule>();

            foreach (var group in entityModules.GroupBy(m => m.PageModuleTypeId))
            {
                var moduleType   = moduleTypes.SingleOrDefault(t => t.PageModuleTypeId == group.Key);
                var mapperOutput = _pageVersionModuleModelMapper.MapDisplayModel(moduleType.FileName, group, workflowStatus);

                foreach (var module in group)
                {
                    var mappedModule = new MappedPageModule()
                    {
                        PageModule   = module,
                        ModuleType   = moduleType,
                        DisplayModel = mapperOutput.Single(o => o.VersionModuleId == module.GetVersionModuleId()).DisplayModel
                    };

                    mappedModules.Add(mappedModule);
                }
            }

            return(mappedModules);
        }
コード例 #15
0
        private List <PageModuleDisplayModelMapperOutput> MapGeneric <T>(IEnumerable <IEntityVersionPageModule> versionModules, WorkFlowStatusQuery workflowStatus) where T : IPageModuleDataModel
        {
            var mapperType = typeof(IPageModuleDisplayModelMapper <T>);

            if (!_resolutionContext.IsRegistered(mapperType))
            {
                string msg = @"{0} does not implement IPageModuleDisplayModel and no custom mapper could be found. You must create 
                               a class that implements IPageModuleDisplayModelMapper<{0}> if you are using a custom display model. Full type name: {1}";
                throw new ApplicationException(string.Format(msg, typeof(T).Name, typeof(T).FullName));
            }

            var mapper     = (IPageModuleDisplayModelMapper <T>)_resolutionContext.Resolve(typeof(IPageModuleDisplayModelMapper <T>));
            var dataModels = new List <PageModuleDisplayModelMapperInput <T> >();

            foreach (var pageModule in versionModules)
            {
                var mapperModel = new PageModuleDisplayModelMapperInput <T>();
                mapperModel.DataModel       = (T)_dbUnstructuredDataSerializer.Deserialize(pageModule.SerializedData, typeof(T));
                mapperModel.VersionModuleId = pageModule.GetVersionModuleId();
                dataModels.Add(mapperModel);
            }

            return(mapper.Map(dataModels, workflowStatus).ToList());
        }
コード例 #16
0
 public IEnumerable <PageModuleDisplayModelMapperOutput> Map(IEnumerable <PageModuleDisplayModelMapperInput <TInput> > inputs, WorkFlowStatusQuery workflowStatus)
 {
     foreach (var input in inputs)
     {
         var output = Mapper.Map <TOutput>(input.DataModel);
         yield return(input.CreateOutput(output));
     }
 }
コード例 #17
0
        private PageVersionModuleRenderDetails Map(PageVersionModule pageVersionModule, string moduleTypeFileName, WorkFlowStatusQuery workFlowStatus)
        {
            var moduleType = _queryExecutor.GetById <PageModuleTypeSummary>(pageVersionModule.PageModuleTypeId);

            EntityNotFoundException.ThrowIfNull(moduleType, pageVersionModule.PageModuleTypeId);

            var result = new PageVersionModuleRenderDetails();

            result.PageVersionModuleId = pageVersionModule.PageVersionModuleId;
            result.ModuleType          = moduleType;
            result.DisplayModel        = _pageVersionModuleModelMapper.MapDisplayModel(moduleTypeFileName, pageVersionModule, workFlowStatus);

            return(result);
        }
コード例 #18
0
        public IEnumerable <PageModuleDisplayModelMapperOutput> Map(IEnumerable <PageModuleDisplayModelMapperInput <DocumentDataModel> > inputs, WorkFlowStatusQuery workflowStatus)
        {
            var documents = _queryExecutor.GetByIdRange <DocumentAssetRenderDetails>(inputs.Select(i => i.DataModel.DocumentAssetId));

            foreach (var input in inputs)
            {
                var document = documents.GetOrDefault(input.DataModel.DocumentAssetId);

                var output = new DocumentDisplayModel();
                if (document != null)
                {
                    output.Description = document.Description;
                    output.Title       = document.Title;
                    output.Url         = _documentAssetRouteLibrary.DocumentAsset(document);
                }

                yield return(input.CreateOutput(output));
            }
        }
コード例 #19
0
        public async Task MapSectionsAsync <TModuleRenderDetails>(IEnumerable <IEntityVersionPageModule> dbModules, IEnumerable <IEntitySectionRenderDetails <TModuleRenderDetails> > sections, WorkFlowStatusQuery workflowStatus, IExecutionContext executionContext)
            where TModuleRenderDetails : IEntityVersionPageModuleRenderDetails, new()
        {
            var allModuleTypes = await _queryExecutor.GetAllAsync <PageModuleTypeSummary>(executionContext);

            var mappedModules = ToModuleMappingData(dbModules, allModuleTypes, workflowStatus);

            // Map Sections

            foreach (var section in sections)
            {
                var sectionMappedModules = mappedModules
                                           .Where(m => m.PageModule.PageTemplateSectionId == section.PageTemplateSectionId)
                                           .OrderBy(m => m.PageModule.Ordering);

                section.Modules = ToModuleRenderDetails <TModuleRenderDetails>(sectionMappedModules).ToArray();
            }
        }