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);
}
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);
}
}
}
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());
}
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"));
}
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);
}
Aggregations