Esempio n. 1
0
        protected override void PersistUpdatedItem(IMemberType entity)
        {
            ValidateAlias(entity);

            //Updates Modified date
            entity.UpdatingEntity();

            //Look up parent to get and set the correct Path if ParentId has changed
            if (entity.IsPropertyDirty("ParentId"))
            {
                var parent = Database.First <NodeDto>("WHERE id = @ParentId", new { ParentId = entity.ParentId });
                entity.Path  = string.Concat(parent.Path, ",", entity.Id);
                entity.Level = parent.Level + 1;
                var maxSortOrder =
                    Database.ExecuteScalar <int>(
                        "SELECT coalesce(max(sortOrder),0) FROM umbracoNode WHERE parentid = @ParentId AND nodeObjectType = @NodeObjectType",
                        new { ParentId = entity.ParentId, NodeObjectType = NodeObjectTypeId });
                entity.SortOrder = maxSortOrder + 1;
            }

            EnsureExplicitDataTypeForBuiltInProperties(entity);
            PersistUpdatedBaseContentType(entity);

            // remove and insert - handle cmsMemberType table
            Database.Delete <MemberPropertyTypeDto>("WHERE NodeId = @Id", new { Id = entity.Id });
            var memberTypeDtos = ContentTypeFactory.BuildMemberPropertyTypeDtos(entity);

            foreach (var memberTypeDto in memberTypeDtos)
            {
                Database.Insert(memberTypeDto);
            }

            entity.ResetDirtyProperties();
        }
Esempio n. 2
0
        protected override void PersistNewItem(IMemberType entity)
        {
            ValidateAlias(entity);

            entity.AddingEntity();

            //set a default icon if one is not specified
            if (entity.Icon.IsNullOrWhiteSpace())
            {
                entity.Icon = Constants.Icons.Member;
            }

            //By Convention we add 9 standard PropertyTypes to an Umbraco MemberType
            entity.AddPropertyGroup(Constants.Conventions.Member.StandardPropertiesGroupName);
            var standardPropertyTypes = Constants.Conventions.Member.GetStandardPropertyTypeStubs();

            foreach (var standardPropertyType in standardPropertyTypes)
            {
                entity.AddPropertyType(standardPropertyType.Value, Constants.Conventions.Member.StandardPropertiesGroupName);
            }

            EnsureExplicitDataTypeForBuiltInProperties(entity);
            PersistNewBaseContentType(entity);

            //Handles the MemberTypeDto (cmsMemberType table)
            var memberTypeDtos = ContentTypeFactory.BuildMemberPropertyTypeDtos(entity);

            foreach (var memberTypeDto in memberTypeDtos)
            {
                Database.Insert(memberTypeDto);
            }

            entity.ResetDirtyProperties();
        }
Esempio n. 3
0
        private void ResetContext(string url)
        {
            _provider.SiteUrl = url;
            var context = _provider.Create();

            _contentTypeFactory = new ContentTypeFactory(context);
            _listFactory        = new ListFactory(context);
            _service            = new SharepointService(context);
        }
Esempio n. 4
0
 public ProcessedContentRepository(IStubToUrlConverter urlGenerator, IHttpClient httpClient, ContentTypeFactory contentTypeFactory, IApplicationConfiguration config)
 {
     _urlGenerator         = urlGenerator;
     _httpClient           = httpClient;
     _contentTypeFactory   = contentTypeFactory;
     _config               = config;
     authenticationHeaders = new Dictionary <string, string> {
         { "Authorization", _config.GetContentApiAuthenticationKey() }, { "X-ClientId", _config.GetWebAppClientId() }
     };
 }
        protected override void PersistUpdatedItem(IContentType entity)
        {
            Mandate.That <Exception>(string.IsNullOrEmpty(entity.Alias) == false,
                                     () =>
            {
                var message =
                    string.Format(
                        "ContentType '{0}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.",
                        entity.Name);
                var exception = new Exception(message);

                LogHelper.Error <ContentTypeRepository>(message, exception);
                throw exception;
            });

            //Updates Modified date
            ((ContentType)entity).UpdatingEntity();

            //Look up parent to get and set the correct Path if ParentId has changed
            if (((ICanBeDirty)entity).IsPropertyDirty("ParentId"))
            {
                var parent = Database.First <NodeDto>("WHERE id = @ParentId", new { ParentId = entity.ParentId });
                entity.Path  = string.Concat(parent.Path, ",", entity.Id);
                entity.Level = parent.Level + 1;
                var maxSortOrder =
                    Database.ExecuteScalar <int>(
                        "SELECT coalesce(max(sortOrder),0) FROM umbracoNode WHERE parentid = @ParentId AND nodeObjectType = @NodeObjectType",
                        new { ParentId = entity.ParentId, NodeObjectType = NodeObjectTypeId });
                entity.SortOrder = maxSortOrder + 1;
            }

            var factory = new ContentTypeFactory(NodeObjectTypeId);
            var dto     = factory.BuildDto(entity);

            PersistUpdatedBaseContentType(dto.ContentTypeDto, entity);

            //Look up DocumentType entries for updating - this could possibly be a "remove all, insert all"-approach
            Database.Delete <DocumentTypeDto>("WHERE contentTypeNodeId = @Id", new { Id = entity.Id });
            //Insert the updated DocumentTypeDto if a template exists
            if (dto.TemplateNodeId > 0)
            {
                Database.Insert(dto);
            }

            //Insert allowed Templates not including the default one, as that has already been inserted
            foreach (var template in entity.AllowedTemplates.Where(x => x != null && x.Id != dto.TemplateNodeId))
            {
                Database.Insert(new DocumentTypeDto {
                    ContentTypeNodeId = entity.Id, TemplateNodeId = template.Id, IsDefault = false
                });
            }

            ((ICanBeDirty)entity).ResetDirtyProperties();
        }
