Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6960 Queries returning Draft Content Items and with more tokens available #6961

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,8 +18,8 @@ public interface IProjectionManager : IDependency {
LayoutDescriptor GetLayout(string category, string type);
PropertyDescriptor GetProperty(string category, string type);

IEnumerable<ContentItem> GetContentItems(int queryId, int skip = 0, int count = 0);
int GetCount(int queryId);
IEnumerable<ContentItem> GetContentItems(int queryId, int skip = 0, int count = 0, IDictionary<string, object> tokenData = null, VersionOptions versionOptions = null);
int GetCount(int queryId, IDictionary<string, object> tokenData = null);
}

}
Expand Up @@ -103,7 +103,7 @@ public class ProjectionManager : IProjectionManager{
.FirstOrDefault(x => x.Category == category && x.Type == type);
}

public int GetCount(int queryId) {
public int GetCount(int queryId, IDictionary<string, object> tokenData = null) {

var queryRecord = _queryRepository.Get(queryId);

Expand All @@ -113,11 +113,10 @@ public class ProjectionManager : IProjectionManager{

// aggregate the result for each group query

return GetContentQueries(queryRecord, Enumerable.Empty<SortCriterionRecord>())
return GetContentQueries(queryRecord, Enumerable.Empty<SortCriterionRecord>(), tokenData)
.Sum(contentQuery => contentQuery.Count());
}

public IEnumerable<ContentItem> GetContentItems(int queryId, int skip = 0, int count = 0) {
public IEnumerable<ContentItem> GetContentItems(int queryId, int skip = 0, int count = 0, IDictionary<string, object> tokenData = null, VersionOptions versionOptions = null) {
var availableSortCriteria = DescribeSortCriteria().ToList();

var queryRecord = _queryRepository.Get(queryId);
Expand All @@ -129,7 +128,7 @@ public class ProjectionManager : IProjectionManager{
var contentItems = new List<ContentItem>();

// aggregate the result for each group query
foreach(var contentQuery in GetContentQueries(queryRecord, queryRecord.SortCriteria.OrderBy(sc => sc.Position))) {
foreach(var contentQuery in GetContentQueries(queryRecord, queryRecord.SortCriteria.OrderBy(sc => sc.Position), tokenData, versionOptions)) {
contentItems.AddRange(contentQuery.Slice(skip, count));
}

Expand Down Expand Up @@ -172,19 +171,20 @@ public class ProjectionManager : IProjectionManager{

return groupQuery.Slice(skip, count);
}

public IEnumerable<IHqlQuery> GetContentQueries(QueryPartRecord queryRecord, IEnumerable<SortCriterionRecord> sortCriteria) {

public IEnumerable<IHqlQuery> GetContentQueries(QueryPartRecord queryRecord, IEnumerable<SortCriterionRecord> sortCriteria, IDictionary<string, object> tokenData, VersionOptions versionOptions = null) {
if (versionOptions == null) versionOptions = VersionOptions.Published;
var availableFilters = DescribeFilters().ToList();
var availableSortCriteria = DescribeSortCriteria().ToList();

// pre-executing all groups
foreach (var group in queryRecord.FilterGroups) {

var contentQuery = _contentManager.HqlQuery().ForVersion(VersionOptions.Published);
var contentQuery = _contentManager.HqlQuery().ForVersion(versionOptions);

// iterate over each filter to apply the alterations to the query object
foreach (var filter in group.Filters) {
var tokenizedState = _tokenizer.Replace(filter.State, new Dictionary<string, object>());
var tokenizedState = _tokenizer.Replace(filter.State, tokenData??new Dictionary<string, object>());
var filterContext = new FilterContext {
Query = contentQuery,
State = FormParametersHelper.ToDynamic(tokenizedState)
Expand Down