This commit is contained in:
2020-12-22 22:40:21 +00:00
parent 135171d141
commit 6d83a60794
18 changed files with 537 additions and 171 deletions

View File

@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Models;
@@ -11,7 +12,7 @@ using System.Collections.Generic;
namespace AyaNova.Biz
{
internal class WorkOrderBiz : BizObject, IJobObject, ISearchAbleObject
internal class WorkOrderBiz : BizObject, IJobObject, ISearchAbleObject, INotifiableObject
{
//Feature specific roles
internal static AuthorizationRoles RolesAllowedToChangeSerial = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.AccountingFull;
@@ -71,7 +72,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
await WorkOrderSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject;
}
}
@@ -96,7 +97,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
await WorkOrderSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject;
}
@@ -185,7 +186,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct);
await WorkOrderSearchIndexAsync(dbObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
return dbObject;
}
@@ -233,7 +234,7 @@ namespace AyaNova.Biz
}
#endif
await transaction.CommitAsync();
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
}
catch
{
@@ -419,7 +420,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, AyaType.WorkOrderItem, AyaEvent.Created), ct);
await ItemSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject;
}
}
@@ -496,7 +497,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderItem, AyaEvent.Modified), ct);
await ItemSearchIndexAsync(dbObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
return dbObject;
}
@@ -567,7 +568,7 @@ namespace AyaNova.Biz
//all good do the commit if it's ours
if (parentTransaction == null)
await transaction.CommitAsync();
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
}
catch
{
@@ -688,7 +689,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, AyaType.WorkOrderItemExpense, AyaEvent.Created), ct);
await ExpenseSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject;
}
}
@@ -749,7 +750,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderItemExpense, AyaEvent.Modified), ct);
await ExpenseSearchIndexAsync(dbObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
return dbObject;
}
@@ -770,7 +771,7 @@ namespace AyaNova.Biz
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, AyaType.WorkOrderItemExpense, ct);
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
return true;
}
@@ -881,7 +882,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, AyaType.WorkOrderItemLabor, AyaEvent.Created), ct);
await LaborSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject;
}
}
@@ -942,7 +943,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderItemLabor, AyaEvent.Modified), ct);
await LaborSearchIndexAsync(dbObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
return dbObject;
}
@@ -963,7 +964,7 @@ namespace AyaNova.Biz
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, AyaType.WorkOrderItemLabor, ct);
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
return true;
}
@@ -1073,7 +1074,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, AyaType.WorkOrderItemLoan, AyaEvent.Created), ct);
await LoanSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject;
}
}
@@ -1134,7 +1135,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderItemLoan, AyaEvent.Modified), ct);
await LoanSearchIndexAsync(dbObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
return dbObject;
}
@@ -1155,7 +1156,7 @@ namespace AyaNova.Biz
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, AyaType.WorkOrderItemLoan, ct);
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
return true;
}
@@ -1326,7 +1327,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderItemPart, AyaEvent.Modified), ct);
await PartSearchIndexAsync(dbObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
return dbObject;
}
@@ -1347,7 +1348,7 @@ namespace AyaNova.Biz
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, AyaType.WorkOrderItemPart, ct);
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
return true;
}
@@ -1455,7 +1456,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, AyaType.WorkOrderItemPartRequest, AyaEvent.Created), ct);
await PartRequestSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject;
}
}
@@ -1516,7 +1517,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderItemPartRequest, AyaEvent.Modified), ct);
await PartRequestSearchIndexAsync(dbObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
return dbObject;
}
@@ -1537,7 +1538,7 @@ namespace AyaNova.Biz
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, AyaType.WorkOrderItemPartRequest, ct);
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
return true;
}
@@ -1648,7 +1649,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, AyaType.WorkOrderItemScheduledUser, AyaEvent.Created), ct);
await ScheduledUserSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject;
}
}
@@ -1709,7 +1710,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderItemScheduledUser, AyaEvent.Modified), ct);
await ScheduledUserSearchIndexAsync(dbObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
return dbObject;
}
@@ -1730,7 +1731,7 @@ namespace AyaNova.Biz
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, AyaType.WorkOrderItemScheduledUser, ct);
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
return true;
}
@@ -1841,7 +1842,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, AyaType.WorkOrderItemTask, AyaEvent.Created), ct);
await TaskSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject;
}
}
@@ -1902,7 +1903,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderItemTask, AyaEvent.Modified), ct);
await TaskSearchIndexAsync(dbObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
return dbObject;
}
@@ -1923,7 +1924,7 @@ namespace AyaNova.Biz
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, AyaType.WorkOrderItemTask, ct);
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
return true;
}
@@ -2034,7 +2035,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, AyaType.WorkOrderItemTravel, AyaEvent.Created), ct);
await TravelSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject;
}
}
@@ -2095,7 +2096,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderItemTravel, AyaEvent.Modified), ct);
await TravelSearchIndexAsync(dbObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
return dbObject;
}
@@ -2116,7 +2117,7 @@ namespace AyaNova.Biz
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, AyaType.WorkOrderItemTravel, ct);
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
return true;
}
@@ -2227,7 +2228,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, AyaType.WorkOrderItemUnit, AyaEvent.Created), ct);
await UnitSearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject;
}
}
@@ -2288,7 +2289,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, AyaType.WorkOrderItemUnit, AyaEvent.Modified), ct);
await UnitSearchIndexAsync(dbObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
await HandlePotentialNotificationEvent(AyaEvent.Modified, dbObject, SnapshotOfOriginalDBObj);
return dbObject;
}
@@ -2309,7 +2310,7 @@ namespace AyaNova.Biz
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, AyaType.WorkOrderItemUnit, ct);
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
await NotifyEventHelper.HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
return true;
}
@@ -2577,6 +2578,30 @@ namespace AyaNova.Biz
}
////////////////////////////////////////////////////////////////////////////////////////////////
// NOTIFICATION PROCESSING
//
public async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel proposedObj, ICoreBizObjectModel currentObj=null)
{
ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger<WorkOrderBiz>();
if (ServerBootConfig.SEEDING) return;
log.LogDebug($"HandlePotentialNotificationEvent processing: [AyaType:{this.BizType}, AyaEvent:{ayaEvent}]");
bool isNew = currentObj == null;
//STANDARD EVENTS FOR ALL OBJECTS
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
//SPECIFIC EVENTS FOR THIS OBJECT
}//end of process notifications
/////////////////////////////////////////////////////////////////////
}//eoc