Search in sources :

Example 31 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class HibernateUserDAO method changeQuestionAnswer.

/**
 * @see org.openmrs.api.UserService#changeQuestionAnswer(java.lang.String, java.lang.String,
 *      java.lang.String)
 */
@Override
public void changeQuestionAnswer(String pw, String question, String answer) throws DAOException {
    User u = Context.getAuthenticatedUser();
    LoginCredential credentials = getLoginCredential(u);
    if (!credentials.checkPassword(pw)) {
        log.error("Passwords don't match");
        throw new DAOException("Passwords don't match");
    }
    changeQuestionAnswer(u, question, answer);
}
Also used : DAOException(org.openmrs.api.db.DAOException) User(org.openmrs.User) LoginCredential(org.openmrs.api.db.LoginCredential)

Example 32 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class PersonVoidHandler method handle.

/**
 * Sets all personVoid* attributes to the given parameters.
 *
 * @see org.openmrs.api.handler.RequiredDataHandler#handle(org.openmrs.OpenmrsObject,
 *      org.openmrs.User, java.util.Date, java.lang.String)
 * @should set the personVoided bit
 * @should set the personVoidReason
 * @should set personVoidedBy
 * @should not set personVoidedBy if non null
 * @should set personDateVoided
 * @should not set personDateVoided if non null
 * @should not set the personVoidReason if already personVoided
 * @should retire users
 */
@Override
public void handle(Person person, User voidingUser, Date voidedDate, String voidReason) {
    // skip over all work if the object is already voided
    if (!person.getPersonVoided()) {
        if (person.getPersonId() != null) {
            // Skip if person is not persisted
            UserService us = Context.getUserService();
            for (User user : us.getUsersByPerson(person, false)) {
                us.retireUser(user, voidReason);
            }
        }
        person.setPersonVoided(true);
        person.setPersonVoidReason(voidReason);
        if (person.getPersonVoidedBy() == null) {
            person.setPersonVoidedBy(voidingUser);
        }
        if (person.getPersonDateVoided() == null) {
            person.setPersonDateVoided(voidedDate);
        }
    }
}
Also used : User(org.openmrs.User) UserService(org.openmrs.api.UserService)

Example 33 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class UserValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see UserValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    User user = new User();
    user.setUsername("test");
    user.setSystemId("systemId");
    user.setRetireReason("retireReason");
    user.setPerson(new Person(999));
    user.getPerson().addName(new PersonName("Users", "Need", "People"));
    user.getPerson().setGender("F");
    Errors errors = new BindException(user, "user");
    validator.validate(user, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) PersonName(org.openmrs.PersonName) User(org.openmrs.User) BindException(org.springframework.validation.BindException) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 34 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class UserValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see UserValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    User user = new User();
    user.setUsername(STRING_WITH_LENGTH_GREATER_THAN_50);
    user.setSystemId(STRING_WITH_LENGTH_GREATER_THAN_50);
    user.setRetireReason(STRING_WITH_LENGTH_GREATER_THAN_50);
    user.setPerson(new Person(999));
    user.getPerson().addName(new PersonName(STRING_WITH_LENGTH_GREATER_THAN_50, STRING_WITH_LENGTH_GREATER_THAN_50, STRING_WITH_LENGTH_GREATER_THAN_50));
    user.getPerson().setGender(STRING_WITH_LENGTH_GREATER_THAN_50);
    Errors errors = new BindException(user, "user");
    validator.validate(user, errors);
    Assert.assertTrue(errors.hasFieldErrors("username"));
    Assert.assertTrue(errors.hasFieldErrors("systemId"));
    Assert.assertTrue(errors.hasFieldErrors("retireReason"));
    Assert.assertTrue(errors.hasFieldErrors("person.names[0].givenName"));
    Assert.assertTrue(errors.hasFieldErrors("person.names[0].middleName"));
    Assert.assertTrue(errors.hasFieldErrors("person.names[0].familyName"));
    Assert.assertTrue(errors.hasFieldErrors("person.gender"));
}
Also used : Errors(org.springframework.validation.Errors) PersonName(org.openmrs.PersonName) User(org.openmrs.User) BindException(org.springframework.validation.BindException) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 35 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class UserValidatorTest method validate_shouldNotThrowNPEWhenUserIsNull.

/**
 * @see UserValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldNotThrowNPEWhenUserIsNull() {
    Errors errors = new BindException(new User(), "user");
    validator.validate(null, errors);
    Assert.assertTrue(true);
}
Also used : Errors(org.springframework.validation.Errors) User(org.openmrs.User) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

User (org.openmrs.User)201 Test (org.junit.Test)150 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)132 Date (java.util.Date)38 Person (org.openmrs.Person)33 Encounter (org.openmrs.Encounter)21 Patient (org.openmrs.Patient)18 PersonName (org.openmrs.PersonName)17 Role (org.openmrs.Role)13 GlobalProperty (org.openmrs.GlobalProperty)11 Location (org.openmrs.Location)11 ArrayList (java.util.ArrayList)10 EncounterType (org.openmrs.EncounterType)10 Locale (java.util.Locale)7 UserService (org.openmrs.api.UserService)7 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)7 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 EncounterRole (org.openmrs.EncounterRole)6 PatientIdentifier (org.openmrs.PatientIdentifier)6