public IEnumerable <FrameworkSummary> GetAllFrameworks()
        {
            var take = _queryHelper.GetFrameworksTotalAmount();

            var searchDescriptor = GetAllFrameworksSearchDescriptor(take);

            var results =
                _elasticsearchCustomClient.Search <FrameworkSearchResultsItem>(s => searchDescriptor);

            if (results.ApiCall.HttpStatusCode != 200)
            {
                throw new ApplicationException($"Failed query all frameworks");
            }

            var resultList = results.Documents.Select(frameworkSearchResultsItem => _frameworkMapping.MapToFrameworkSummary(frameworkSearchResultsItem));

            return(resultList);
        }
Пример #2
0
        public IEnumerable <ProviderFramework> GetFrameworksByProviderUkprn(long ukprn)
        {
            var totalTakeForFrameworkDocuments = _queryHelper.GetFrameworksTotalAmount();
            var aggregateKeyName = "levelId";
            var matchedIds       =
                _elasticsearchCustomClient.Search <ProviderFrameworkDto>(
                    s =>
                    s.Index(_applicationSettings.ProviderIndexAlias)
                    .From(0)
                    .Query(q => + q.Term("documentType", "frameworkprovider") && +q.Term(t => t.Ukprn, ukprn))
                    .Aggregations(agg => agg.Terms(aggregateKeyName, frm => frm.Size(totalTakeForFrameworkDocuments).Field(fi => fi.FrameworkId))));

            if (matchedIds.ApiCall.HttpStatusCode != 200)
            {
                _applicationLogger.LogWarning($"httpStatusCode was {matchedIds.ApiCall.HttpStatusCode} when querying provider frameworks for ukprn [{ukprn}]");
                throw new ApplicationException($"Failed to query provider frameworks for ukprn [{ukprn}]");
            }

            var matchingFrameworkIds = ExtractFrameworkIdsFromAggregation(matchedIds, aggregateKeyName);

            var providerFrameworks =
                _elasticsearchCustomClient.Search <ProviderFramework>(
                    s =>
                    s.Index(_applicationSettings.ApprenticeshipIndexAlias)
                    .From(0)
                    .Take(matchingFrameworkIds.Count)
                    .Query(q => + q.Term("documentType", "frameworkdocument") && +q.Terms(t => t.Field(f => f.FrameworkId).Terms(matchingFrameworkIds))));

            if (providerFrameworks.ApiCall.HttpStatusCode != 200)
            {
                _applicationLogger.LogWarning($"httpStatusCode was {providerFrameworks.ApiCall.HttpStatusCode} when querying provider frameworks apprenticeship details for ukprn [{ukprn}]");
                throw new ApplicationException($"Failed to query provider frameworks apprenticeship details for ukprn [{ukprn}]");
            }

            return(providerFrameworks.Documents);
        }