This commit is contained in:
@@ -558,7 +558,7 @@ namespace AyaNova.Biz
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
|
||||
//Tag match? (will be true if no sub tags so always safe to call this)
|
||||
if (NotifyEventHelper.TagsMatch(o.Tags, sub.Tags))
|
||||
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags))
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
|
||||
@@ -517,7 +517,7 @@ namespace AyaNova.Biz
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
|
||||
//Tag match? (will be true if no sub tags so always safe to call this)
|
||||
if (NotifyEventHelper.TagsMatch(o.Tags, sub.Tags))
|
||||
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags))
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace AyaNova.Biz
|
||||
{
|
||||
//not for inactive users
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
if (TagsMatch(newObject.Tags, sub.Tags))
|
||||
if (ObjectHasAllSubscriptionTags(newObject.Tags, sub.Tags))
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
@@ -105,7 +105,7 @@ namespace AyaNova.Biz
|
||||
{
|
||||
//not for inactive users
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
if (TagsMatch(newObject.Tags, sub.Tags))
|
||||
if (ObjectHasAllSubscriptionTags(newObject.Tags, sub.Tags))
|
||||
{
|
||||
//Note: age is set by advance notice which is consulted by CoreJobNotify in it's run so the deliver date is not required here only the reference EventDate to check for deliver
|
||||
//ObjectAge is determined by subscription AgeValue in combo with the EventDate NotifyEvent parameter which together determines at what age from notifyevent.EventDate it's considered for the event to have officially occured
|
||||
@@ -143,7 +143,7 @@ namespace AyaNova.Biz
|
||||
{
|
||||
//not for inactive users
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
if (TagsMatch(newObject.Tags, sub.Tags))
|
||||
if (ObjectHasAllSubscriptionTags(newObject.Tags, sub.Tags))
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
@@ -182,7 +182,7 @@ namespace AyaNova.Biz
|
||||
{
|
||||
//not for inactive users
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
if (TagsMatch(bizObject.Tags, sub.Tags))
|
||||
if (ObjectHasAllSubscriptionTags(bizObject.Tags, sub.Tags))
|
||||
{
|
||||
//TODO: On deliver should point to history event log record or take from there and insert into delivery message?
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
@@ -236,7 +236,7 @@ namespace AyaNova.Biz
|
||||
//
|
||||
// A match here means *all* tags in the subscription are present in the object
|
||||
//
|
||||
public static bool TagsMatch(List<string> objectTags, List<string> subTags)
|
||||
public static bool ObjectHasAllSubscriptionTags(List<string> objectTags, List<string> subTags)
|
||||
{
|
||||
//no subscription tags? Then it always will match
|
||||
if (subTags.Count == 0) return true;
|
||||
@@ -250,6 +250,23 @@ namespace AyaNova.Biz
|
||||
return subTags.All(z => objectTags.Any(x => x == z));
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
// COMPARE TAGS COLLECTION
|
||||
//
|
||||
// A match here means *all* tags are the same in both objects (don't have to be in same order)
|
||||
//
|
||||
public static bool TwoObjectsHaveSameTags(List<string> firstObjectTags, List<string> secondObjectTags)
|
||||
{
|
||||
//no tags on either side?
|
||||
if (firstObjectTags.Count == 0 && secondObjectTags.Count == 0) return true;
|
||||
|
||||
//different counts will always mean not a match
|
||||
if (firstObjectTags.Count != secondObjectTags.Count) return false;
|
||||
|
||||
//Do ALL the tags in the first object exist in the second object?
|
||||
return firstObjectTags.All(z => secondObjectTags.Any(x => x == z));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
// CREATE OPS PROBLEM EVENT
|
||||
//
|
||||
@@ -346,7 +363,7 @@ namespace AyaNova.Biz
|
||||
|
||||
foreach (var sub in subs)
|
||||
{
|
||||
//not for inactive users
|
||||
//not for inactive users
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
//note flag ~SERVER~ means to client to substitute "Server" translation key text instead
|
||||
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = sub.UserId, Message = message, NotifySubscriptionId = sub.Id, Name = "~SERVER~" };
|
||||
|
||||
@@ -531,7 +531,7 @@ namespace AyaNova.Biz
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
|
||||
//Tag match? (will be true if no sub tags so always safe to call this)
|
||||
if (NotifyEventHelper.TagsMatch(o.Tags, sub.Tags))
|
||||
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags))
|
||||
{
|
||||
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
@@ -565,7 +565,7 @@ namespace AyaNova.Biz
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
|
||||
//Tag match? (will be true if no sub tags so always safe to call this)
|
||||
if (NotifyEventHelper.TagsMatch(o.Tags, sub.Tags))
|
||||
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags))
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
|
||||
@@ -986,14 +986,25 @@ namespace AyaNova.Biz
|
||||
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
|
||||
|
||||
//SPECIFIC EVENTS FOR THIS OBJECT
|
||||
WorkOrder o = (WorkOrder)proposedObj;
|
||||
WorkOrder oProposed = (WorkOrder)proposedObj;
|
||||
WorkOrder oCurrent = null;
|
||||
bool SameTags = true;
|
||||
if (currentObj != null)
|
||||
{
|
||||
oCurrent = (WorkOrder)currentObj;
|
||||
SameTags = NotifyEventHelper.TwoObjectsHaveSameTags(proposedObj.Tags, currentObj.Tags);
|
||||
}
|
||||
|
||||
|
||||
//OVERDUE TO COMPLETION
|
||||
if (ayaEvent == AyaEvent.Created)
|
||||
//OVERDUE COMPLETION
|
||||
if (ayaEvent == AyaEvent.Created && oProposed.CompleteByDate != null)
|
||||
{// WorkorderCompletedStatusOverdue Created here on workorder creation for any subscribers
|
||||
// State notify event processor below has more notes and details and will remove this event if set to a completed state
|
||||
|
||||
|
||||
//If new and has completeby then can do notification
|
||||
|
||||
|
||||
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.WorkorderCompletedStatusOverdue).ToListAsync();
|
||||
|
||||
foreach (var sub in subs)
|
||||
@@ -1002,18 +1013,18 @@ namespace AyaNova.Biz
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
|
||||
//Tag match? (will be true if no sub tags so always safe to call this)
|
||||
if (NotifyEventHelper.TagsMatch(o.Tags, sub.Tags))
|
||||
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags))
|
||||
{
|
||||
var OverdueDate = DateTime.UtcNow.Add(sub.AgeValue);//age value is how long the user wants to wait before workorder is considered overdue
|
||||
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.WorkorderCompletedStatusOverdue,
|
||||
UserId = sub.UserId,
|
||||
AyaType = o.AyaType,
|
||||
ObjectId = o.Id,
|
||||
AyaType = proposedObj.AyaType,
|
||||
ObjectId = proposedObj.Id,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
Name = o.Serial.ToString(),
|
||||
EventDate = OverdueDate
|
||||
Name = oProposed.Serial.ToString(),
|
||||
EventDate = (DateTime)oProposed.CompleteByDate
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
@@ -1021,7 +1032,48 @@ namespace AyaNova.Biz
|
||||
}
|
||||
}
|
||||
|
||||
}//overdue event
|
||||
}//CREATED overdue completion
|
||||
|
||||
if (ayaEvent == AyaEvent.Modified)
|
||||
{// WorkorderCompletedStatusOverdue modified in some way, could be tags, could be date either of which is relevant to this notification block
|
||||
|
||||
//differences requiring re-processing of notification??
|
||||
if (oProposed.CompleteByDate != oCurrent.CompleteByDate || !SameTags)
|
||||
{
|
||||
await NotifyEventHelper.ClearPriorEventsForObject(ct, proposedObj.AyaType, proposedObj.Id, NotifyEventType.WorkorderCompletedStatusOverdue);
|
||||
|
||||
//new has date?
|
||||
if (oProposed.CompleteByDate != null)
|
||||
{
|
||||
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.WorkorderCompletedStatusOverdue).ToListAsync();
|
||||
|
||||
foreach (var sub in subs)
|
||||
{
|
||||
//not for inactive users
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
|
||||
//Tag match? (will be true if no sub tags so always safe to call this)
|
||||
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(proposedObj.Tags, sub.Tags))
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
EventType = NotifyEventType.WorkorderCompletedStatusOverdue,
|
||||
UserId = sub.UserId,
|
||||
AyaType = proposedObj.AyaType,
|
||||
ObjectId = proposedObj.Id,
|
||||
NotifySubscriptionId = sub.Id,
|
||||
Name = oProposed.Serial.ToString(),
|
||||
EventDate = (DateTime)oProposed.CompleteByDate
|
||||
};
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}//CREATED overdue completion
|
||||
|
||||
|
||||
|
||||
@@ -1223,7 +1275,7 @@ namespace AyaNova.Biz
|
||||
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||
|
||||
//Tag match? (will be true if no sub tags so always safe to call this)
|
||||
if (NotifyEventHelper.TagsMatch(wo.Tags, sub.Tags))
|
||||
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(wo.Tags, sub.Tags))
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user