private bool CreateFolder(IDataExtractionClient dataExtractionClient, string customerShortName, string projectShortName, Guid id) { var exportFolderRoot = _iam.GetProjectConfig(customerShortName, projectShortName).MassResultExportConfig; if (!Directory.Exists(Path.Combine(exportFolderRoot.ExportLandingZone, customerShortName, projectShortName, id.ToString(), _config.MrePlusEventsFolderName))) { var input = new { customerShortName = customerShortName, projectShortName = projectShortName, folderName = id.ToString(), }; var json = JsonConvert.SerializeObject(input); var method = "CreateMrePlusEventFolders_Rest"; var response = dataExtractionClient.Client.PostAsync(method, new StringContent(json, Encoding.UTF8, "application/json")).Result; _validation.ValidateResponse(response); var result = response.Content.ReadAsStringAsync().Result; var property = JObject.Parse(result).Property("CreateMrePlusEventFolders_RestResult"); return(property.Value.ToObject <bool>()); } else { return(true); } }
public IActionResult MREPlusEventDefinitions([FromServices] IDataExtractionClient dataExtractionClient, string customerShortName, string projectShortName, Guid id) { var job = _jobProxy.GetJob(customerShortName, projectShortName, id); var fileNameSuffix = DateTime.Now.ToString("yyyyMMddHHmmss"); var mrePlusEnabled = false; if (job.eventMrePlusOptions != null && Boolean.TryParse(job.eventMrePlusOptions.Value, out mrePlusEnabled) && mrePlusEnabled) { bool folderCreated = CreateFolder(dataExtractionClient, customerShortName, projectShortName, id); if (folderCreated) { job.eventMrePlusOptions.file_name_suffix = fileNameSuffix; bool isgZip = job.eventMrePlusOptions != null && job.eventMrePlusOptions.archive_format.ToLower() == "gzip"; var input = new { customerShortName = customerShortName, projectShortName = projectShortName, folderName = id.ToString() + @"/" + _config.MrePlusEventsFolderName, fileType = $"TAB|txt{(isgZip ? ".gz" : string.Empty)}", fileNameSuffix = fileNameSuffix }; var json = JsonConvert.SerializeObject(input); var method = "MassResultsExportPlusEventDefinitions_Rest"; var response = dataExtractionClient.Client.PostAsync(method, new StringContent(json, Encoding.UTF8, "application/json")).Result; _validation.ValidateResponse(response); var result = response.Content.ReadAsStringAsync().Result; var succeeded = ((JProperty)JObject.Parse(result).First).Value.Value <bool>(); if (!succeeded) { throw new OperationCanceledException($"MRE+ Event definition export failed for the following input: api: {method}, json: {json}"); } _jobProxy.UpdateJob(job); _logging.Log("MREPlusEventDefinitions completed", Orchestration.Shared.Domain.Log.LogLevels.Info); } else { _logging.Log("CreateMrePlusEventFolders_Rest failed", Orchestration.Shared.Domain.Log.LogLevels.Info); } } else { _logging.Log("Skipped running MREPlusEventDefinitions", Orchestration.Shared.Domain.Log.LogLevels.Info); } return(Ok()); }