Skip to content

Commit

Permalink
Merge pull request #4979 from bcgov/dev-shiva-4077
Browse files Browse the repository at this point in the history
All notification/user labels must be fetched from cache first
  • Loading branch information
antsand authored Jan 8, 2024
2 parents 765e992 + a65a000 commit 87c3b55
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,56 @@
import os
from request_api.models.NotificationTypes import NotificationType
from request_api.models.NotificationUserTypes import NotificationUserType
notificationuserfile = open('common/notificationusertypes.json', encoding="utf8")
notificationusertypes_cache = json.load(notificationuserfile)

notificationfile = open('common/notificationtypes.json', encoding="utf8")
notificationtypes_cache = json.load(notificationfile)

class notificationconfig:
""" Notfication config
"""

# This method is used to get the notification user type label
# It first tries to get the notification user type label from the cache
# If it is not found in the cache, it fetches it from the DB
def getnotificationtypelabel(self, notificationtype):
id = NotificationType().getnotificationtypeid(notificationtype)
if id is not None:
return id['notificationtypelabel']
return 0
notificationtype_format = notificationtype.replace(" ", "").lower()
if notificationtype_format in notificationtypes_cache:
return notificationtypes_cache[notificationtype_format]['notificationtypelabel']
else:
print("Notification type not found in cache. Fetching from DB", notificationtype)
id = NotificationType().getnotificationtypeid(notificationtype)
if id is not None:
return id['notificationtypelabel']
return None

def getnotificationtypeid(self, notificationtype):
id = NotificationType().getnotificationtypeid(notificationtype)
if id is not None:
return id['notificationtypeid']
return 0
return None

# This method is used to get the notification user type label
# It first tries to get the notification user type label from the cache
# If it is not found in the cache, it fetches it from the DB
def getnotificationusertypelabel(self, notificationusertype):
id = NotificationUserType().getnotificationusertypesid(notificationusertype)
if id is not None:
return id['notificationusertypelabel']
return 0
notificationusertype_format = notificationusertype.replace(" ", "").lower()
if notificationusertype_format in notificationusertypes_cache:
return notificationusertypes_cache[notificationusertype_format]['notificationusertypelabel']
else:
print("Notification user type not found in cache. Fetching from DB", notificationusertype)
id = NotificationUserType().getnotificationusertypesid(notificationusertype)
if id is not None:
return id['notificationusertypelabel']
return None

def getnotificationusertypeid(self, notificationusertype):
id = NotificationUserType().getnotificationusertypesid(notificationusertype)
if id is not None:
return id['notificationusertypeid']
return 0
return None

def getnotificationdays(self):
if 'FOI_NOTIFICATION_DAYS' in os.environ and os.getenv('FOI_NOTIFICATION_DAYS') != '':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,8 @@ def __preparenotification(self, message, requesttype, notificationtype, userid,
notification.idnumber ='U-00' + str(foirequest['requestid'])
mutenotification = False

# in notificationtype remove space and make lower case
notificationtype_format = notificationtype.replace(" ", "").lower()
if notificationtype_format not in notificationtypes_cache:
print('Notification type not found in enum.', notificationtype)
else:
notification.notificationtypelabel = notificationtypes_cache[notificationtype_format]['notificationtypelabel']
notification.notificationtypeid = notificationtypes_cache[notificationtype_format]['notificationtypeid']
notification.notificationtypelabel = notificationconfig().getnotificationtypelabel(notificationtype)
notification.notificationtypeid = notificationconfig().getnotificationtypeid(notificationtype)
notification.axisnumber = foirequest["axisrequestid"]
notification.version = foirequest["version"]
notification.createdby = userid
Expand Down

0 comments on commit 87c3b55

Please sign in to comment.