Skip to content

Commit d7f653d

Browse files
committed
ADDR-132: Add 'Get Global Properties' proxy privilege
1 parent 8299adb commit d7f653d

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
public class AddressHierarchyServiceImpl implements AddressHierarchyService {
4545

4646
protected static final Log log = LogFactory.getLog(AddressHierarchyServiceImpl.class);
47-
47+
48+
private static final String GET_GLOBAL_PROPERTIES = "Get Global Properties";
4849
private AddressHierarchyDAO dao;
4950

5051
private Map<Locale, Map<String,List<String>> > fullAddressCache;
@@ -705,18 +706,26 @@ else if (level.getParent() == null){
705706
synchronized public void initializeFullAddressCache() {
706707

707708
// generally, this global property should be set to true; it just allows cache load to be disabled to speed startup
708-
if (Context.getAdministrationService().getGlobalProperty(AddressHierarchyConstants.GLOBAL_PROP_INITIALIZE_ADDRESS_HIERARCHY_CACHE_ON_STARTUP).equalsIgnoreCase("true")) {
709-
710-
// only initialize if necessary (and if we have entries)
711-
if ((this.fullAddressCacheInitialized == false || MapUtils.isEmpty(this.fullAddressCache))
712-
&& this.getAddressHierarchyEntryCount() > 0) {
713-
714-
this.fullAddressCache = new HashMap<Locale, Map<String,List<String>> >();
715-
Locale locale = i18nCache.getLocaleForFullAddressCache();
716-
getAddressesForLocale(locale);
717-
this.fullAddressCacheInitialized = true;
709+
try {
710+
Context.addProxyPrivilege(GET_GLOBAL_PROPERTIES);
711+
if (Context.getAdministrationService()
712+
.getGlobalProperty(AddressHierarchyConstants.GLOBAL_PROP_INITIALIZE_ADDRESS_HIERARCHY_CACHE_ON_STARTUP)
713+
.equalsIgnoreCase("true")) {
714+
715+
// only initialize if necessary (and if we have entries)
716+
if ((this.fullAddressCacheInitialized == false || MapUtils.isEmpty(this.fullAddressCache))
717+
&& this.getAddressHierarchyEntryCount() > 0) {
718+
719+
this.fullAddressCache = new HashMap<Locale, Map<String, List<String>>>();
720+
Locale locale = i18nCache.getLocaleForFullAddressCache();
721+
getAddressesForLocale(locale);
722+
this.fullAddressCacheInitialized = true;
723+
}
718724
}
719725
}
726+
finally {
727+
Context.removeProxyPrivilege(GET_GLOBAL_PROPERTIES);
728+
}
720729

721730
}
722731

0 commit comments

Comments
 (0)