private static object[] GetChildrenByNodeInternal(Node node, bool includeLeafNodes, string contentTypes, bool simpleContent = false) { var folderParent = node as IFolder; if (folderParent == null) { return(null); } var content = SenseNet.ContentRepository.Content.Create(node); var filter = GetContentTypesFilter(contentTypes); // add content type filter if needed if (!string.IsNullOrEmpty(filter)) { content.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(content.ChildrenDefinition.ContentQuery, filter, LogicalOperator.And); } // in case of SmartFolder: do not override the settings given on the content if (!(folderParent is SmartFolder)) { content.ChildrenDefinition.EnableAutofilters = FilterStatus.Disabled; } var children = content.Children.AsEnumerable().Where(c => c != null).Select(c => c.ContentHandler); if (!includeLeafNodes) { children = children.Where(c => c is IFolder).ToList(); } return(children.Where(c => c != null).Select(child => new cs.SimpleServiceContent(child)).ToArray()); }
internal void WriteChildrenCollection(String path, PortalContext portalContext, ODataRequest req) { var content = Content.Load(path); var chdef = content.ChildrenDefinition; if (req.HasContentQuery) { chdef.ContentQuery = ContentQuery.AddClause(req.ContentQueryText, String.Concat("InTree:'", path, "'"), ContentRepository.Storage.Search.ChainOperator.And); if (req.AutofiltersEnabled != FilterStatus.Default) { chdef.EnableAutofilters = req.AutofiltersEnabled; } if (req.LifespanFilterEnabled != FilterStatus.Default) { chdef.EnableLifespanFilter = req.LifespanFilterEnabled; } if (req.QueryExecutionMode != QueryExecutionMode.Default) { chdef.QueryExecutionMode = req.QueryExecutionMode; } if (req.Top > 0) { chdef.Top = req.Top; } if (req.Skip > 0) { chdef.Skip = req.Skip; } if (req.Sort.Any()) { chdef.Sort = req.Sort; } } else { chdef.EnableAutofilters = FilterStatus.Disabled; if (string.IsNullOrEmpty(chdef.ContentQuery)) { chdef.ContentQuery = ContentQuery.AddClause(chdef.ContentQuery, String.Concat("InFolder:'", path, "'"), ContentRepository.Storage.Search.ChainOperator.And); } } int count; var contents = ProcessOperationQueryResponse(chdef, portalContext, req, out count); if (req.CountOnly) { WriteCount(portalContext, count); } else { WriteMultipleContent(portalContext, contents, count); } }
internal async Task WriteChildrenCollectionAsync(String path, HttpContext httpContext, ODataRequest req) { var content = Content.Load(path); var chdef = content.ChildrenDefinition; if (req.HasContentQuery) { chdef.ContentQuery = ContentQuery.AddClause(req.ContentQueryText, String.Concat("InTree:'", path, "'"), LogicalOperator.And); if (req.AutofiltersEnabled != FilterStatus.Default) { chdef.EnableAutofilters = req.AutofiltersEnabled; } if (req.LifespanFilterEnabled != FilterStatus.Default) { chdef.EnableLifespanFilter = req.LifespanFilterEnabled; } if (req.QueryExecutionMode != QueryExecutionMode.Default) { chdef.QueryExecutionMode = req.QueryExecutionMode; } if (req.Top > 0) { chdef.Top = req.Top; } if (req.Skip > 0) { chdef.Skip = req.Skip; } if (req.Sort.Any()) { chdef.Sort = req.Sort; } } else { chdef.EnableAutofilters = FilterStatus.Disabled; if (string.IsNullOrEmpty(chdef.ContentQuery)) { chdef.ContentQuery = ContentQuery.AddClause(chdef.ContentQuery, String.Concat("InFolder:'", path, "'"), LogicalOperator.And); } } var contents = ProcessOperationQueryResponse(chdef, req, httpContext, out var count); if (req.CountOnly) { await WriteCountAsync(httpContext, count).ConfigureAwait(false); } else { await WriteMultipleContentAsync(httpContext, contents, count).ConfigureAwait(false); } }
protected override object GetModel() { var sf = Node.Load <SmartFolder>("/Root/System/RuntimeQuery"); if (sf == null) { using (new SystemAccount()) { var systemFolder = Node.LoadNode("/root/system"); sf = new SmartFolder(systemFolder) { Name = "RuntimeQuery" }; sf.Save(); } } var model = Content.Create(sf); if (!this.AllowEmptySearch && SearchTextIsTooGeneric(this.QueryString)) { this.ErrorMessage = "Please give a more specific search text"; return(model); } sf.Query = ReplaceTemplates(this.QueryString); var baseModel = base.GetModel() as Content; if (baseModel != null) { model.ChildrenQueryFilter = baseModel.ChildrenQueryFilter; model.ChildrenQuerySettings = baseModel.ChildrenQuerySettings; if (FilterByContext) { var ctx = GetContextNode(); if (ctx != null) { //add filter: we search only under the current context var excapedPath = ctx.Path.Replace("(", "\\(").Replace(")", "\\)"); sf.Query = ContentQuery.AddClause(sf.Query, string.Format("InTree:\"{0}\"", excapedPath), ChainOperator.And); } } } ResultModel = model; return(model); }
private IEnumerable <Content> GetChildren() { //update children definition if needed if (this.Settings != null) { if (this.Settings.Top > 0) { this.Content.ChildrenDefinition.Top = this.Settings.Top; } if (this.Settings.Skip > 0) { this.Content.ChildrenDefinition.Skip = this.Settings.Skip; } if (this.Settings.Sort != null && this.Settings.Sort.Any()) { this.Content.ChildrenDefinition.Sort = this.Settings.Sort; } if (this.Settings.EnableAutofilters != FilterStatus.Default) { this.Content.ChildrenDefinition.EnableAutofilters = this.Settings.EnableAutofilters; } if (this.Settings.EnableLifespanFilter != FilterStatus.Default) { this.Content.ChildrenDefinition.EnableLifespanFilter = this.Settings.EnableLifespanFilter; } } this.Content.ChildrenDefinition.AllChildren = this.FlattenResults; //must exclude the current content from the results (in case of an InTree query) this.Content.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(this.Content.ChildrenDefinition.ContentQuery, string.Format("-Id:{0}", this.Content.Id), ChainOperator.And); var children = this.Content.Children.AsEnumerable().Where(c => c != null).ToList(); //set descriptor collection to each content var propDesc = Content.GetPropertyDescriptors(GetFieldNames()); foreach (var content in children) { content.PropertyDescriptors = propDesc; } OnSelected(new SenseNetDataSourceStatusEventArgs(children.Count)); return(children); }
protected override object GetModel() { var sf = SmartFolder.GetRuntimeQueryFolder(); var model = Content.Create(sf); if (!this.AllowEmptySearch && SearchTextIsTooGeneric(this.QueryString)) { if (HttpContext.Current.Request.Params.AllKeys.Contains(QueryParameterName)) { this.ErrorMessage = SNSR.GetString(ContextSearchClass, "Error_GenericSearchExpression"); } return(model); } sf.Query = ReplaceTemplates(this.QueryString); var baseModel = base.GetModel() as Content; if (baseModel != null) { model.ChildrenDefinition = baseModel.ChildrenDefinition; model.ChildrenDefinition.PathUsage = PathUsageMode.NotUsed; if (FilterByContext) { var ctx = GetContextNode(); if (ctx != null) { //add filter: we search only under the current context var escapedPath = ctx.Path.Replace("(", "\\(").Replace(")", "\\)"); model.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(model.ChildrenDefinition.ContentQuery, ContentQuery.AddClause(sf.Query, string.Format("InTree:\"{0}\"", escapedPath), ChainOperator.And), ChainOperator.And); } } else { if (!string.IsNullOrEmpty(sf.Query)) { model.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(model.ChildrenDefinition.ContentQuery, sf.Query, ChainOperator.And); } } } ResultModel = model; return(model); }
/// <summary> /// Gets the groups. /// </summary> /// <returns>List of group nodes.</returns> private List <Node> GetGroups() { var groups = new List <Node>(); if (!String.IsNullOrEmpty(GroupQuery)) { var sort = new[] { new SortInfo("Name") }; var settings = new QuerySettings { EnableAutofilters = FilterStatus.Disabled, EnableLifespanFilter = FilterStatus.Disabled, Sort = sort }; var query = new ContentQuery { Text = GroupQuery, Settings = settings }; query.AddClause(string.Format("-Path:({0})", string.Join(" ", Identifiers.SpecialGroupPaths))); var results = query.Execute(); groups.AddRange(results.Nodes); } return(groups); }
/// <summary> /// Gets the groups. /// </summary> /// <returns>List of group nodes.</returns> private List <Node> GetGroups() { var groups = new List <Node>(); if (!String.IsNullOrEmpty(GroupQuery)) { var sort = new[] { new SortInfo { FieldName = "Name" } }; var settings = new QuerySettings { EnableAutofilters = false, EnableLifespanFilter = false, Sort = sort }; var query = new ContentQuery { Text = GroupQuery, Settings = settings }; query.AddClause(string.Format("-Name:({0})", string.Join(" ", RepositoryConfiguration.SpecialGroupNames))); var results = query.Execute(); groups.AddRange(results.Nodes); } return(groups); }
internal void WriteChildrenCollection(String path, PortalContext portalContext, ODataRequest req) { var content = Content.Load(path); var chdef = content.ChildrenDefinition; if (string.IsNullOrEmpty(chdef.ContentQuery)) { chdef.ContentQuery = ContentQuery.AddClause(chdef.ContentQuery, String.Concat("InFolder:'", path, "'"), ContentRepository.Storage.Search.ChainOperator.And); } chdef.EnableAutofilters = FilterStatus.Disabled; int count; var contents = ProcessOperationQueryResponse(chdef, portalContext, req, out count); if (req.CountOnly) { WriteCount(portalContext, count); } else { WriteMultipleContent(portalContext, contents, count); } }
public void ContentQuery_AddAndClause() { void AndTest(string @base, string add, string expected) { var result = ContentQuery.AddClause( @base, add, LogicalOperator.And) .Replace(" ", ""); Assert.AreEqual(expected.Replace(" ", ""), result); } Test(() => { AndTest("+Id:1 +Id:2 .AUTOFILTERS:OFF", "+Id:3", "+(+Id:1 +Id:2) +(+Id:3) .AUTOFILTERS:OFF"); AndTest("+Id:1 +Id:2", "+Id:3 .AUTOFILTERS:OFF", "+(+Id:1 +Id:2) +(+Id:3) .AUTOFILTERS:OFF"); AndTest("+Id:1 +Id:2 .TOP:3 .SKIP:5", "+Id:3", "+(+Id:1 +Id:2) +(+Id:3) .TOP:3 .SKIP:5"); AndTest("+Id:1 +Id:2 .TOP:3", "+Id:3 .QUICK", "+(+Id:1 +Id:2) +(+Id:3) .TOP:3 .QUICK"); AndTest("+Id:1 .COUNTONLY", "+Id:2 .ALLVERSIONS", "+(+Id:1) +(+Id:2) .COUNTONLY .ALLVERSIONS"); AndTest("+Id:1 .SELECT:Name", "+Id:2", "+(+Id:1) +(+Id:2) .SELECT:Name"); AndTest("+Id:1 .SORT:Name", "+Id:2", "+(+Id:1) +(+Id:2) .SORT:Name"); AndTest("+Id:1 .REVERSESORT:Name", "+Id:2", "+(+Id:1) +(+Id:2) .REVERSESORT:Name"); AndTest("+Id:1 .LIFESPAN:OFF", "+Id:2", "+(+Id:1) +(+Id:2) .LIFESPAN:OFF"); }); }
public void ContentQuery_AddOrClause() { void OrTest(string @base, string add, string expected) { var result = ContentQuery.AddClause( @base, add, LogicalOperator.Or) .Replace(" ", ""); Assert.AreEqual(expected.Replace(" ", ""), result); } Test(() => { OrTest("Id:1 Id:2 .AUTOFILTERS:OFF", "Id:3", "(Id:1 Id:2) Id:3 .AUTOFILTERS:OFF"); OrTest("Id:1 Id:2", "Id:3 .AUTOFILTERS:OFF", "(Id:1 Id:2) Id:3 .AUTOFILTERS:OFF"); OrTest("Id:1 Id:2 .TOP:3 .SKIP:5", "Id:3", "(Id:1 Id:2) Id:3 .TOP:3 .SKIP:5"); OrTest("Id:1 Id:2 .TOP:3", "Id:3 .QUICK", "(Id:1 Id:2) Id:3 .QUICK .TOP:3"); OrTest("Id:1 .COUNTONLY", "Id:2 .ALLVERSIONS", "(Id:1) Id:2 .ALLVERSIONS .COUNTONLY"); OrTest("Id:1 .SELECT:Name", "Id:2", "(Id:1) Id:2 .SELECT:Name"); OrTest("Id:1 .SORT:Name", "Id:2", "(Id:1) Id:2 .SORT:Name"); OrTest("Id:1 .REVERSESORT:Name", "Id:2", "(Id:1) Id:2 .REVERSESORT:Name"); OrTest("Id:1 .LIFESPAN:OFF", "Id:2", "(Id:1) Id:2 .LIFESPAN:OFF"); }); }
internal void WriteQueryResult(PortalContext portalContext, OData.ODataRequest req) { var settings = new QuerySettings { Top = req.Top, Skip = req.Skip, Sort = req.Sort }; var contentQuery = new ContentQuery { Settings = settings, Text = req.ContentQueryText }; if (req.RepositoryPath != Repository.RootPath) { contentQuery.AddClause("InTree:\"" + req.RepositoryPath + "\""); } var result = contentQuery.Execute(); var contents = new List <Dictionary <string, object> >(); var projector = Projector.Create(req, true); foreach (var node in result.Nodes) { var content = Content.Create(node); var fields = CreateFieldDictionary(content, portalContext, projector); contents.Add(fields); } var count = req.InlineCount == InlineCount.AllPages ? result.Count : contents.Count; if (req.CountOnly) { WriteCount(portalContext, count); } else { WriteMultipleContent(portalContext, contents, count); } }
private ActionResult GetChildrenByNodeInternal(Node node, bool includeLeafNodes, string contentTypes, bool simpleContent = false) { var folderParent = node as IFolder; if (folderParent == null) { return(null); } var content = ContentRepository.Content.Create(node); var filter = GetContentTypesFilter(contentTypes); //add content type filter if needed if (!string.IsNullOrEmpty(filter)) { content.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(content.ChildrenDefinition.ContentQuery, filter, ChainOperator.And); } //in case of SmartFolder: do not override the settings given on the content if (!(folderParent is SmartFolder)) { content.ChildrenDefinition.EnableAutofilters = FilterStatus.Disabled; } var children = content.Children.AsEnumerable().Where(c => c != null).Select(c => c.ContentHandler); if (!includeLeafNodes) { children = children.Where(c => c is IFolder).ToList(); } //return simpleContent // ? Json(children.Where(c => c != null).Select(child => new SimpleServiceContent(child)).ToArray(), JsonRequestBehavior.AllowGet) // : Json(children.Where(c => c != null).Select(child => new Content(child, true, false, false, false, 0, 0)).ToArray(), JsonRequestBehavior.AllowGet); return(Json(children.Where(c => c != null).Select(child => new SimpleServiceContent(child)).ToArray(), JsonRequestBehavior.AllowGet)); }
protected override object GetModel() { if (ContextNode == null) { return(null); } var content = Content.Create(ContextNode); var cdef = content.ChildrenDefinition; if (EnableAutofilters != FilterStatus.Default) { cdef.EnableAutofilters = EnableAutofilters; } if (EnableLifespanFilter != FilterStatus.Default) { cdef.EnableLifespanFilter = EnableLifespanFilter; } if (Top > 0) { cdef.Top = Top; } if (State.Skip > 0) { cdef.Skip = State.Skip; } if (!string.IsNullOrEmpty(State.SortColumn)) { cdef.Sort = new[] { new SortInfo { FieldName = State.SortColumn, Reverse = State.SortDescending } } } ; var filter = GetQueryFilter(); if (!string.IsNullOrEmpty(content.ChildrenDefinition.ContentQuery)) { // combine the two queries (e.g. in case of a Smart Folder or a container with a custom children query) if (!string.IsNullOrEmpty(filter)) { content.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(content.ChildrenDefinition.ContentQuery, filter, ChainOperator.And); } } else { content.ChildrenDefinition.ContentQuery = filter; } content.XmlWriterExtender = writer => { }; switch (CollectionAxis) { case CollectionAxisMode.Children: return(content); case CollectionAxisMode.VersionHistory: var versionRoot = SearchFolder.Create(content.Versions); return(versionRoot); case CollectionAxisMode.ReferenceProperty: return(content); case CollectionAxisMode.External: return(SearchFolder.Create(RequestNodeList)); } return(null); }
private IEnumerable <ISecurityContainer> GetAdminGroups() { var ag = new List <ISecurityContainer>(); if (string.IsNullOrEmpty(this.Groups)) { return(ag); } var ags = this.Groups.Split(new [] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries); using (new SystemAccount()) { foreach (var agName in ags) { try { if (agName.StartsWith("/Root/")) { var group = Node.LoadNode(agName) as ISecurityContainer; if (group != null) { ag.Add(group); } } else { ContentQuery cq = null; const string queryText = "+TypeIs:(Group OrganizationalUnit) +Name:{0}"; var nameParts = agName.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); switch (nameParts.Length) { case 0: break; case 1: //load group or OU only by name cq = ContentQuery.CreateQuery(string.Format(queryText, nameParts[0])); break; default: //load group or OU by domain and name var domain = ContentQuery.Query("+TypeIs:Domain +Name:" + nameParts[0]).Nodes.FirstOrDefault(); if (domain != null) { cq = ContentQuery.CreateQuery(string.Format(queryText, nameParts[1])); cq.AddClause("InTree:\"" + domain.Path + "\""); } break; } if (cq != null) { ag.AddRange(cq.Execute().Nodes.Cast <ISecurityContainer>()); } } } catch (Exception ex) { Logger.WriteException(ex); } } } return(ag); }