WIP: process layers

This commit is contained in:
Michał Zieliński
2023-09-17 13:00:24 +02:00
parent 40122314b2
commit 5cb362b5e0
7 changed files with 200 additions and 14 deletions

View File

@@ -172,29 +172,119 @@ namespace WebAPI.Controllers
return BadRequest(e.ToString());
}
return Ok();
}
}
[HttpGet]
[Route("autoImportMorska/{apiKey}")]
[Route("AutoProcess/{apiKey}")]
[AllowAnonymous]
public IActionResult autoImportMorska(string apiKey)
public IActionResult AutoProcess(string apiKey)
{
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
{
return Unauthorized();
}
morskaK5Parser parser = new morskaK5Parser(googleSheetValues, db);
Layer layer = parser.parse();
List<Layer> processWorkerLayers;
List<Layer> layersToProcess;
try
{
processWorkerLayers = db.Layers
.Include(x => x.Records)
.Where(x => x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ProcessWorker"))
.ToList();
layersToProcess = new List<Layer>();
foreach (Layer layer in processWorkerLayers)
{
string? sourceName = layer?.Records?.Single(x => x.Code == "Source")?.Desc1;
if (sourceName == null)
{
logsController.AddEntry(new LogEntry
{
Title = "Process error",
Type = LogEntryType.error,
LogType = LogType.import,
Message = layer?.Name + " Source record not found",
CreatedAt = DateTime.UtcNow
});
return BadRequest();
} else
{
Layer sourceLayer = db.Layers.Single(x => x.Name == sourceName);
if (sourceLayer == null)
{
logsController.AddEntry(new LogEntry
{
Title = "Process error",
Type = LogEntryType.error,
LogType = LogType.import,
Message = layer?.Name + " Source layer not found " + sourceLayer,
CreatedAt = DateTime.UtcNow
});
return BadRequest();
} else
{
string startDate = sourceLayer.Records!.Where(x => x.Code == "StartDate").First().Desc1!;
string endDate = sourceLayer.Records!.Where(x => x.Code == "EndDate").First().Desc1!;
var startDateParsed = DateTime.ParseExact(startDate, "yyyy.MM.dd", null);
var endDateParsed = DateTime.ParseExact(endDate, "yyyy.MM.dd", null);
if (startDateParsed.Date <= DateTime.UtcNow.Date && endDateParsed.Date >= DateTime.UtcNow.Date)
{
string? processType = layer?.Records?.Single(x => x.Code == "ProcessType")?.Desc1;
if (processType == null)
{
logsController.AddEntry(new LogEntry
{
Title = "Process error",
Type = LogEntryType.error,
LogType = LogType.import,
Message = layer?.Name + " ProcessType record not found",
CreatedAt = DateTime.UtcNow
});
return BadRequest();
} else
{
switch (processType)
{
case "Copy":
break;
case "Deaggregate":
break;
}
}
}
}
}
//Layer sourceLayer = db.Layers.Single(x => x.Name == layer.Records.Single(y => y.Code == "Source").Desc1);
AddLayer(layer, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
return Ok("OK");
}
// string startDate = layer.Records!.Where(x => x.Code == "StartDate").First().Desc1!;
/// string endDate = layer.Records!.Where(x => x.Code == "EndDate").First().Desc1!;
// var startDateParsed = DateTime.ParseExact(startDate, "yyyy.MM.dd", null);
// var endDateParsed = DateTime.ParseExact(endDate, "yyyy.MM.dd", null);
// if (startDateParsed.Date <= DateTime.UtcNow.Date && endDateParsed.Date >= DateTime.UtcNow.Date)
// {
// processImportWorker(layer);
// }
}
}
catch (Exception e)
{
logsController.AddEntry(new LogEntry
{
Title = "Process error",
Type = LogEntryType.error,
LogType = LogType.import,
Message = e.ToString(),
CreatedAt = DateTime.UtcNow
});
return BadRequest(e.ToString());
}
return Ok();
}
[HttpGet]
[Route("checkDates")]
public IActionResult checkDates()

View File

@@ -32,6 +32,9 @@ namespace WebAPI.Controllers
case LogType.backup:
type = "Backup";
break;
case LogType.process:
type = "Process";
break;
default:
type = "Other"; // should never happen
break;