Deagregation processor

This commit is contained in:
Michał Zieliński
2023-09-18 19:41:39 +02:00
parent 716ed532f1
commit a30b584ca7
7 changed files with 771 additions and 41 deletions

View File

@@ -196,9 +196,9 @@ namespace WebAPI.Controllers
layersToProcess = new List<Layer>();
foreach (Layer layer in processWorkerLayers)
foreach (Layer processWorker in processWorkerLayers)
{
string? sourceName = layer?.Records?.Single(x => x.Code == "Source")?.Desc1;
string? sourceName = processWorker?.Records?.Single(x => x.Code == "Source")?.Desc1;
if (sourceName == null)
{
logsController.AddEntry(new LogEntry
@@ -206,7 +206,7 @@ namespace WebAPI.Controllers
Title = "Process error",
Type = LogEntryType.error,
LogType = LogType.import,
Message = layer?.Name + " Source record not found",
Message = processWorker?.Name + " Source record not found",
CreatedAt = DateTime.UtcNow
});
return BadRequest();
@@ -221,7 +221,7 @@ namespace WebAPI.Controllers
Title = "Process error",
Type = LogEntryType.error,
LogType = LogType.import,
Message = layer?.Name + " Source layer not found " + sourceLayer,
Message = processWorker?.Name + " Source layer not found " + sourceLayer,
CreatedAt = DateTime.UtcNow
});
return BadRequest();
@@ -233,7 +233,7 @@ namespace WebAPI.Controllers
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;
string? processType = processWorker?.Records?.Single(x => x.Code == "ProcessType")?.Desc1;
if (processType == null)
{
logsController.AddEntry(new LogEntry
@@ -241,28 +241,34 @@ namespace WebAPI.Controllers
Title = "Process error",
Type = LogEntryType.error,
LogType = LogType.import,
Message = layer?.Name + " ProcessType record not found",
Message = processWorker?.Name + " ProcessType record not found",
CreatedAt = DateTime.UtcNow
});
return BadRequest();
} else
{
Layer processedLayer;
Layer? processedLayer = null;
switch (processType)
{
case "Copy":
CopyProcessor processor = new CopyProcessor(db);
processedLayer = processor.process(sourceLayer);
CopyProcessor cp = new CopyProcessor(db, googleSheetValues);
processedLayer = cp.process(sourceLayer, processWorker?.Id);
break;
case "Deaggregate":
case "Deaggregation":
DeaggregationProcessor dp = new DeaggregationProcessor(db, googleSheetValues);
processedLayer = dp.process(sourceLayer, processWorker?.Id);
break;
}
if (processedLayer != null)
{
AddLayer(processedLayer, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
}
}
}
}
}
}
return Ok();
}
catch (Exception e)
{
@@ -270,13 +276,12 @@ namespace WebAPI.Controllers
{
Title = "Process error",
Type = LogEntryType.error,
LogType = LogType.import,
LogType = LogType.process,
Message = e.ToString(),
CreatedAt = DateTime.UtcNow
});
return BadRequest(e.ToString());
}
return Ok();
}
@@ -391,18 +396,16 @@ namespace WebAPI.Controllers
input.ModifiedById = currentUserId;
input.CreatedAt = DateTime.UtcNow;
input.ModifiedAt = DateTime.UtcNow;
db.Layers.Add(input);
SaveRecords(input.Id, input.Records!, currentUserId);
db.SaveChanges();
return input;
}
private void SaveRecords(Guid id, ICollection<Models.Record> records, Guid currentUserId)
private void SaveRecords(Guid id, ICollection<Record> records, Guid currentUserId)
{
try
{
List<Guid> ids = new List<Guid>();
foreach (Record record in records)
{
record.CreatedById = currentUserId;
@@ -410,7 +413,6 @@ namespace WebAPI.Controllers
record.ModifiedById = currentUserId;
record.ModifiedAt = DateTime.UtcNow;
record.LayerId = id;
db.Records.Add(record);
}
}
@@ -418,6 +420,21 @@ namespace WebAPI.Controllers
{
throw;
}
}
private void SaveSources(ICollection<ProcessSource> sources)
{
try
{
foreach (ProcessSource processSource in sources)
{
Console.WriteLine($"{processSource.LayerId} {processSource.SourceId}");
// db.ProcessSources.Add(processSource);
}
}
catch (Exception)
{
throw;
}
}
}
}