Esempio n. 6
0
        public ContentFactoryTest()
        {
            var tagParserContainer     = new Mock <ISimpleTagParserContainer>();
            var profileTagParser       = new Mock <IDynamicTagParser <Profile> >();
            var documentTagParser      = new Mock <IDynamicTagParser <Document> >();
            var alertsInlineTagParser  = new Mock <IDynamicTagParser <Alert> >();
            var httpContextAccessor    = new Mock <IHttpContextAccessor>();
            var s3BucketParser         = new Mock <IDynamicTagParser <S3BucketSearch> >();
            var privacyNoticeTagParser = new Mock <IDynamicTagParser <PrivacyNotice> >();

            tagParserContainer.Setup(o => o.ParseAll(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>())).Returns("");
            s3BucketParser.Setup(o => o.Parse(It.IsAny <string>(), It.IsAny <IEnumerable <S3BucketSearch> >())).Returns("");

            _factory = new ContentTypeFactory(tagParserContainer.Object, profileTagParser.Object, new MarkdownWrapper(), documentTagParser.Object, alertsInlineTagParser.Object, httpContextAccessor.Object, s3BucketParser.Object, privacyNoticeTagParser.Object);
        }
        protected override IContentType PerformGet(int id)
        {
            var contentTypeSql = GetBaseQuery(false);

            contentTypeSql.Where(GetBaseWhereClause(), new { Id = id });

            // The SQL will contain one record for each allowed template, so order to put the default one
            // at the top to populate the default template property correctly.
            contentTypeSql.OrderByDescending <DocumentTypeDto>(x => x.IsDefault);

            var dto = Database.Fetch <DocumentTypeDto, ContentTypeDto, NodeDto>(contentTypeSql).FirstOrDefault();

            if (dto == null)
            {
                return(null);
            }

            var factory     = new ContentTypeFactory(NodeObjectTypeId);
            var contentType = factory.BuildEntity(dto);

            contentType.AllowedContentTypes          = GetAllowedContentTypeIds(id);
            contentType.PropertyGroups               = GetPropertyGroupCollection(id, contentType.CreateDate, contentType.UpdateDate);
            ((ContentType)contentType).PropertyTypes = GetPropertyTypeCollection(id, contentType.CreateDate, contentType.UpdateDate);

            var templates = Database.Fetch <DocumentTypeDto>("WHERE contentTypeNodeId = @Id", new { Id = id });

            if (templates.Any())
            {
                contentType.AllowedTemplates = templates.Select(template => _templateRepository.Get(template.TemplateNodeId)).ToList();
            }

            var list = Database.Fetch <ContentType2ContentTypeDto>("WHERE childContentTypeId = @Id", new { Id = id });

            foreach (var contentTypeDto in list)
            {
                bool result = contentType.AddContentType(Get(contentTypeDto.ParentId));
                //Do something if adding fails? (Should hopefully not be possible unless someone created a circular reference)
            }

            //on initial construction we don't want to have dirty properties tracked
            // http://issues.umbraco.org/issue/U4-1946
            ((Entity)contentType).ResetDirtyProperties(false);
            return(contentType);
        }
