public async Task<List<RoatpProviderResult>> Handle(RoatpRequest message)
        {
            var roatpSummaries = await _apiClient.GetRoatpSummary();

            var records = _mapper.Map(roatpSummaries);

            _logger.Debug($"Retrieved {records.Count} providers on the ROATP list", new Dictionary<string, object> { { "TotalCount", records.Count } });
            var filtered = records.Where(x => _validProviderTypes.Contains(x.ProviderType) && x.IsDateValid()).ToList();
            _logger.Debug($"Filtered out Supporting providers on ROATP", new Dictionary<string, object> { { "TotalCount", filtered.Count } });
            return filtered;

        }
        public IEnumerable <RoatpProvider> GetRoatpData()
        {
            IDictionary <string, object> extras = new Dictionary <string, object>();

            extras.Add("DependencyLogEntry.Url", _appServiceSettings.VstsRoatpUrl);

            if (!string.IsNullOrEmpty(_appServiceSettings.GitUsername))
            {
                var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{_appServiceSettings.GitUsername}:{_appServiceSettings.GitPassword}"));
                _client.Headers[HttpRequestHeader.Authorization] = $"Basic {credentials}";
            }

            try
            {
                _log.Debug("Getting roatp data from roatp api endpoint");
                var roatpProviders = _apiClient.GetRoatpSummary().Result;
                return(roatpProviders.Where(roatpProviderResult => roatpProviderResult.Ukprn != string.Empty));
            }
            catch (WebException wex)
            {
                var response = (HttpWebResponse)wex.Response;
                if (response != null)
                {
                    extras.Add("DependencyLogEntry.ResponseCode", response.StatusCode);
                }

                if (response?.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _log.Error(wex, "Your VSTS credentials were unauthorised", extras);
                }
                else
                {
                    _log.Error(wex, "Problem downloading ROATP from VSTS", extras);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex, "Problem downloading ROATP from VSTS", extras);
            }

            return(null);
        }
Esempio n. 3
0
        public async Task <IActionResult> GetAll()
        {
            try
            {
                _log.LogDebug($"Fetching GET ALL for ukprns");

                IEnumerable <RoatpResult> results;

                try
                {
                    var result = _retryService.RetryPolicy("<roatpService>/api/v1/download/roatp-summary").ExecuteAsync(context => _apiClient.GetRoatpSummary(), new Context());
                    results = result.Result.Where(x => x.IsDateValid(DateTime.UtcNow));
                }
                catch (Exception ex)
                {
                    _log.LogError("Unable to retrieve results for all roatps", ex);
                    results = new List <RoatpResult>();
                }

                var providers = new List <Provider>();

                foreach (var result in results)
                {
                    var provider = _mapper.Map(result);
                    if (provider == null)
                    {
                        continue;
                    }
                    provider.Uri = Resolve(provider.Ukprn);
                    providers.Add(provider);
                }

                return(Ok(providers));
            }
            catch (Exception e)
            {
                _log.LogError(e, "/providers");
                throw;
            }
        }