// Umbraco.Code.MapAll -Trashed -Alias -Score private static void Map(EntitySlim source, SearchResultEntity target, MapperContext context) { target.Icon = MapContentTypeIcon(source); target.Id = source.Id; target.Key = source.Key; target.Name = source.Name; target.ParentId = source.ParentId; target.Path = source.Path; target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key); if (target.Icon.IsNullOrWhiteSpace()) { if (source.NodeObjectType == Constants.ObjectTypes.Member) { target.Icon = Constants.Icons.Member; } else if (source.NodeObjectType == Constants.ObjectTypes.DataType) { target.Icon = Constants.Icons.DataType; } else if (source.NodeObjectType == Constants.ObjectTypes.DocumentType) { target.Icon = Constants.Icons.ContentType; } else if (source.NodeObjectType == Constants.ObjectTypes.MediaType) { target.Icon = Constants.Icons.MediaType; } else if (source.NodeObjectType == Constants.ObjectTypes.TemplateType) { target.Icon = Constants.Icons.Template; } } }
public void Ensure_Path_Throws_Without_Id() { var entity = new EntitySlim(); //no id assigned Assert.Throws <InvalidOperationException>(() => entity.EnsureValidPath(Mock.Of <ILogger>(), umbracoEntity => new EntitySlim(), umbracoEntity => { })); }
// Umbraco.Code.MapAll -Trashed -Alias -Score private static void Map(EntitySlim source, SearchResultEntity target, MapperContext context) { target.Icon = MapContentTypeIcon(source); target.Id = source.Id; target.Key = source.Key; target.Name = source.Name; target.ParentId = source.ParentId; target.Path = source.Path; target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key); if (target.Icon.IsNullOrWhiteSpace()) { if (source.NodeObjectType == Constants.ObjectTypes.Member) { target.Icon = "icon-user"; } else if (source.NodeObjectType == Constants.ObjectTypes.DataType) { target.Icon = "icon-autofill"; } else if (source.NodeObjectType == Constants.ObjectTypes.DocumentType) { target.Icon = "icon-item-arrangement"; } else if (source.NodeObjectType == Constants.ObjectTypes.MediaType) { target.Icon = "icon-thumbnails"; } else if (source.NodeObjectType == Constants.ObjectTypes.TemplateType) { target.Icon = "icon-newspaper-alt"; } } }
//fixme - see https://github.com/umbraco/Umbraco-CMS/pull/3460#issuecomment-434903930 we need to not load any property data at all for media private void BuildProperty(EntitySlim entity, PropertyDataDto pdto) { // explain ?! var value = string.IsNullOrWhiteSpace(pdto.TextValue) ? pdto.VarcharValue : pdto.TextValue.ConvertToJsonIfPossible(); entity.AdditionalData[pdto.PropertyTypeDto.Alias] = new EntitySlim.PropertySlim(pdto.PropertyTypeDto.DataTypeDto.EditorAlias, value); }
//fixme - see https://github.com/umbraco/Umbraco-CMS/pull/3460#issuecomment-434903930 we need to not load any property data at all for media private void BuildProperties(EntitySlim entity, BaseDto dto) { var pdtos = Database.Fetch <PropertyDataDto>(GetPropertyData(dto.VersionId)); foreach (var pdto in pdtos) { BuildProperty(entity, pdto); } }
public void Ensure_Path_Throws_Without_Id() { EntitySlim entity = _builder .WithoutIdentity() .Build(); // no id assigned Assert.Throws <InvalidOperationException>(() => entity.EnsureValidPath(Mock.Of <ILogger <EntitySlim> >(), umbracoEntity => new EntitySlim(), umbracoEntity => { })); }
public void Ensure_Path_Throws_Without_Parent() { var entity = new EntitySlim { Id = 1234 }; //no parent found Assert.Throws <NullReferenceException>(() => entity.EnsureValidPath(Mock.Of <ILogger>(), umbracoEntity => null, umbracoEntity => { })); }
public void Ensure_Path_Throws_Without_Parent() { EntitySlim entity = _builder .WithId(1234) .WithNoParentId() .Build(); // no parent found Assert.Throws <NullReferenceException>(() => entity.EnsureValidPath(Mock.Of <ILogger <EntitySlim> >(), umbracoEntity => null, umbracoEntity => { })); }
public void Ensure_Path_Entity_Valid_Recursive_Parent() { var parentA = new EntitySlim { Id = 999, ParentId = -1 }; var parentB = new EntitySlim { Id = 888, ParentId = 999 }; var parentC = new EntitySlim { Id = 777, ParentId = 888 }; var entity = new EntitySlim { Id = 1234, ParentId = 777 }; Func <IUmbracoEntity, IUmbracoEntity> getParent = umbracoEntity => { switch (umbracoEntity.ParentId) { case 999: return(parentA); case 888: return(parentB); case 777: return(parentC); case 1234: return(entity); default: return(null); } }; //this will recursively fix all paths entity.EnsureValidPath(Mock.Of <ILogger>(), getParent, umbracoEntity => { }); Assert.AreEqual("-1,999", parentA.Path); Assert.AreEqual("-1,999,888", parentB.Path); Assert.AreEqual("-1,999,888,777", parentC.Path); Assert.AreEqual("-1,999,888,777,1234", entity.Path); }
public void Ensure_Path_Entity_Valid_Recursive_Parent() { EntitySlim parentA = _builder .WithId(999) .Build(); // Re-creating the class-level builder as we need to reset before usage when creating multiple entities. _builder = new EntitySlimBuilder(); EntitySlim parentB = _builder .WithId(888) .WithParentId(999) .Build(); _builder = new EntitySlimBuilder(); EntitySlim parentC = _builder .WithId(777) .WithParentId(888) .Build(); _builder = new EntitySlimBuilder(); EntitySlim entity = _builder .WithId(1234) .WithParentId(777) .Build(); IUmbracoEntity GetParent(IUmbracoEntity umbracoEntity) { switch (umbracoEntity.ParentId) { case 999: return(parentA); case 888: return(parentB); case 777: return(parentC); case 1234: return(entity); default: return(null); } } // this will recursively fix all paths entity.EnsureValidPath(Mock.Of <ILogger <IUmbracoEntity> >(), GetParent, umbracoEntity => { }); Assert.AreEqual("-1,999", parentA.Path); Assert.AreEqual("-1,999,888", parentB.Path); Assert.AreEqual("-1,999,888,777", parentC.Path); Assert.AreEqual("-1,999,888,777,1234", entity.Path); }
public void Ensure_Path_Entity_At_Root() { EntitySlim entity = _builder .WithId(1234) .Build(); entity.EnsureValidPath(Mock.Of <ILogger <EntitySlim> >(), umbracoEntity => null, umbracoEntity => { }); // works because it's under the root Assert.AreEqual("-1,1234", entity.Path); }
public void Ensure_Path_Entity_Valid_Parent() { EntitySlim entity = _builder .WithId(1234) .WithParentId(888) .Build(); entity.EnsureValidPath(Mock.Of <ILogger <EntitySlim> >(), umbracoEntity => umbracoEntity.ParentId == 888 ? new EntitySlim { Id = 888, Path = "-1,888" } : null, umbracoEntity => { }); // works because the parent was found Assert.AreEqual("-1,888,1234", entity.Path); }
public void Ensure_Path_Entity_At_Root() { var entity = new EntitySlim { Id = 1234, ParentId = -1 }; entity.EnsureValidPath(Mock.Of <ILogger>(), umbracoEntity => null, umbracoEntity => { }); //works because it's under the root Assert.AreEqual("-1,1234", entity.Path); }
// Umbraco.Code.MapAll -Trashed -Alias -AssignedPermissions private static void Map(EntitySlim source, AssignedContentPermissions target, MapperContext context) { target.Icon = MapContentTypeIcon(source); target.Id = source.Id; target.Key = source.Key; target.Name = source.Name; target.ParentId = source.ParentId; target.Path = source.Path; target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key); if (source.NodeObjectType == Constants.ObjectTypes.Member && target.Icon.IsNullOrWhiteSpace()) { target.Icon = "icon-user"; } }
public void Ensure_Path_Entity_Valid_Parent() { var entity = new EntitySlim { Id = 1234, ParentId = 888 }; entity.EnsureValidPath(Mock.Of <ILogger>(), umbracoEntity => umbracoEntity.ParentId == 888 ? new EntitySlim { Id = 888, Path = "-1,888" } : null, umbracoEntity => { }); //works because the parent was found Assert.AreEqual("-1,888,1234", entity.Path); }
private static void BuildEntity(EntitySlim entity, BaseDto dto) { entity.Trashed = dto.Trashed; entity.CreateDate = dto.CreateDate; entity.CreatorId = dto.UserId ?? Constants.Security.UnknownUserId; entity.Id = dto.NodeId; entity.Key = dto.UniqueId; entity.Level = dto.Level; entity.Name = dto.Text; entity.NodeObjectType = dto.NodeObjectType; entity.ParentId = dto.ParentId; entity.Path = dto.Path; entity.SortOrder = dto.SortOrder; entity.HasChildren = dto.Children > 0; entity.IsContainer = dto.IsContainer; }
private EntitySlim BuildEntity(bool isContent, bool isMedia, BaseDto dto) { if (isContent) { return(BuildDocumentEntity(dto)); } if (isMedia) { return(BuildMediaEntity(dto)); } // EntitySlim does not track changes var entity = new EntitySlim(); BuildEntity(entity, dto); return(entity); }
private EntitySlim BuildEntity(BaseDto dto) { if (dto.NodeObjectType == Constants.ObjectTypes.Document) { return(BuildDocumentEntity(dto)); } if (dto.NodeObjectType == Constants.ObjectTypes.Media) { return(BuildMediaEntity(dto)); } if (dto.NodeObjectType == Constants.ObjectTypes.Member) { return(BuildMemberEntity(dto)); } // EntitySlim does not track changes var entity = new EntitySlim(); BuildEntity(entity, dto); return(entity); }
/// <summary> /// Returns the menu structure for the node /// </summary> /// <param name="id"></param> /// <param name="queryStrings"></param> /// <returns></returns> protected override ActionResult <MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings) { MenuItemCollection menu = _menuItemCollectionFactory.Create(); //Create the normal create action MenuItem?item = menu.Items.Add <ActionNew>(LocalizedTextService, opensDialog: true, useLegacyIcon: false); item?.NavigateToRoute( $"{queryStrings.GetRequiredValue<string>("application")}/templates/edit/{id}?create=true"); if (id == Constants.System.RootString) { //refresh action menu.Items.Add(new RefreshNode(LocalizedTextService, separatorBefore: true)); return(menu); } ITemplate?template = _fileService.GetTemplate(int.Parse(id, CultureInfo.InvariantCulture)); if (template == null) { return(menu); } EntitySlim entity = FromTemplate(template); //don't allow delete if it has child layouts if (template.IsMasterTemplate == false) { //add delete option if it doesn't have children menu.Items.Add <ActionDelete>(LocalizedTextService, hasSeparator: true, opensDialog: true); } //add refresh menu.Items.Add(new RefreshNode(LocalizedTextService, separatorBefore: true)); return(menu); }
public void Validate_Path() { var entity = new EntitySlim(); //it's empty with no id so we need to allow it Assert.IsTrue(entity.ValidatePath()); entity.Id = 1234; //it has an id but no path, so we can't allow it Assert.IsFalse(entity.ValidatePath()); entity.Path = "-1"; //invalid path Assert.IsFalse(entity.ValidatePath()); entity.Path = string.Concat("-1,", entity.Id); //valid path Assert.IsTrue(entity.ValidatePath()); }
private IEntitySlim?GetEntity(Sql <ISqlContext> sql, bool isContent, bool isMedia, bool isMember) { // isContent is going to return a 1:M result now with the variants so we need to do different things if (isContent) { List <DocumentEntityDto>?cdtos = Database.Fetch <DocumentEntityDto>(sql); return(cdtos.Count == 0 ? null : BuildVariants(BuildDocumentEntity(cdtos[0]))); } BaseDto?dto = isMedia ? Database.FirstOrDefault <MediaEntityDto>(sql) : Database.FirstOrDefault <BaseDto>(sql); if (dto == null) { return(null); } EntitySlim entity = BuildEntity(dto); return(entity); }
private static string GetContentTypeIcon(EntitySlim entity) => entity is ContentEntitySlim contentEntity ? contentEntity.ContentTypeIcon : null;