Esempio n. 8
0
        protected override void PersistUpdatedItem(IContentType entity)
        {
            ValidateAlias(entity);

            //Updates Modified date
            ((ContentType)entity).UpdatingEntity();

            //Look up parent to get and set the correct Path if ParentId has changed
            if (entity.IsPropertyDirty("ParentId"))
            {
                var parent = Database.First <NodeDto>("WHERE id = @ParentId", new { ParentId = entity.ParentId });
                entity.Path  = string.Concat(parent.Path, ",", entity.Id);
                entity.Level = parent.Level + 1;
                var maxSortOrder =
                    Database.ExecuteScalar <int>(
                        "SELECT coalesce(max(sortOrder),0) FROM umbracoNode WHERE parentid = @ParentId AND nodeObjectType = @NodeObjectType",
                        new { ParentId = entity.ParentId, NodeObjectType = NodeObjectTypeId });
                entity.SortOrder = maxSortOrder + 1;
            }

            var factory = new ContentTypeFactory(NodeObjectTypeId);
            var dto     = factory.BuildDto(entity);

            PersistUpdatedBaseContentType(dto.ContentTypeDto, entity);

            //Look up DocumentType entries for updating - this could possibly be a "remove all, insert all"-approach
            Database.Delete <DocumentTypeDto>("WHERE contentTypeNodeId = @Id", new { Id = entity.Id });
            //Insert the updated DocumentTypeDto if a template exists
            if (dto.TemplateNodeId > 0)
            {
                Database.Insert(dto);
            }

            //Insert allowed Templates not including the default one, as that has already been inserted
            foreach (var template in entity.AllowedTemplates.Where(x => x != null && x.Id != dto.TemplateNodeId))
            {
                Database.Insert(new DocumentTypeDto {
                    ContentTypeNodeId = entity.Id, TemplateNodeId = template.Id, IsDefault = false
                });
            }

            entity.ResetDirtyProperties();
        }
        protected override void PersistNewItem(IContentType entity)
        {
            Mandate.That <Exception>(string.IsNullOrEmpty(entity.Alias) == false,
                                     () =>
            {
                var message =
                    string.Format(
                        "ContentType '{0}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.",
                        entity.Name);
                var exception = new Exception(message);

                LogHelper.Error <ContentTypeRepository>(message, exception);
                throw exception;
            });

            ((ContentType)entity).AddingEntity();

            var factory = new ContentTypeFactory(NodeObjectTypeId);
            var dto     = factory.BuildDto(entity);

            PersistNewBaseContentType(dto.ContentTypeDto, entity);
            //Inserts data into the cmsDocumentType table if a template exists
            if (dto.TemplateNodeId > 0)
            {
                dto.ContentTypeNodeId = entity.Id;
                Database.Insert(dto);
            }

            //Insert allowed Templates not including the default one, as that has already been inserted
            foreach (var template in entity.AllowedTemplates.Where(x => x != null && x.Id != dto.TemplateNodeId))
            {
                Database.Insert(new DocumentTypeDto
                {
                    ContentTypeNodeId = entity.Id, TemplateNodeId = template.Id, IsDefault = false
                });
            }

            ((ICanBeDirty)entity).ResetDirtyProperties();
        }
        private IEnumerable <IContentTypeComposition> GetAllTypesInternal()
        {
            var contentTypes = new Dictionary <int, IContentTypeComposition>();

            // get content types
            var sql1 = Sql()
                       .Select <ContentTypeDto>(r => r.Select(x => x.NodeDto))
                       .From <ContentTypeDto>()
                       .InnerJoin <NodeDto>().On <ContentTypeDto, NodeDto>((ct, n) => ct.NodeId == n.NodeId)
                       .OrderBy <ContentTypeDto>(x => x.NodeId);

            var contentTypeDtos = Database.Fetch <ContentTypeDto>(sql1);

            // get allowed content types
            var sql2 = Sql()
                       .Select <ContentTypeAllowedContentTypeDto>()
                       .From <ContentTypeAllowedContentTypeDto>()
                       .OrderBy <ContentTypeAllowedContentTypeDto>(x => x.Id);

            var allowedDtos = Database.Fetch <ContentTypeAllowedContentTypeDto>(sql2);

            // prepare
            // note: same alias could be used for media, content... but always different ids = ok
            var aliases = contentTypeDtos.ToDictionary(x => x.NodeId, x => x.Alias);

            // create
            var allowedDtoIx = 0;

            foreach (var contentTypeDto in contentTypeDtos)
            {
                // create content type
                IContentTypeComposition contentType;
                if (contentTypeDto.NodeDto.NodeObjectType == Constants.ObjectTypes.MediaType)
                {
                    contentType = ContentTypeFactory.BuildMediaTypeEntity(contentTypeDto);
                }
                else if (contentTypeDto.NodeDto.NodeObjectType == Constants.ObjectTypes.DocumentType)
                {
                    contentType = ContentTypeFactory.BuildContentTypeEntity(contentTypeDto);
                }
                else if (contentTypeDto.NodeDto.NodeObjectType == Constants.ObjectTypes.MemberType)
                {
                    contentType = ContentTypeFactory.BuildMemberTypeEntity(contentTypeDto);
                }
                else
                {
                    throw new PanicException($"The node object type {contentTypeDto.NodeDto.NodeObjectType} is not supported");
                }
                contentTypes.Add(contentType.Id, contentType);

                // map allowed content types
                var allowedContentTypes = new List <ContentTypeSort>();
                while (allowedDtoIx < allowedDtos.Count && allowedDtos[allowedDtoIx].Id == contentTypeDto.NodeId)
                {
                    var allowedDto = allowedDtos[allowedDtoIx];
                    if (!aliases.TryGetValue(allowedDto.AllowedId, out var alias))
                    {
                        continue;
                    }
                    allowedContentTypes.Add(new ContentTypeSort(new Lazy <int>(() => allowedDto.AllowedId), allowedDto.SortOrder, alias));
                    allowedDtoIx++;
                }
                contentType.AllowedContentTypes = allowedContentTypes;
            }

            MapTemplates(contentTypes);
            MapComposition(contentTypes);
            MapGroupsAndProperties(contentTypes);

            // finalize
            foreach (var contentType in contentTypes.Values)
            {
                contentType.ResetDirtyProperties(false);
            }

            return(contentTypes.Values);
        }