private void init() { if (!initialized) { Context.getAdministrationService().addGlobalPropertyListener(singleton); String layoutTemplateXml = Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GLOBAL_PROPERTY_ADDRESS_TEMPLATE); setAddressTemplate(layoutTemplateXml); List<String> specialTokens = new ArrayList<>(); specialTokens.add("address1"); specialTokens.add("address2"); specialTokens.add("address3"); specialTokens.add("address4"); specialTokens.add("address5"); specialTokens.add("address6"); specialTokens.add("cityVillage"); specialTokens.add("countyDistrict"); specialTokens.add("stateProvince"); specialTokens.add("country"); specialTokens.add("latitude"); specialTokens.add("longitude"); specialTokens.add("postalCode"); specialTokens.add("startDate"); specialTokens.add("endDate"); setSpecialTokens(specialTokens); initialized = true; } }
@Test public void addGlobalPropertyListener_shouldAddListener() { List<GlobalPropertyListener> listeners = new ArrayList<>(); when(eventListeners.getGlobalPropertyListeners()).thenReturn(listeners); GlobalPropertyListener listener = mock(GlobalPropertyListener.class); adminService.addGlobalPropertyListener(listener); assertThat(listeners.size(), is(1)); assertThat(listeners, contains(listener)); }
@Test public void removeGlobalPropertyListener_shouldRemoveListener() { List<GlobalPropertyListener> listeners = new ArrayList<>(); when(eventListeners.getGlobalPropertyListeners()).thenReturn(listeners); GlobalPropertyListener listener = mock(GlobalPropertyListener.class); adminService.addGlobalPropertyListener(listener); assertThat(listeners.size(), is(1)); assertThat(listeners, contains(listener)); adminService.removeGlobalPropertyListener(listener); assertThat(listeners.size(), is(0)); } }
/** * @see org.openmrs.api.AdministrationService#getAllowedLocales() */ @Override @Transactional(readOnly = true) public List<Locale> getAllowedLocales() { // lazy-load the global locale list and initialize with current global property value if (globalLocaleList == null) { globalLocaleList = new GlobalLocaleList(); Context.getAdministrationService().addGlobalPropertyListener(globalLocaleList); } Set<Locale> allowedLocales = globalLocaleList.getAllowedLocales(); // update the GlobalLocaleList.allowedLocales by faking a global property change if (allowedLocales == null) { // use a default language of "english" if they have cleared this GP for some reason String currentPropertyValue = Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, LocaleUtility.getDefaultLocale().toString()); GlobalProperty allowedLocalesProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, currentPropertyValue); globalLocaleList.globalPropertyChanged(allowedLocalesProperty); allowedLocales = globalLocaleList.getAllowedLocales(); } // allowedLocales is guaranteed to not be null at this point return new ArrayList<>(allowedLocales); }
Context.getAdministrationService().addGlobalPropertyListener(this);