public async Task <IActionResult> GetReportDocumentAsync(string schemaId, string iaocCode, ReportPeriod reportPeriod, string year, string currency = "native") { try { currency = currency.Trim().ToLowerInvariant(); var adjustedSchema = schemaId; if (currency != "native") { adjustedSchema += "-" + currency.ToLowerInvariant(); } // Recover Document Details from DB var report = _reportDataService.GetReportDetail(iaocCode, reportPeriod, schemaId, Convert.ToInt32(year, CultureInfo.InvariantCulture)); if (report != null && !string.IsNullOrEmpty(report.Airline)) { return(await GetDocumentAsync(schemaId, currency, report.DocumentId.ToString())); } } catch (Exception ex) { _logger.LogError($"Failed to Recover Document for airline:{iaocCode}, period:{reportPeriod}, type:{schemaId} and year:{year} -> Error Message:{ex.Message}"); } return(NotFound($"No Report Found for airline:{iaocCode}, period:{reportPeriod}, type:{schemaId} and year:{year}")); }
public async Task <IActionResult> GetReportDocumentAsync(string schemaId, string iaocCode, ReportPeriod reportPeriod, string year, string currency = "native") { try { currency = currency.Trim().ToLowerInvariant(); var documentHandler = GetDocumentHandler(schemaId); var adjustedSchema = schemaId; if (currency != "native") { // adjustedSchema += "-" + currency.ToLowerInvariant(); } // Recover Document Details from DB var report = _reportDataService.GetReportDetail(iaocCode, reportPeriod, adjustedSchema, Convert.ToInt32(year, CultureInfo.InvariantCulture)); if (report != null) { // Get Valid AuthO Token var token = _clientTokenHandler.GetValidToken(); // Build Document URI var documentUri = GCPDocumentHelper.BuildGCPDocumentRequestUri(_documentSettings, schemaId, currency, report.DocumentId); // Retrieve Document from GCP var document = await documentHandler.GetDocumentAsync(documentUri.AbsoluteUri, token, CancellationToken.None); return(Ok(document)); } } catch (Exception ex) { _logger.LogError($"Failed to Recover Document for airline:{iaocCode}, period:{reportPeriod}, type:{schemaId} and year:{year} -> Error Message:{ex.Message}"); } return(NotFound($"No Report Found for airline:{iaocCode}, period:{reportPeriod}, type:{schemaId} and year:{year}")); }
public async Task <IActionResult> PublishReportStorageNotificationAsync(string schemaId, string iaocCode, ReportPeriod reportPeriod, string year, string currency = "native") { try { currency = currency.Trim().ToLowerInvariant(); var adjustedSchema = schemaId; if (currency != "native") { // adjustedSchema += "-" + currency.ToLowerInvariant(); } // Recover Document Details from DB var report = _reportDataService.GetReportDetail(iaocCode, reportPeriod, adjustedSchema, Convert.ToInt32(year, CultureInfo.InvariantCulture)); if (report != null) { var documentId = report.DocumentId.ToString(); var gcpToken = _clientTokenHandler.GetValidToken(); var documentURI = $"{_gcpAserviceAPI}{schemaId}/{documentId}"; // Get Stored Document direct from GCP var storedDocument = await GCPDocumentHelper.GetGCPDocumentAsync(documentURI, gcpToken, CancellationToken.None); // Upsert Document - (Same URI but with a PUT) var response = await _documentUpsertProcessor.UpsertDocumentAsync(documentURI, gcpToken, storedDocument, CancellationToken.None); if (response) { return(Ok()); } } else { return(NotFound()); } } catch (Exception ex) { _logger.LogCritical(ex, "FAILED trying to Publish Report Storage Notification", iaocCode, reportPeriod); } return(BadRequest()); }