From 02608a4dd03b8b9766637cb00ef4753ed825b8dc Mon Sep 17 00:00:00 2001 From: Seremba Patrick Date: Wed, 6 Mar 2024 05:04:53 +0300 Subject: [PATCH] ADDR-132: Add and Remove 'Get Global Properties' proxy privilege --- .../service/AddressHierarchyServiceImpl.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java b/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java index 8499f69..53faa8d 100644 --- a/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java @@ -705,19 +705,26 @@ else if (level.getParent() == null){ synchronized public void initializeFullAddressCache() { // generally, this global property should be set to true; it just allows cache load to be disabled to speed startup - Context.addProxyPrivilege("Get Global Properties"); - if (Context.getAdministrationService().getGlobalProperty(AddressHierarchyConstants.GLOBAL_PROP_INITIALIZE_ADDRESS_HIERARCHY_CACHE_ON_STARTUP).equalsIgnoreCase("true")) { - - // only initialize if necessary (and if we have entries) - if ((this.fullAddressCacheInitialized == false || MapUtils.isEmpty(this.fullAddressCache)) - && this.getAddressHierarchyEntryCount() > 0) { - - this.fullAddressCache = new HashMap> >(); - Locale locale = i18nCache.getLocaleForFullAddressCache(); - getAddressesForLocale(locale); - this.fullAddressCacheInitialized = true; + try { + Context.addProxyPrivilege("Get Global Properties"); + if (Context.getAdministrationService() + .getGlobalProperty(AddressHierarchyConstants.GLOBAL_PROP_INITIALIZE_ADDRESS_HIERARCHY_CACHE_ON_STARTUP) + .equalsIgnoreCase("true")) { + + // only initialize if necessary (and if we have entries) + if ((this.fullAddressCacheInitialized == false || MapUtils.isEmpty(this.fullAddressCache)) + && this.getAddressHierarchyEntryCount() > 0) { + + this.fullAddressCache = new HashMap>>(); + Locale locale = i18nCache.getLocaleForFullAddressCache(); + getAddressesForLocale(locale); + this.fullAddressCacheInitialized = true; + } } } + finally { + Context.removeProxyPrivilege("Get Global Properties"); + } }