/** * @see org.openmrs.api.UserService#getUsersByRole(org.openmrs.Role) */ @Override @Transactional(readOnly = true) public List<User> getUsersByRole(Role role) throws APIException { List<Role> roles = new ArrayList<>(); roles.add(role); return Context.getUserService().getUsers(null, roles, false); }
/** * @see org.openmrs.api.UserService#voidUser(org.openmrs.User, java.lang.String) */ public User voidUser(User user, String reason) throws APIException { return Context.getUserService().retireUser(user, reason); }
/** * @see org.openmrs.api.UserService#unvoidUser(org.openmrs.User) */ public User unvoidUser(User user) throws APIException { return Context.getUserService().unretireUser(user); }
@Override protected User getObjectByUuid(String uuid) { return Context.getUserService().getUserByUuid(uuid); } }
/** * @see org.openmrs.Attributable#findPossibleValues(java.lang.String) */ @Override public List<User> findPossibleValues(String searchText) { try { return Context.getUserService().getUsersByName(searchText, "", false); } catch (Exception e) { return Collections.emptyList(); } }
/** * @see org.openmrs.Attributable#getPossibleValues() */ @Override public List<User> getPossibleValues() { try { return Context.getUserService().getAllUsers(); } catch (Exception e) { return Collections.emptyList(); } }
/** * @see org.openmrs.api.UserService#getUsers(java.lang.String, java.util.List, boolean) */ @Override @Transactional(readOnly = true) public List<User> getUsers(String nameSearch, List<Role> roles, boolean includeVoided) throws APIException { return Context.getUserService().getUsers(nameSearch, roles, includeVoided, null, null); }
/** * Sends a message to a group of users identifier by their role. */ @Override public void sendMessage(Message message, Role role) throws MessageException { log.debug("Sending message to role " + role); log.debug("User Service : " + Context.getUserService()); List<Role> roles = new ArrayList<>(); roles.add(role); Collection<User> users = Context.getUserService().getUsers(null, roles, false); log.debug("Sending message " + message + " to " + users); Context.getMessageService().sendMessage(message, users); }
/** * @see org.openmrs.Attributable#hydrate(java.lang.String) */ @Override public User hydrate(String userId) { try { return Context.getUserService().getUser(Integer.valueOf(userId)); } catch (Exception e) { return new User(); } }
/** * Send a message to a group of users identified by their role. */ @Override public void sendMessage(Message message, String roleName) throws MessageException { log.debug("Sending message to role with name " + roleName); Role role = Context.getUserService().getRole(roleName); Context.getMessageService().sendMessage(message, role); }
/** * Send a message to a user that is identified by the given identifier. * * @param message <code>Message</code> to be sent * @param recipientId Integer identifier of user (recipient) */ @Override public void sendMessage(Message message, Integer recipientId) throws MessageException { log.debug("Sending message to user with user id " + recipientId); User user = Context.getUserService().getUser(recipientId); message.addRecipient(user.getUserProperty(OpenmrsConstants.USER_PROPERTY_NOTIFICATION_ADDRESS)); Context.getMessageService().sendMessage(message); }
@Before public void setup() { userService = Context.getUserService(); messages = Context.getMessageSourceService(); }
@Test(expected = ContextAuthenticationException.class) public void authenticate_shouldThrowAPIExceptionIfUsernameIsWhiteSpace() { // it would be illegal to save this user (with a whitespace username) but we can get it in the db via xml User u = Context.getUserService().getUser(507); dao.authenticate(" ", "password"); }
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldChangeUserRecordsOfNonPreferredPersonToPreferredPerson() throws Exception { executeDataSet(USERS_WHO_ARE_PATIENTS_XML); Patient notPreferred = patientService.getPatient(2); voidOrders(Collections.singleton(notPreferred)); Context.getPatientService().mergePatients(patientService.getPatient(6), notPreferred); User user = Context.getUserService().getUser(2); Assert.assertEquals(6, user.getPerson().getId().intValue()); }
@Test public void createUser_shouldNotAllowForDuplicatedUsername() { User someUser = userService.getUserByUsername(SOME_USERNAME); User newUser = userWithValidPerson(); newUser.setUsername(someUser.getUsername()); expectedException.expect(DAOException.class); expectedException.expectMessage( String.format("Username %s or system id %s is already in use.", newUser.getUsername(), Context.getUserService().generateSystemId())); userService.createUser(newUser, SOME_VALID_PASSWORD); }
@Test public void createUser_shouldNotAllowUsernameEqualsExistingSystemId() { User someUser = userService.getUserByUsername(SOME_USERNAME); User newUser = userWithValidPerson(); newUser.setUsername(someUser.getSystemId()); expectedException.expect(DAOException.class); expectedException.expectMessage( String.format("Username %s or system id %s is already in use.", newUser.getUsername(), Context.getUserService().generateSystemId())); userService.createUser(newUser, SOME_VALID_PASSWORD); }
/** * @see EncounterService#canEditEncounter(Encounter, User) */ @Test public void canEditEncounter_shouldReturnFalseIfUserCanNotEditEncounter() { // get encounter that has type with edit privilege set Encounter encounter = getEncounterWithEditPrivilege(); User user = Context.getUserService().getUserByUsername("test_user"); assertNotNull(user); // left user as is - i.e. without required privilege assertFalse(Context.getEncounterService().canEditEncounter(encounter, user)); }
/** * @see EncounterService#canViewEncounter(Encounter, User) */ @Test public void canViewEncounter_shouldReturnFalseIfUserCanNotViewEncounter() { // get encounter that has type with view privilege set Encounter encounter = getEncounterWithViewPrivilege(); User user = Context.getUserService().getUserByUsername("test_user"); assertNotNull(user); // left user as is - i.e. without required privilege assertFalse(Context.getEncounterService().canViewEncounter(encounter, user)); }
@Test(expected = ContextAuthenticationException.class) public void authenticate_shouldThrowAContextAuthenticationExceptionIfUsernameIsAnEmptyString() { //update a user with a username that is an empty string for this test UserService us = Context.getUserService(); User u = us.getUser(1); u.setUsername(""); u.getPerson().setGender("M"); us.saveUser(u); dao.authenticate("", "password"); }
/** * @see AuditableInterceptor#onSave(Object,Serializable,Object[],String[],Type[]) */ @Test public void onSave_shouldBeCalledWhenSavingOpenmrsObject() { User u = new User(); u.setSystemId("user"); u.setPerson(Context.getPersonService().getPerson(1)); Context.getUserService().createUser(u, "Admin123"); Assert.assertSame(Context.getAuthenticatedUser(), u.getCreator()); Assert.assertNotNull(u.getDateCreated()); }