Manually process layer
This commit is contained in:
@@ -131,4 +131,15 @@ export class Layer extends Base {
|
||||
})
|
||||
})
|
||||
}
|
||||
static processLayer(id: string, _http: HttpClient): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.get<boolean>(`${environment.api.url}/layers/processLayer/${id}`,
|
||||
).subscribe({
|
||||
next: (data) => {
|
||||
resolve(data);
|
||||
},
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
[routerLink]="['/app/layers/Edit/', document.id, 'duplicate']">Duplicate</button>
|
||||
<button mat-button *ngIf="document && document.type === LayerType.Administration"
|
||||
[routerLink]="['/app/layers/Edit/', document.id]">Edit</button>
|
||||
<button mat-button *ngIf="document && document.type === LayerType.Processed"
|
||||
(click)="processLayer()">Process layer</button>
|
||||
</mat-card-title>
|
||||
<mat-card-subtitle> </mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
|
||||
@@ -86,6 +86,14 @@ export class LayerDetailComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
processLayer() {
|
||||
Layer.processLayer(this.document.id!, this.http$).then(() => {
|
||||
this.notifications$.add({
|
||||
text: "Layer processed",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async export() {
|
||||
if (await Layer.exportToGoogleSheet(this.document.id || "", this.http$)) {
|
||||
this.notifications$.add({
|
||||
|
||||
@@ -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;
|
||||
@@ -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
|
||||
@@ -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,6 +279,96 @@ namespace WebAPI.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
ProcessLayer(processWorker);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.error,
|
||||
LogType = LogType.process,
|
||||
Message = e.ToString(),
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
[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)
|
||||
@@ -279,7 +376,7 @@ namespace WebAPI.Controllers
|
||||
throw new Exception("Year record nod found");
|
||||
}
|
||||
|
||||
if (int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
if (!alwaysProcess && int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
@@ -289,7 +386,7 @@ namespace WebAPI.Controllers
|
||||
Message = "processLayer is out of date. Should be disabled. Not processed.",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
string? processType = processWorker?.Records?.SingleOrDefault(x => x.Code == "ProcessType")?.Desc1;
|
||||
@@ -299,7 +396,7 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
if (processType == "T3-SourceYearSummary")
|
||||
{
|
||||
if (int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
if (!alwaysProcess && int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
@@ -309,7 +406,7 @@ namespace WebAPI.Controllers
|
||||
Message = "processLayer is out of date. Should be disabled. Not processed",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
@@ -322,11 +419,11 @@ namespace WebAPI.Controllers
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
if (processType == "T3-MultiSourceYearSummary")
|
||||
{
|
||||
if (int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
if (!alwaysProcess && int.Parse(year!) < DateTime.UtcNow.Year)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
@@ -336,7 +433,7 @@ namespace WebAPI.Controllers
|
||||
Message = "processLayer is out of date. Should be disabled. Not processed",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
T3MultiSourceYearSummaryProcessor processor = new T3MultiSourceYearSummaryProcessor(db, googleSheetValues, this);
|
||||
processor.process(processWorker!);
|
||||
@@ -349,23 +446,24 @@ namespace WebAPI.Controllers
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
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)
|
||||
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.",
|
||||
Message = "processLayer is out of date. Should be disabled. Not processed",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
return;
|
||||
}
|
||||
switch (processType!)
|
||||
{
|
||||
@@ -397,33 +495,8 @@ namespace WebAPI.Controllers
|
||||
Message = "Success",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
} catch (Exception e)
|
||||
{
|
||||
logsController.AddEntry(new LogEntry
|
||||
{
|
||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||
Type = LogEntryType.error,
|
||||
LogType = LogType.process,
|
||||
Message = e.ToString(),
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
}
|
||||
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 SaveRecords(Guid id, ICollection<Record> records, Guid currentUserId)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user