Manually process layer
This commit is contained in:
@@ -27,7 +27,8 @@ namespace WebAPI.Controllers
|
||||
IConfiguration _configuration)
|
||||
{
|
||||
db = _db;
|
||||
if (_googleSheetsHelper.Service is not null) {
|
||||
if (_googleSheetsHelper.Service is not null)
|
||||
{
|
||||
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
||||
}
|
||||
googleSheetsHelper = _googleSheetsHelper;
|
||||
@@ -44,7 +45,7 @@ namespace WebAPI.Controllers
|
||||
IQueryable<Layer> response = db.Layers.Where(x => !x.IsDeleted);
|
||||
if (name != null)
|
||||
{
|
||||
response = response.Where(x => x.Name!=null && x.Name.Contains(name));
|
||||
response = response.Where(x => x.Name != null && x.Name.Contains(name));
|
||||
}
|
||||
if (type != null)
|
||||
{
|
||||
@@ -78,7 +79,8 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("{id}")] public IActionResult Get(Guid id)
|
||||
[Route("{id}")]
|
||||
public IActionResult Get(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -116,7 +118,8 @@ namespace WebAPI.Controllers
|
||||
[Route("exportToGoogleSheet/{id}")]
|
||||
public IActionResult ExportToGoogleSheet(Guid id)
|
||||
{
|
||||
if (googleSheetValues is null) {
|
||||
if (googleSheetValues is null)
|
||||
{
|
||||
throw new Exception("Google Sheets API not initialized");
|
||||
}
|
||||
Layer layer = db.Layers
|
||||
@@ -137,7 +140,8 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
if (googleSheetValues is null) {
|
||||
if (googleSheetValues is null)
|
||||
{
|
||||
throw new Exception("Google Sheets API not initialized");
|
||||
}
|
||||
try
|
||||
@@ -147,7 +151,7 @@ namespace WebAPI.Controllers
|
||||
.Include(x => x.Records)
|
||||
.Where(x =>
|
||||
x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ImportWorker") &&
|
||||
x.Records!.Any(x => x.Code == "IsEnabled" && x.Desc1 == "True")
|
||||
x.Records!.Any(x => x.Code == "IsEnabled" && x.Desc1 == "True")
|
||||
)
|
||||
.OrderBy(x => x.CreatedAt)
|
||||
.ToList();
|
||||
@@ -205,7 +209,8 @@ namespace WebAPI.Controllers
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
} catch(Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
@@ -218,7 +223,8 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
}
|
||||
return Ok();
|
||||
} catch(Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
@@ -240,7 +246,8 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
if (googleSheetValues is null) {
|
||||
if (googleSheetValues is null)
|
||||
{
|
||||
throw new Exception("Google Sheets API not initialized");
|
||||
}
|
||||
|
||||
@@ -272,132 +279,9 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
string? name = processWorker.Name;
|
||||
string? year = processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
|
||||
if (year == null)
|
||||
{
|
||||
throw new Exception("Year record nod found");
|
||||
}
|
||||
|
||||
if (int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.warning,
|
||||
LogType = LogType.process,
|
||||
Message = "processLayer is out of date. Should be disabled. Not processed.",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
string? processType = processWorker?.Records?.SingleOrDefault(x => x.Code == "ProcessType")?.Desc1;
|
||||
if (processType == null)
|
||||
{
|
||||
throw new Exception("ProcessType record not found");
|
||||
}
|
||||
if (processType == "T3-SourceYearSummary")
|
||||
{
|
||||
if (int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.warning,
|
||||
LogType = LogType.process,
|
||||
Message = "processLayer is out of date. Should be disabled. Not processed",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
continue;
|
||||
}
|
||||
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.info,
|
||||
LogType = LogType.process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (processType == "T3-MultiSourceYearSummary")
|
||||
{
|
||||
if (int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.warning,
|
||||
LogType = LogType.process,
|
||||
Message = "processLayer is out of date. Should be disabled. Not processed",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
continue;
|
||||
}
|
||||
T3MultiSourceYearSummaryProcessor processor = new T3MultiSourceYearSummaryProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.info,
|
||||
LogType = LogType.process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
continue;
|
||||
}
|
||||
string? month = processWorker?.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1;
|
||||
if (month == null)
|
||||
{
|
||||
throw new Exception("Month record not found");
|
||||
}
|
||||
if (int.Parse(month!) < DateTime.UtcNow.Month)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.warning,
|
||||
LogType = LogType.process,
|
||||
Message = "processLayer is out of date. Should be disabled.",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
switch (processType!)
|
||||
{
|
||||
case "T3-SingleSource":
|
||||
{
|
||||
T3SingleSourceProcessor processor = new T3SingleSourceProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
break;
|
||||
}
|
||||
case "T3-MultiSourceSummary":
|
||||
{
|
||||
T3MultiSourceSummaryProcessor processor = new T3MultiSourceSummaryProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
break;
|
||||
}
|
||||
case "T3-MultiSourceCopySelectedCodes":
|
||||
{
|
||||
T3MultiSourceCopySelectedCodesProcessor processor = new T3MultiSourceCopySelectedCodesProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
processor.updateReport();
|
||||
break;
|
||||
}
|
||||
}
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.info,
|
||||
LogType = LogType.process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
} catch (Exception e)
|
||||
ProcessLayer(processWorker);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
@@ -407,7 +291,7 @@ namespace WebAPI.Controllers
|
||||
Message = e.ToString(),
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
@@ -424,6 +308,195 @@ namespace WebAPI.Controllers
|
||||
return BadRequest(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("ProcessLayer/{id}")]
|
||||
public IActionResult ProcessLayer(Guid id)
|
||||
{
|
||||
if (googleSheetValues is null)
|
||||
{
|
||||
throw new Exception("Google Sheets API not initialized");
|
||||
}
|
||||
try
|
||||
{
|
||||
Layer layer = db.Layers
|
||||
.Include(x => x.Records)
|
||||
.Where(x => x.Id == id && !x.IsDeleted).First();
|
||||
if (layer == null)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = "Process error",
|
||||
Type = LogEntryType.error,
|
||||
LogType = LogType.process,
|
||||
Message = "Layer not found",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return BadRequest("Layer not found");
|
||||
}
|
||||
Layer processWorker = db.Layers
|
||||
.Include(x => x.Records)
|
||||
.Where(x => x.Id == layer.ParentId && !x.IsDeleted).First();
|
||||
|
||||
if (processWorker == null)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = "Process error",
|
||||
Type = LogEntryType.error,
|
||||
LogType = LogType.process,
|
||||
Message = "ProcessWorker not found",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return BadRequest("ProcessWorker not found");
|
||||
}
|
||||
ProcessLayer(processWorker, true);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = "Process error",
|
||||
Type = LogEntryType.error,
|
||||
LogType = LogType.process,
|
||||
Message = e.ToString(),
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return BadRequest(e.ToString());
|
||||
}
|
||||
}
|
||||
internal void ProcessLayer(Layer processWorker, bool alwaysProcess = false)
|
||||
{
|
||||
|
||||
string? name = processWorker.Name;
|
||||
string? year = processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
|
||||
if (year == null)
|
||||
{
|
||||
throw new Exception("Year record nod found");
|
||||
}
|
||||
|
||||
if (!alwaysProcess && int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.warning,
|
||||
LogType = LogType.process,
|
||||
Message = "processLayer is out of date. Should be disabled. Not processed.",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
string? processType = processWorker?.Records?.SingleOrDefault(x => x.Code == "ProcessType")?.Desc1;
|
||||
if (processType == null)
|
||||
{
|
||||
throw new Exception("ProcessType record not found");
|
||||
}
|
||||
if (processType == "T3-SourceYearSummary")
|
||||
{
|
||||
if (!alwaysProcess && int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.warning,
|
||||
LogType = LogType.process,
|
||||
Message = "processLayer is out of date. Should be disabled. Not processed",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.info,
|
||||
LogType = LogType.process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (processType == "T3-MultiSourceYearSummary")
|
||||
{
|
||||
if (!alwaysProcess && int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.warning,
|
||||
LogType = LogType.process,
|
||||
Message = "processLayer is out of date. Should be disabled. Not processed",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
T3MultiSourceYearSummaryProcessor processor = new T3MultiSourceYearSummaryProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.info,
|
||||
LogType = LogType.process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
string? month = processWorker?.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1;
|
||||
if (month == null)
|
||||
{
|
||||
throw new Exception("Month record not found");
|
||||
}
|
||||
if (!alwaysProcess && int.Parse(month!) < DateTime.UtcNow.Month)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.warning,
|
||||
LogType = LogType.process,
|
||||
Message = "processLayer is out of date. Should be disabled. Not processed",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
switch (processType!)
|
||||
{
|
||||
case "T3-SingleSource":
|
||||
{
|
||||
T3SingleSourceProcessor processor = new T3SingleSourceProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
break;
|
||||
}
|
||||
case "T3-MultiSourceSummary":
|
||||
{
|
||||
T3MultiSourceSummaryProcessor processor = new T3MultiSourceSummaryProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
break;
|
||||
}
|
||||
case "T3-MultiSourceCopySelectedCodes":
|
||||
{
|
||||
T3MultiSourceCopySelectedCodesProcessor processor = new T3MultiSourceCopySelectedCodesProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
processor.updateReport();
|
||||
break;
|
||||
}
|
||||
}
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.info,
|
||||
LogType = LogType.process,
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
|
||||
internal void SaveRecords(Guid id, ICollection<Record> records, Guid currentUserId)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user