public void Delete(string schemaId, string documentId) { documentId = documentId.ToLowerInvariant(); // Get GCP Auth0 Token var clientToken = _clientTokenHandler.GetValidToken(); // DELETE Document from GCP var gcpDeletionResponse = _documentDeletionProcessor.DeleteDocumentAsync(schemaId, documentId, clientToken, CancellationToken.None).GetAwaiter().GetResult(); if (gcpDeletionResponse == true) { // Delete Report in Database var response = _reportDataService.DeleteReport(documentId); if (response.Success) { _logger.LogInformation($"Successfully Deleted Document with Id:{documentId}"); } } }
/// <summary> /// Delete Historic Records for Specified Airline, Reporting Period, ReportType (GCP SchemaId) and Year /// </summary> /// <param name="iaocCode">Airline Code</param> /// <param name="reportPeriod">Report Period - Annual, Q1, Q2</param> /// <param name="schemaId">GCP SchemaId e.g. raw-income-statement</param> /// <param name="year">Report Year</param> /// <returns>Command Response</returns> public async Task <CommandResponse> DeleteHistoricRecordsAsync(string iaocCode, ReportPeriod reportPeriod, string schemaId, int year) { CommandResponse response = new CommandResponse { Information = $"Deleting Historic Reports for:{iaocCode} period:{reportPeriod} type:{schemaId} year:{year}", Success = true }; try { var deleteList = _reportDataService.GetReportDocumentsForDeletions(iaocCode, reportPeriod, schemaId, year); if (deleteList != null) { var token = _clientTokenHandler.GetValidToken(); foreach (Guid documentId in deleteList) { // DELETE Document from GCP var gcpDeletionResponse = await _documentDeletionProcessor.DeleteDocumentAsync(schemaId, documentId.ToString(), token, CancellationToken.None); if (gcpDeletionResponse == true) { // Delete Report in Document Service Database var documentAPIResponse = _reportDataService.DeleteReport(documentId.ToString()); if (documentAPIResponse != null && !documentAPIResponse.Success) { response.Success = false; } } else { response.Success = false; _logger.LogWarning($"FAILED to DELETE Document from GCP for:{iaocCode} period:{reportPeriod} type:{schemaId} year:{year}"); } } if (!response.Success) { _logger.LogWarning($"FAILED to DELETE ALL Historic Documents for :{iaocCode} period:{reportPeriod} type:{schemaId} year:{year}"); } } } catch (Exception ex) { _logger.LogError(ex.Message); response.FaultMessage = ex.Message; response.Success = false; } return(response); }
public async Task <IActionResult> GetProcessedDocumentByIdAsync(string schemaId, string documentId) { try { string currency = "native"; var documentHandler = GetDocumentHandler(schemaId); // Get Valid AuthO Token var token = _clientTokenHandler.GetValidToken(); // Build Document URI var documentUri = GCPDocumentHelper.BuildGCPDocumentRequestUri(_documentSettings, schemaId, currency, 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 with Id:{documentId} -> Error Message:{ex.Message}"); } return(NotFound($"No Report Found for Document Id:{documentId}")); }
public IActionResult PostRawDocument(string schemaId, [FromBody] dynamic postedDocument) { var documentHandler = GetDocumentHandler(schemaId); // make sure that values are valid for base data such as AirlineICAOCode, ReportPeriod, ReportDate and Currency var reportBaseValidation = new ReportBaseValidation(postedDocument); if (!TryValidateModel(reportBaseValidation)) { return(BadRequest(new BadRequestObjectResult(ModelState))); } // Serialize Model to JSON var json = JsonConvert.SerializeObject(postedDocument); // POST Document to GCP var clientToken = _clientTokenHandler.GetValidToken(); var documentResponse = documentHandler.PostNewDocument(new Uri(_documentSettings.Endpoint, schemaId).ToString(), clientToken, json, CancellationToken.None).GetAwaiter().GetResult(); if (documentResponse.Success) { var documentId = new Guid(new Uri(documentResponse.DocumentUri).Segments.Last()); // Save Report to report database var report = GetReportBaseData(json, schemaId, documentId); // Save Report in Database var saveResponse = _reportDataService.RegisterNewReport(report); if (saveResponse.Success) { _logger.LogInformation($"Successfully stored new Document:{report.DocumentId} or Schema:{schemaId}"); } return(Created(new Uri(documentResponse.DocumentUri), documentId)); } else { _logger.LogWarning($"Unprocessable Entity"); return(UnprocessableEntity(documentResponse.Content)); } }