/// <inheritdoc /> protected async override Task <IActionResult> ProcessWellFormedRequestAsync( GetCensusRequest getCensusRequest, FunctionRunContext functionRunContext, CancellationToken cancellationToken) { IActionResult toReturn = null; if (getCensusRequest == null) { getCensusRequest = new GetCensusRequest(); } getCensusRequest.CensusIdentifier = this.censusIdentifier; try { GetCensusResponse getCensusResponse = await this.censusProcessor.GetCensusAsync( getCensusRequest, cancellationToken) .ConfigureAwait(false); Census census = getCensusResponse.Census; JsonSerializerSettings jsonSerializerSettings = JsonConvert.DefaultSettings(); if (jsonSerializerSettings == null) { toReturn = new JsonResult(census); } else { toReturn = new JsonResult(census, jsonSerializerSettings); } } catch (DatasetQueryFileNotFoundException datasetQueryFileNotFoundException) { toReturn = this.GetErrorBody( HttpStatusCode.NotFound, 4, datasetQueryFileNotFoundException); } catch (IncompleteDatasetQueryFileException incompleteDatasetQueryFileException) { toReturn = this.GetErrorBody( HttpStatusCode.ExpectationFailed, 5, incompleteDatasetQueryFileException); } catch (TranslationApiAdapterException translationApiAdapterException) { toReturn = this.GetErrorBody( HttpStatusCode.FailedDependency, 6, translationApiAdapterException); } catch (UnsupportedAggregateColumnRequestException unsupportedAggregateColumnRequestException) { toReturn = this.GetErrorBody( HttpStatusCode.BadRequest, 7, unsupportedAggregateColumnRequestException); } catch (InvalidMappingTypeException invalidMappingTypeException) { toReturn = this.GetErrorBody( HttpStatusCode.ExpectationFailed, 8, invalidMappingTypeException); } catch (SqlFieldValueUnboxingTypeException sqlFieldValueUnboxingTypeException) { toReturn = this.GetErrorBody( HttpStatusCode.ExpectationFailed, 9, sqlFieldValueUnboxingTypeException); } catch (InvalidBetweenValueException invalidBetweenValueException) { toReturn = this.GetErrorBody( HttpStatusCode.BadRequest, 10, invalidBetweenValueException); } catch (InvalidDateTimeFormatException invalidDateTimeFormatException) { toReturn = this.GetErrorBody( HttpStatusCode.BadRequest, 11, invalidDateTimeFormatException); } catch (DataFilterValueUnboxingTypeException dataFilterValueUnboxingTypeException) { toReturn = this.GetErrorBody( HttpStatusCode.BadRequest, 12, dataFilterValueUnboxingTypeException); } catch (UnsupportedSearchParameterException unsupportedSearchParameterException) { toReturn = this.GetErrorBody( HttpStatusCode.BadRequest, 13, unsupportedSearchParameterException); } return(toReturn); }
/// <inheritdoc /> public async Task <GetCensusResponse> GetCensusAsync( GetCensusRequest getCensusRequest, CancellationToken cancellationToken) { GetCensusResponse toReturn = null; if (getCensusRequest == null) { throw new ArgumentNullException(nameof(getCensusRequest)); } CensusIdentifier censusIdentifier = getCensusRequest.CensusIdentifier; string datasetQueryFileId = censusIdentifier.DatasetQueryFileId; this.loggerWrapper.Debug( $"Pulling back {nameof(DatasetQueryFile)} with id " + $"\"{datasetQueryFileId}\"..."); DatasetQueryFile datasetQueryFile = await this.datasetQueryFilesStorageAdapter.GetDatabaseQueryFileAsync( censusIdentifier.DatasetQueryFileId, cancellationToken) .ConfigureAwait(false); this.loggerWrapper.Info( $"Got {nameof(DatasetQueryFile)} for id " + $"\"{datasetQueryFileId}\": {datasetQueryFile}."); Dictionary <string, AggregateQuery> aggregateQueries = getCensusRequest.AggregateQueries; Census census = null; if (aggregateQueries != null) { census = await this.GetCensusAggregates( getCensusRequest, datasetQueryFile, cancellationToken) .ConfigureAwait(false); } else { census = new Census(); } census.Name = $"Census results from " + $"{datasetQueryFile.QueryConfiguration.DatabaseName}"; this.loggerWrapper.Info( $"Fetched {nameof(Census)}: {census} using " + $"{datasetQueryFile} and supplied aggregate queries."); toReturn = new GetCensusResponse() { Census = census, }; return(toReturn); }