/** * @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); }
private void validateFileIsNotNull(File moduleFile) { if (moduleFile == null) { throw new ModuleException(messageSourceService.getMessage("Module.error.fileCannotBeNull")); } }
private void validateFileHasModuleFileExtension(File moduleFile) { if (!moduleFile.getName().endsWith(OPENMRS_MODULE_FILE_EXTENSION)) { throw new ModuleException(messageSourceService.getMessage("Module.error.invalidFileExtension"), moduleFile.getName()); } }
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; }
/** * 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; }
private void validateModuleConfigVersion(String version, File moduleFile) { if (!validConfigVersions.contains(version)) { throw new ModuleException(Context.getMessageSourceService().getMessage("Module.error.invalidConfigVersion", new Object[] { version, String.join(", ", validConfigVersions) }, Context.getLocale()), moduleFile.getName()); } }
private Document getModuleConfigXml(File moduleFile) { Document config; try (JarFile jarfile = new JarFile(moduleFile)) { ZipEntry configEntry = getConfigXmlZipEntry(jarfile, moduleFile); config = parseConfigXml(jarfile, configEntry, moduleFile); } catch (IOException e) { throw new ModuleException(messageSourceService.getMessage("Module.error.cannotGetJarFile"), moduleFile.getName(), e); } return config; }
/** * Gets the error message of cyclic dependencies between modules * * @return the message text. */ private static String getCyclicDependenciesMessage(String message) { return Context.getMessageSourceService().getMessage("Module.error.cyclicDependencies", new Object[]{ message }, Context.getLocale()); }
private User getEnterer(ORC orc) throws HL7Exception { XCN hl7Enterer = orc.getEnteredBy(0); Integer entererId = Context.getHL7Service().resolveUserId(hl7Enterer); if (entererId == null) { throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.UnresolvedEnterer")); } User enterer = new User(); enterer.setUserId(entererId); return enterer; }
/** * @see HandlerUtil#getPreferredHandler(Class, Class) */ @Test public void getPreferredHandler_shouldThrowAAPIExceptionExceptionIfNoHandlerIsFound() { thrown.expect(APIException.class); thrown.expectMessage(Context.getMessageSourceService().getMessage("handler.type.not.found", new Object[] { Validator.class.toString(), Integer.class }, null)); HandlerUtil.getPreferredHandler(Validator.class, Integer.class); }
@Test public void shouldFailIfAnEditedOrderIsFlushed() { Encounter encounter = encounterService.getEncounter(3); assertFalse(encounter.getOrders().isEmpty()); encounter.getOrders().iterator().next().setInstructions("new"); expectedException.expect(APIException.class); expectedException.expectMessage(Matchers.is(Context.getMessageSourceService().getMessage("editing.fields.not.allowed", new Object[] { "[instructions]", Order.class.getSimpleName() }, null))); encounterService.saveEncounter(encounter); Context.flushSession(); }
@Test public void getUserByUsernameOrEmail_shouldFailIfEmailIsWhiteSpace() { expectedException.expect(APIException.class); expectedException.expectMessage(messages.getMessage("error.usernameOrEmail.notNullOrBlank")); userService.getUserByUsernameOrEmail(" "); }
@Test public void addToDate_shouldFailWhenUnitIsUnknown() throws ParseException { Duration duration = new Duration(3, "J"); expectedException.expect(APIException.class); expectedException.expectMessage(Matchers.is(Context.getMessageSourceService().getMessage("Duration.unknown.code", new Object[] { "J" }, null))); duration.addToDate(createDateTime("2014-07-01 10:00:00"), null); }
@Test public void notifySuperUsers_shouldAddAnAlertWithMessageTextIfCauseIsNull() { Context.getAlertService().notifySuperUsers("Module.startupError.notification.message", null, "test"); Alert lastAlert = Context.getAlertService().getAlertsByUser(null).iterator().next(); String expectedText = Context.getMessageSourceService().getMessage("Module.startupError.notification.message", new Object[] { "test" }, Context.getLocale()); Assert.assertEquals(expectedText, lastAlert.getText()); }
@Test public void addToDate_shouldFailWhenUnitIsRecurringAndFrequencyIsUnknown() throws ParseException { Duration duration = new Duration(3, Duration.SNOMED_CT_RECURRING_INTERVAL_CODE); // 3 Times Date startDate = createDateTime("2014-07-01 10:00:00"); OrderFrequency frequency = null; expectedException.expect(APIException.class); expectedException.expectMessage(Matchers.is(Context.getMessageSourceService().getMessage("Duration.error.frequency.null"))); duration.addToDate(startDate, frequency); }
/** * @see OrderService#purgeOrderType(org.openmrs.OrderType) */ @Test public void purgeOrderType_shouldNotAllowDeletingAnOrderTypeThatIsInUse() { OrderType orderType = orderService.getOrderType(1); assertNotNull(orderType); expectedException.expect(CannotDeleteObjectInUseException.class); expectedException.expectMessage(mss.getMessage("Order.type.cannot.delete")); orderService.purgeOrderType(orderType); }
@Test public void changePassword_shouldNotUpdatePasswordOfGivenUserWhenLoggedInUserDoesNotHaveEditUsersPasswordPrivilege() { executeDataSet(XML_FILENAME_WITH_DATA_FOR_CHANGE_PASSWORD_ACTION); User user = userService.getUser(6001); assertFalse(user.hasPrivilege(PrivilegeConstants.EDIT_USER_PASSWORDS)); Context.authenticate(user.getUsername(), "userServiceTest"); expectedException.expect(APIAuthenticationException.class); expectedException.expectMessage( messages.getMessage("error.privilegesRequired", new Object[] {PrivilegeConstants.EDIT_USER_PASSWORDS}, null)); userService.changePassword(user, "testTest123"); }
@Test public void changePasswordUsingSecretAnswer_shouldNotUpdatePasswordIfSecretIsNotCorrect() { executeDataSet(XML_FILENAME_WITH_DATA_FOR_CHANGE_PASSWORD_ACTION); User user = userService.getUser(6001); assertFalse(user.hasPrivilege(PrivilegeConstants.EDIT_USER_PASSWORDS)); Context.authenticate(user.getUsername(), "userServiceTest"); expectedException.expect(APIException.class); expectedException.expectMessage(messages.getMessage("secret.answer.not.correct")); userService.changePasswordUsingSecretAnswer("wrong answer", "userServiceTest2"); }