/// <summary> /// Performs the query by PublicContentApi client based on the given filters /// </summary> private ItemConnection ExecuteItemQuery(IEnumerable <InputItemFilter> keywordfilters, InputItemFilter languageFilter, int maxItems) { var customMetaFilters = keywordfilters.ToList(); customMetaFilters.Add(languageFilter); InputItemFilter filter = new InputItemFilter { NamespaceIds = new List <ContentNamespace> { ContentNamespace.Docs }, ItemTypes = new List <FilterItemType> { FilterItemType.PAGE }, And = customMetaFilters }; var results = _publicContentApi.ExecuteItemQuery( filter, new InputSortParam { Order = SortOrderType.Ascending, SortBy = SortFieldType.TITLE }, new Pagination { First = maxItems }, null, ContentIncludeMode.IncludeJsonAndRender, includeContainerItems: false, contextData: null ); return(results); }
public ItemConnection ExecuteItemQuery(InputItemFilter filter, InputSortParam sort, IPagination pagination, string customMetaFilter, ContentIncludeMode contentIncludeMode, bool includeContainerItems, IContextData contextData) => _client.Execute <ContentQuery>(GraphQLRequests.ExecuteItemQuery(filter, sort, pagination, customMetaFilter, contentIncludeMode, includeContainerItems, contextData, GlobalContextDataInternal)).TypedResponseData.Items;
public static IGraphQLRequest ExecuteItemQuery(InputItemFilter filter, InputSortParam sort, IPagination pagination, string customMetaFilter, ContentIncludeMode contentIncludeMode, bool includeContainerItems, IContextData contextData, IContextData globaContextData) { QueryBuilder builder = new QueryBuilder().WithQueryResource("ItemQuery", false); // We only include the fragments that will be required based on the item types in the // input item filter if (filter.ItemTypes != null) { string fragmentList = filter.ItemTypes.Select(itemType => $"{Enum.GetName(typeof (ContentModel.FilterItemType), itemType).Capitialize()}Fields") .Aggregate(string.Empty, (current, fragment) => current + $"...{fragment}\n"); // Just a quick and easy way to replace markers in our queries with vars here. builder.ReplaceTag("fragmentList", fragmentList); builder.LoadFragments(); } return(builder.WithIncludeRegion("includeContainerItems", includeContainerItems). WithPagination(pagination). WithCustomMetaFilter(customMetaFilter). WithContentIncludeMode(contentIncludeMode). WithInputItemFilter(filter). WithInputSortParam(sort). WithContextData(contextData). WithContextData(globaContextData). WithConvertor(new ItemConvertor()). Build()); }
public IEnumerable <IItem> ExecuteQueryItems(SimpleBrokerQuery queryParams) { InputItemFilter filter = BuildFilter(queryParams); InputSortParam sort = BuildSort(queryParams); var client = ApiClientFactory.Instance.CreateClient(); int pageSize = queryParams.PageSize > 0 ? queryParams.PageSize + 1 : queryParams.PageSize; var results = client.ExecuteItemQuery(filter, sort, new Pagination { First = pageSize, After = queryParams.Cursor }, null, ContentIncludeMode.Exclude, false, null); var resultList = results.Edges.Select(edge => edge.Node).ToList(); if (pageSize == -1) { // returning all items with pageSize = -1 Cursor = null; return(resultList); } HasMore = results.Edges.Count > queryParams.PageSize; int n = HasMore ? queryParams.PageSize : results.Edges.Count; Cursor = n > 0 ? results.Edges[n - 1].Cursor : null; return(HasMore ? resultList.GetRange(0, queryParams.PageSize) : resultList); }
/// <summary> /// Creates the required filters and peforms the query to fetch and return the results /// </summary> private List <ItemEdge> ExecuteQuery(Dictionary <string, KeywordModel> keywords, int maxItems) { if (maxItems < 1) { return(null); } List <InputItemFilter> keywordFilters = GetKeyWordFilters(keywords); // First , we filter the query based on the specified language in the current culture. InputItemFilter languageFilter = GetLanguageFilter(WebRequestContext.Localization.CultureInfo.Name); ItemConnection results = ExecuteItemQuery(keywordFilters, languageFilter, maxItems); // If no result, then we do another query based on the parent language (if exists). if (results?.Edges == null || !results.Edges.Any()) { var parentLanguage = WebRequestContext.Localization.CultureInfo.Parent?.Name; if (!string.IsNullOrEmpty(parentLanguage)) { languageFilter = GetLanguageFilter(parentLanguage); results = ExecuteItemQuery(keywordFilters, languageFilter, maxItems); } } return(results?.Edges); }
public async Task <ItemConnection> ExecuteItemQueryAsync(InputItemFilter filter, InputSortParam sort, IPagination pagination, string customMetaFilter, ContentIncludeMode contentIncludeMode, bool includeContainerItems, IContextData contextData, CancellationToken cancellationToken = default(CancellationToken)) => ( await _client.ExecuteAsync <ContentQuery>( GraphQLRequests.ExecuteItemQuery(filter, sort, pagination, customMetaFilter, contentIncludeMode, includeContainerItems, contextData, GlobalContextDataInternal) , cancellationToken).ConfigureAwait(false)).TypedResponseData.Items;
/// <summary> /// Creates and returns an <see cref="InputItemFilter"/> based on the given language /// </summary> private static InputItemFilter GetLanguageFilter(string language) { var languageFilter = new InputItemFilter { CustomMeta = new InputCustomMetaCriteria { Key = "DOC-LANGUAGE.lng.value", Value = language, Scope = CriteriaScope.Publication } }; return(languageFilter); }
public Item GetPageIdByIshLogicalReference(int publicationId, string ishLogicalRefValue) { try { Item item = new Item(); var client = ApiClientFactory.Instance.CreateClient(); InputItemFilter filter = new InputItemFilter { NamespaceIds = new List <ContentNamespace> { ContentNamespace.Docs }, PublicationIds = new List <int?> { publicationId }, ItemTypes = new List <FilterItemType> { FilterItemType.PAGE }, CustomMeta = new InputCustomMetaCriteria { Key = RefFieldName, Value = ishLogicalRefValue, ValueType = CustomMetaValueType.STRING, Scope = CriteriaScope.ItemInPublication } }; var items = client.ExecuteItemQuery(filter, new InputSortParam { Order = SortOrderType.Ascending, SortBy = SortFieldType.CREATION_DATE }, new Pagination { First = 1 }, null, ContentIncludeMode.Exclude, false, null); if (items?.Edges == null || items.Edges.Count != 1) { return(item); } item.Id = items.Edges[0].Node.ItemId; item.PublicationId = items.Edges[0].Node.PublicationId; item.Title = items.Edges[0].Node.Title; return(item); } catch (Exception) { throw new DxaItemNotFoundException( $"Page reference by ishlogicalref.object.id = {ishLogicalRefValue} not found in publication {publicationId}."); } }
public void ItemQuery1_Success() { var client = CreateClient(LoadResource("ItemQuery1_Success")); var filter = new InputItemFilter { NamespaceIds = new List <ContentNamespace> { ContentNamespace.Docs }, ItemTypes = new List <ContentModel.FilterItemType> { ContentModel.FilterItemType.PAGE } }; IContextData contextData = new ContextData(); contextData.ClaimValues.Add(new ClaimValue { Uri = ClaimUris.ModelType, Type = ClaimValueType.STRING, Value = Enum.GetName(typeof(ContentType), ContentType.RAW) }); contextData.ClaimValues.Add(new ClaimValue { Uri = ClaimUris.ModelType, Type = ClaimValueType.STRING, Value = Enum.GetName(typeof(DataModelType), DataModelType.R2) }); contextData.ClaimValues.Add(new ClaimValue { Uri = ClaimUris.PageIncludeRegions, Type = ClaimValueType.STRING, Value = Enum.GetName(typeof(PageInclusion), PageInclusion.INCLUDE) }); ItemConnection query = client.ExecuteItemQuery(filter, null, new Pagination { First = 10 }, null, ContentIncludeMode.Exclude, false, null); Assert.AreEqual(query.Edges.Count, 10); }
/// <summary> /// Creates and returns a collection of <see cref="InputItemFilter"/> based on the given keyword models /// </summary> private static List <InputItemFilter> GetKeyWordFilters(Dictionary <string, KeywordModel> keywords) { var keyWordFilters = new List <InputItemFilter>(); foreach (var keyword in keywords) { var keywordFilter = new InputItemFilter { CustomMeta = new InputCustomMetaCriteria { Key = GetKeywordKey(keyword.Key), Value = keyword.Value.Id, Scope = GetKeywordScope(keyword.Key) } }; keyWordFilters.Add(keywordFilter); } return(keyWordFilters); }
public IEnumerable <string> ExecuteQuery(SimpleBrokerQuery queryParams) { InputItemFilter filter = BuildFilter(queryParams); InputSortParam sort = BuildSort(queryParams); var client = ApiClientFactory.Instance.CreateClient(); var results = client.ExecuteItemQuery(filter, sort, new Pagination { First = queryParams.PageSize + 1, After = queryParams.Cursor }, null, ContentIncludeMode.Exclude, false, null); HasMore = results.Edges.Count > queryParams.PageSize; int n = HasMore ? queryParams.PageSize : results.Edges.Count; var resultList = new List <string>(); for (int i = 0; i < n; i++) { resultList.Add(results.Edges[i].Node.CmUri()); } Cursor = n > 0 ? results.Edges[n - 1].Cursor : null; return(resultList); }
protected InputItemFilter BuildFilter(SimpleBrokerQuery queryParams) { InputItemFilter filter = new InputItemFilter { ItemTypes = new List <FilterItemType> { FilterItemType.COMPONENT }, }; if (queryParams.SchemaId > 0) { filter.Schema = new InputSchemaCriteria { Id = queryParams.SchemaId }; } if (queryParams.PublicationId > 0) { filter.PublicationIds = new List <int?> { queryParams.PublicationId }; } return(filter); }
public QueryBuilder WithInputItemFilter(InputItemFilter filter) => WithVariable("inputItemFilter", filter);