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>
|
[routerLink]="['/app/layers/Edit/', document.id, 'duplicate']">Duplicate</button>
|
||||||
<button mat-button *ngIf="document && document.type === LayerType.Administration"
|
<button mat-button *ngIf="document && document.type === LayerType.Administration"
|
||||||
[routerLink]="['/app/layers/Edit/', document.id]">Edit</button>
|
[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-title>
|
||||||
<mat-card-subtitle> </mat-card-subtitle>
|
<mat-card-subtitle> </mat-card-subtitle>
|
||||||
</mat-card-header>
|
</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() {
|
async export() {
|
||||||
if (await Layer.exportToGoogleSheet(this.document.id || "", this.http$)) {
|
if (await Layer.exportToGoogleSheet(this.document.id || "", this.http$)) {
|
||||||
this.notifications$.add({
|
this.notifications$.add({
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ namespace WebAPI.Controllers
|
|||||||
IConfiguration _configuration)
|
IConfiguration _configuration)
|
||||||
{
|
{
|
||||||
db = _db;
|
db = _db;
|
||||||
if (_googleSheetsHelper.Service is not null) {
|
if (_googleSheetsHelper.Service is not null)
|
||||||
|
{
|
||||||
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
googleSheetValues = _googleSheetsHelper.Service.Spreadsheets.Values;
|
||||||
}
|
}
|
||||||
googleSheetsHelper = _googleSheetsHelper;
|
googleSheetsHelper = _googleSheetsHelper;
|
||||||
@@ -44,7 +45,7 @@ namespace WebAPI.Controllers
|
|||||||
IQueryable<Layer> response = db.Layers.Where(x => !x.IsDeleted);
|
IQueryable<Layer> response = db.Layers.Where(x => !x.IsDeleted);
|
||||||
if (name != null)
|
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)
|
if (type != null)
|
||||||
{
|
{
|
||||||
@@ -78,7 +79,8 @@ namespace WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{id}")] public IActionResult Get(Guid id)
|
[Route("{id}")]
|
||||||
|
public IActionResult Get(Guid id)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -116,7 +118,8 @@ namespace WebAPI.Controllers
|
|||||||
[Route("exportToGoogleSheet/{id}")]
|
[Route("exportToGoogleSheet/{id}")]
|
||||||
public IActionResult ExportToGoogleSheet(Guid id)
|
public IActionResult ExportToGoogleSheet(Guid id)
|
||||||
{
|
{
|
||||||
if (googleSheetValues is null) {
|
if (googleSheetValues is null)
|
||||||
|
{
|
||||||
throw new Exception("Google Sheets API not initialized");
|
throw new Exception("Google Sheets API not initialized");
|
||||||
}
|
}
|
||||||
Layer layer = db.Layers
|
Layer layer = db.Layers
|
||||||
@@ -137,7 +140,8 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
if (googleSheetValues is null) {
|
if (googleSheetValues is null)
|
||||||
|
{
|
||||||
throw new Exception("Google Sheets API not initialized");
|
throw new Exception("Google Sheets API not initialized");
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
@@ -205,7 +209,8 @@ namespace WebAPI.Controllers
|
|||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch(Exception e)
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
@@ -218,7 +223,8 @@ namespace WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok();
|
return Ok();
|
||||||
} catch(Exception e)
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
@@ -240,7 +246,8 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
if (googleSheetValues is null) {
|
if (googleSheetValues is null)
|
||||||
|
{
|
||||||
throw new Exception("Google Sheets API not initialized");
|
throw new Exception("Google Sheets API not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,6 +279,96 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
try
|
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? name = processWorker.Name;
|
||||||
string? year = processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
|
string? year = processWorker?.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1;
|
||||||
if (year == null)
|
if (year == null)
|
||||||
@@ -279,7 +376,7 @@ namespace WebAPI.Controllers
|
|||||||
throw new Exception("Year record nod found");
|
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
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
@@ -289,7 +386,7 @@ namespace WebAPI.Controllers
|
|||||||
Message = "processLayer is out of date. Should be disabled. Not processed.",
|
Message = "processLayer is out of date. Should be disabled. Not processed.",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string? processType = processWorker?.Records?.SingleOrDefault(x => x.Code == "ProcessType")?.Desc1;
|
string? processType = processWorker?.Records?.SingleOrDefault(x => x.Code == "ProcessType")?.Desc1;
|
||||||
@@ -299,7 +396,7 @@ namespace WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
if (processType == "T3-SourceYearSummary")
|
if (processType == "T3-SourceYearSummary")
|
||||||
{
|
{
|
||||||
if (int.Parse(year!) < DateTime.UtcNow.Year)
|
if (!alwaysProcess && int.Parse(year!) < DateTime.UtcNow.Year)
|
||||||
{
|
{
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
@@ -309,7 +406,7 @@ namespace WebAPI.Controllers
|
|||||||
Message = "processLayer is out of date. Should be disabled. Not processed",
|
Message = "processLayer is out of date. Should be disabled. Not processed",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
|
T3SourceYearSummaryProcessor processor = new T3SourceYearSummaryProcessor(db, googleSheetValues, this);
|
||||||
processor.process(processWorker!);
|
processor.process(processWorker!);
|
||||||
@@ -322,11 +419,11 @@ namespace WebAPI.Controllers
|
|||||||
Message = "Success",
|
Message = "Success",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
if (processType == "T3-MultiSourceYearSummary")
|
if (processType == "T3-MultiSourceYearSummary")
|
||||||
{
|
{
|
||||||
if (int.Parse(year!) < DateTime.UtcNow.Year)
|
if (!alwaysProcess && int.Parse(year!) < DateTime.UtcNow.Year)
|
||||||
{
|
{
|
||||||
logsController.AddEntry(new LogEntry
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
@@ -336,7 +433,7 @@ namespace WebAPI.Controllers
|
|||||||
Message = "processLayer is out of date. Should be disabled. Not processed",
|
Message = "processLayer is out of date. Should be disabled. Not processed",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
T3MultiSourceYearSummaryProcessor processor = new T3MultiSourceYearSummaryProcessor(db, googleSheetValues, this);
|
T3MultiSourceYearSummaryProcessor processor = new T3MultiSourceYearSummaryProcessor(db, googleSheetValues, this);
|
||||||
processor.process(processWorker!);
|
processor.process(processWorker!);
|
||||||
@@ -349,23 +446,24 @@ namespace WebAPI.Controllers
|
|||||||
Message = "Success",
|
Message = "Success",
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
string? month = processWorker?.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1;
|
string? month = processWorker?.Records?.SingleOrDefault(x => x.Code == "Month")?.Desc1;
|
||||||
if (month == null)
|
if (month == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Month record not found");
|
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
|
logsController.AddEntry(new LogEntry
|
||||||
{
|
{
|
||||||
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
Title = $"{processWorker!.Name}, {processWorker.Id}",
|
||||||
Type = LogEntryType.warning,
|
Type = LogEntryType.warning,
|
||||||
LogType = LogType.process,
|
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
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
switch (processType!)
|
switch (processType!)
|
||||||
{
|
{
|
||||||
@@ -397,33 +495,8 @@ namespace WebAPI.Controllers
|
|||||||
Message = "Success",
|
Message = "Success",
|
||||||
CreatedAt = DateTime.UtcNow
|
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)
|
internal void SaveRecords(Guid id, ICollection<Record> records, Guid currentUserId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user