public IActionResult PostEnrichedDocument(string schemaId, [FromBody] dynamic postedDocument) { var documentHandler = GetDocumentHandler(schemaId); // Serialize Model to JSON var json = JsonConvert.SerializeObject(postedDocument); // 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))); } // 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}"); } // Check to see if document is some of this types and send notification if yes // operational-data // income-statement // balance-sheet // cash flow statement // share info var coreReportTypes = new string[] { "operational-data", "income-statement", "balance-sheet", "cash-flow-statement", "share-info" }; if (coreReportTypes.Contains(schemaId)) { var response = _notificationService.TestAndPublishSecondaryReportNotificationAsync(report.AirlineICAOCode, report.ReportPeriod, report.Currency, report.Year); } return(Created(new Uri(documentResponse.DocumentUri), documentId)); } else { _logger.LogWarning($"Unprocessable Entity"); return(UnprocessableEntity(documentResponse.Content)); } }
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)); } }