/** * @see org.openmrs.api.handler.ExistingVisitAssignmentHandler#getDisplayName(java.util.Locale) */ @Override public String getDisplayName(Locale locale) { return Context.getMessageSourceService().getMessage("visit.assignmentHandler.assignToExistingVisitOrNew", null, locale); }
if (presentationLocales == null) { presentationLocales = new LinkedHashSet<>(); Collection<Locale> messageLocales = Context.getMessageSourceService().getLocales(); List<Locale> allowedLocales = getAllowedLocales();
@Test public void getPresentationLocales_shouldReturnOnlyCountryLocaleIfBothCountryLocaleAndLanguageLocaleAreSpecifiedInAllowedList() { adminService.saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, es, es_CL")); List<Locale> locales = new ArrayList<>(); locales.add(new Locale("pl", "PL")); locales.add(new Locale("en")); locales.add(new Locale("es")); locales.add(new Locale("es", "CL")); MutableResourceBundleMessageSource mutableResourceBundleMessageSource = Mockito .mock(MutableResourceBundleMessageSource.class); Mockito.when(mutableResourceBundleMessageSource.getLocales()).thenReturn(locales); MutableMessageSource mutableMessageSource = Context.getMessageSourceService().getActiveMessageSource(); Context.getMessageSourceService().setActiveMessageSource(mutableResourceBundleMessageSource); Set<Locale> presentationLocales = adminService.getPresentationLocales(); Context.getMessageSourceService().setActiveMessageSource(mutableMessageSource); assertEquals(2, presentationLocales.size()); assertTrue("en", presentationLocales.contains(new Locale("en"))); assertTrue("es_CL", presentationLocales.contains(new Locale("es", "CL"))); }
@Test public void getPresentationLocales_shouldReturnLanguageLocaleIfItIsSpecifiedInAllowedListAndThereAreNoCountryLocaleMessageFilesAvailable() { adminService.saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, es")); List<Locale> locales = new ArrayList<>(); locales.add(new Locale("pl", "PL")); locales.add(new Locale("en")); locales.add(new Locale("es")); MutableResourceBundleMessageSource mutableResourceBundleMessageSource = Mockito .mock(MutableResourceBundleMessageSource.class); Mockito.when(mutableResourceBundleMessageSource.getLocales()).thenReturn(locales); MutableMessageSource mutableMessageSource = Context.getMessageSourceService().getActiveMessageSource(); Context.getMessageSourceService().setActiveMessageSource(mutableResourceBundleMessageSource); Set<Locale> presentationLocales = adminService.getPresentationLocales(); Context.getMessageSourceService().setActiveMessageSource(mutableMessageSource); assertEquals(2, presentationLocales.size()); assertTrue("en", presentationLocales.contains(new Locale("en"))); assertTrue("es", presentationLocales.contains(new Locale("es"))); }
private void validateFileIsNotNull(File moduleFile) { if (moduleFile == null) { throw new ModuleException(messageSourceService.getMessage("Module.error.fileCannotBeNull")); } }
@Test public void getPresentationLocales_shouldReturnAllCountryLocalesIfLanguageLocaleAndNoCountryLocalesAreSpecifiedInAllowedList() { adminService.saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, es")); List<Locale> locales = new ArrayList<>(); locales.add(new Locale("pl", "PL")); locales.add(new Locale("en")); locales.add(new Locale("es")); locales.add(new Locale("es", "CL")); locales.add(new Locale("es", "SN")); MutableResourceBundleMessageSource mutableResourceBundleMessageSource = Mockito .mock(MutableResourceBundleMessageSource.class); Mockito.when(mutableResourceBundleMessageSource.getLocales()).thenReturn(locales); MutableMessageSource mutableMessageSource = Context.getMessageSourceService().getActiveMessageSource(); Context.getMessageSourceService().setActiveMessageSource(mutableResourceBundleMessageSource); Set<Locale> presentationLocales = adminService.getPresentationLocales(); Context.getMessageSourceService().setActiveMessageSource(mutableMessageSource); assertEquals(3, presentationLocales.size()); assertTrue("es_CL", presentationLocales.contains(new Locale("es", "CL"))); assertTrue("es_SN", presentationLocales.contains(new Locale("es", "SN"))); assertTrue("en", presentationLocales.contains(new Locale("en"))); }
@Test public void getPresentationLocales_shouldNotReturnMoreLocalesThanMessageSourceServiceLocales() { assertFalse(adminService.getPresentationLocales().size() > Context .getMessageSourceService().getLocales().size()); }
private void validateFileHasModuleFileExtension(File moduleFile) { if (!moduleFile.getName().endsWith(OPENMRS_MODULE_FILE_EXTENSION)) { throw new ModuleException(messageSourceService.getMessage("Module.error.invalidFileExtension"), moduleFile.getName()); } }
@Test public void getPresentationLocales_shouldReturnLanguageLocaleIfCountryLocaleIsSpecifiedInAllowedListButCountryLocaleMessageFileIsMissing() { adminService.saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB, es_CL")); List<Locale> locales = new ArrayList<>(); locales.add(new Locale("pl", "PL")); locales.add(new Locale("en")); locales.add(new Locale("es")); MutableResourceBundleMessageSource mutableResourceBundleMessageSource = Mockito .mock(MutableResourceBundleMessageSource.class); Mockito.when(mutableResourceBundleMessageSource.getLocales()).thenReturn(locales); MutableMessageSource mutableMessageSource = Context.getMessageSourceService().getActiveMessageSource(); Context.getMessageSourceService().setActiveMessageSource(mutableResourceBundleMessageSource); Set<Locale> presentationLocales = adminService.getPresentationLocales(); Context.getMessageSourceService().setActiveMessageSource(mutableMessageSource); assertEquals(2, presentationLocales.size()); assertTrue("en", presentationLocales.contains(new Locale("en"))); assertTrue("es", presentationLocales.contains(new Locale("es"))); }
private ZipEntry getConfigXmlZipEntry(JarFile jarfile, File moduleFile) { ZipEntry config = jarfile.getEntry(MODULE_CONFIG_XML_FILENAME); if (config == null) { throw new ModuleException(messageSourceService.getMessage("Module.error.noConfigFile"), moduleFile.getName()); } return config; }
Mockito.when(mutableResourceBundleMessageSource.getLocales()).thenReturn(locales); MutableMessageSource mutableMessageSource = Context.getMessageSourceService().getActiveMessageSource(); Context.getMessageSourceService().setActiveMessageSource(mutableResourceBundleMessageSource); Context.getMessageSourceService().setActiveMessageSource(mutableMessageSource);
/** * @see org.openmrs.api.handler.EncounterVisitHandler#getDisplayName(java.util.Locale) */ @Override public String getDisplayName(Locale locale) { return Context.getMessageSourceService().getMessage("visit.assignmentHandler.assignToExistingVisitOnly", null, locale); }
private File createTempFile(String prefix, String suffix) { File file; try { file = File.createTempFile(prefix, suffix); } catch (IOException e) { throw new ModuleException(messageSourceService.getMessage("Module.error.cannotCreateFile"), e); } return file; }
@Override public String getDisplayName(Locale locale) { return Context.getMessageSourceService().getMessage("Visit.assignmentHandler.noAssignment", null, locale); }
public InvalidActivationKeyException(String message) { super(Context.getMessageSourceService().getMessage(message)); }
/** * Throws an APIAuthorization exception stating why the user failed * * @param user authenticated user * @param method acting method * @param attrs Collection of String privilege names that the user must have */ private void throwUnauthorized(User user, Method method, Collection<String> attrs) { log.debug(USER_IS_NOT_AUTHORIZED_TO_ACCESS, user, method.getName()); throw new APIAuthenticationException(Context.getMessageSourceService().getMessage("error.privilegesRequired", new Object[] { StringUtils.join(attrs, ",") }, null)); }
/** * Throws an APIAuthorization exception stating why the user failed * * @param user authenticated user * @param method acting method * @param attrs privilege names that the user must have */ private void throwUnauthorized(User user, Method method, String attr) { log.debug(USER_IS_NOT_AUTHORIZED_TO_ACCESS, user, method.getName()); throw new APIAuthenticationException(Context.getMessageSourceService().getMessage("error.privilegesRequired", new Object[] { attr }, null)); }
private Document parseConfigXml(JarFile jarfile, ZipEntry configEntry, File moduleFile) { Document config; try (InputStream configStream = jarfile.getInputStream(configEntry)) { config = parseConfigXmlStream(configStream, moduleFile); } catch (IOException e) { throw new ModuleException(messageSourceService.getMessage( "Module.error.cannotGetConfigFileStream"), moduleFile.getName(), e); } return config; }
/** * Throws an APIAuthorization exception stating why the user failed * * @param user authenticated user * @param method acting method */ private void throwUnauthorized(User user, Method method) { log.debug(USER_IS_NOT_AUTHORIZED_TO_ACCESS, user, method.getName()); throw new APIAuthenticationException(Context.getMessageSourceService().getMessage("error.aunthenticationRequired")); } }
private String getTrimmedElementOrFail(Element rootNode, String elementName, String errorMessageKey, String moduleName) { String element = getElementTrimmed(rootNode, elementName); if (element == null || element.length() == 0) { throw new ModuleException(messageSourceService.getMessage(errorMessageKey), moduleName); } return element; }