/** * @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); }
/** * @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); }
/** * 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 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()); } }
/** * 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()); }
/** * Constructor to give the end user a helpful message that relates to why this error occurred. * * @param messageKey message code to retrieve * @param parameters message parameters */ public APIException(String messageKey, Object[] parameters) { super(Context.getMessageSourceService().getMessage(messageKey, parameters, Context.getLocale())); }
@Test public void getMessageSourceService_shouldNotThrowServiceNotFoundException() { Context.getMessageSourceService(); } }
@Test public void parse_shouldParseValidLogicModuleFromFile() { File moduleFile = new File(getClass().getClassLoader().getResource(LOGIC_MODULE_PATH).getPath()); ModuleFileParser parser = new ModuleFileParser(Context.getMessageSourceService()); Module module = parser.parse(moduleFile); assertThat(module.getModuleId(), is("logic")); assertThat(module.getVersion(), is("0.2")); assertThat(module.getPackageName(), is("org.openmrs.logic")); assertThat(module.getActivatorName(), is("org.openmrs.logic.LogicModuleActivator")); assertThat(module.getMappingFiles().size(), is(1)); assertThat(module.getMappingFiles(), hasItems("LogicRuleToken.hbm.xml")); }
@Before public void setup() { userService = Context.getUserService(); messages = Context.getMessageSourceService(); }
@Test public void getPresentationLocales_shouldNotReturnMoreLocalesThanMessageSourceServiceLocales() { assertFalse(adminService.getPresentationLocales().size() > Context .getMessageSourceService().getLocales().size()); }
private Patient getPatient(PID pid) throws HL7Exception { Integer patientId = Context.getHL7Service().resolvePatientId(pid); if (patientId == null) { throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.UnresolvedPatient")); } return Context.getPatientService().getPatient(patientId); }
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 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 ConceptService#getDrugByMapping(String, org.openmrs.ConceptSource, java.util.Collection */ @Test public void getDrugByMapping_shouldFailIfSourceIsNull() { expectedException.expect(APIException.class); expectedException.expectMessage(Context.getMessageSourceService().getMessage("ConceptSource.is.required")); conceptService.getDrugByMapping("random", null, null); }
/** * @see OrderTypeValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldBeInvokedWhenAnOrderTypeIsSaved() { OrderType orderType = orderService.getOrderType(1); orderType.setName(null); expectedException.expect(APIException.class); String expectedMsg = "'" + orderType + "' failed to validate with reason: name: " + Context.getMessageSourceService().getMessage("error.name"); expectedException.expectMessage(expectedMsg); orderService.saveOrderType(orderType); }