diff --git a/request-management-api/request_api/services/notifications/notificationconfig.py b/request-management-api/request_api/services/notifications/notificationconfig.py index da099251d..7bcc08139 100644 --- a/request-management-api/request_api/services/notifications/notificationconfig.py +++ b/request-management-api/request_api/services/notifications/notificationconfig.py @@ -5,17 +5,30 @@ 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 0 def getnotificationtypeid(self, notificationtype): id = NotificationType().getnotificationtypeid(notificationtype) @@ -23,11 +36,19 @@ def getnotificationtypeid(self, notificationtype): return id['notificationtypeid'] return 0 + # 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 0 def getnotificationusertypeid(self, notificationusertype): id = NotificationUserType().getnotificationusertypesid(notificationusertype) diff --git a/request-management-api/request_api/services/notificationservice.py b/request-management-api/request_api/services/notificationservice.py index 346659bd8..cd518d5e6 100644 --- a/request-management-api/request_api/services/notificationservice.py +++ b/request-management-api/request_api/services/notificationservice.py @@ -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