Exemplo n.º 1
0
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = new CancellationToken())
        {
            _logger.LogInformation("Pinging ProviderRelationships API");

            try
            {
                var timer = Stopwatch.StartNew();
                await _apiClient.GetAccountProviderLegalEntitiesWithPermission(new GetAccountProviderLegalEntitiesWithPermissionRequest());

                timer.Stop();

                var durationString = timer.Elapsed.ToHumanReadableString();

                _logger.LogInformation($"ProviderRelationships API ping successful and took {durationString}");

                return(HealthCheckResult.Healthy(HealthCheckResultDescription,
                                                 new Dictionary <string, object> {
                    { "Duration", durationString }
                }));
            }
            catch (RestHttpClientException e)
            {
                _logger.LogWarning($"ProviderRelationships API ping failed : [Code: {e.StatusCode}] - {e.ReasonPhrase}");
                return(HealthCheckResult.Unhealthy(HealthCheckResultDescription, e));
            }
        }
        public async Task Run()
        {
            const long ukprn = 10005077;

            var relationshipsRequest = new GetAccountProviderLegalEntitiesWithPermissionRequest {
                Ukprn = ukprn, Operation = Operation.CreateCohort
            };
            var response = await _providerRelationshipsApiClient.GetAccountProviderLegalEntitiesWithPermission(relationshipsRequest);

            if (response.AccountProviderLegalEntities.Any())
            {
                Console.WriteLine($"Provider with UKPRN {relationshipsRequest.Ukprn} has AccountProviderLegalEntities with {relationshipsRequest.Operation} permission");
            }
        }
Exemplo n.º 3
0
        private async Task <IEnumerable <AccountProviderLegalEntityDto> > GetLegalEntitiesWithCreatePermission(long providerId)
        {
            var result = await _providerRelationshipsApiClient.GetAccountProviderLegalEntitiesWithPermission(
                new GetAccountProviderLegalEntitiesWithPermissionRequest
            {
                Ukprn     = providerId,
                Operation = Operation.CreateCohort
            });

            if (result?.AccountProviderLegalEntities == null)
            {
                return(new List <AccountProviderLegalEntityDto>());
            }

            return(result.AccountProviderLegalEntities);
        }
Exemplo n.º 4
0
        private async Task CheckProviderHasPermission(long providerId, long accountLegalEntityId)
        {
            var permissionsRequest = new GetAccountProviderLegalEntitiesWithPermissionRequest
            {
                Ukprn     = providerId,
                Operation = Operation.CreateCohort
            };

            var permissions = await
                              _providerRelationshipsApiClient.GetAccountProviderLegalEntitiesWithPermission(permissionsRequest);

            if (permissions.AccountProviderLegalEntities.All(x => x.AccountLegalEntityId != accountLegalEntityId))
            {
                throw new DomainException(nameof(accountLegalEntityId), $"Provider {providerId} does not have {nameof(Operation.CreateCohort)} permission for AccountLegalEntity {accountLegalEntityId} in order to create a Change of Party request");
            }
        }
        public async Task <GetProviderRelationshipsWithPermissionQueryResponse> Handle(GetProviderRelationshipsWithPermissionQueryRequest request, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(new GetProviderRelationshipsWithPermissionQueryResponse
                {
                    ProviderRelationships = new List <AccountProviderLegalEntityDto>()
                });
            }

            var result = await _providerRelationshipsApiClient.GetAccountProviderLegalEntitiesWithPermission(new GetAccountProviderLegalEntitiesWithPermissionRequest
            {
                Operation = request.Permission,
                Ukprn     = request.ProviderId
            }, cancellationToken);

            return(new GetProviderRelationshipsWithPermissionQueryResponse
            {
                ProviderRelationships = result.AccountProviderLegalEntities
            });
        }
Exemplo n.º 6
0
        public async Task <IEnumerable <Employer> > GetTrustedEmployers(uint ukPrn)
        {
            if (ukPrn == default(uint))
            {
                throw new ArgumentException("Ukprn must be set to a non default value", nameof(ukPrn));
            }

            var trustedEmployers = await _apiClient.GetAccountProviderLegalEntitiesWithPermission(
                new GetAccountProviderLegalEntitiesWithPermissionRequest
            {
                Operation = Operation.CreateCohort,
                Ukprn     = ukPrn
            });

            return(trustedEmployers?.AccountProviderLegalEntities?.Select(e => new Employer
            {
                AccountId = e.AccountId,
                AccountPublicHashedId = e.AccountPublicHashedId,
                AccountName = e.AccountName,
                AccountLegalEntityId = e.AccountLegalEntityId,
                AccountLegalEntityPublicHashedId = e.AccountLegalEntityPublicHashedId,
                AccountLegalEntityName = e.AccountLegalEntityName
            }).ToArray());
        }