Search in sources :

Example 21 with Role

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

the class OpenmrsObjectSaveHandlerTest method handle_shouldSetEmptyStringPropertiesToNull.

/**
 * @see OpenmrsObjectSaveHandler#handle(OpenmrsObject,User,Date,String)
 */
@Test
public void handle_shouldSetEmptyStringPropertiesToNull() {
    Role role = new Role();
    role.setName("");
    role.setDescription("");
    role.setRole("");
    new OpenmrsObjectSaveHandler().handle(role, null, null, null);
    Assert.assertNull(role.getName());
    Assert.assertNull(role.getDescription());
    Assert.assertNull(role.getRole());
}
Also used : Role(org.openmrs.Role) Test(org.junit.Test)

Example 22 with Role

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

the class RoleEditor method setAsText.

/**
 * @should set using name
 * @should set using uuid
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    UserService es = Context.getUserService();
    if (StringUtils.hasText(text)) {
        try {
            Role r = es.getRole(text);
            setValue(r);
            // when a role is not found, no exception is generated. throw one to execute the catch block
            if (r == null) {
                throw new Exception();
            }
        } catch (Exception ex) {
            Role r = es.getRoleByUuid(text);
            setValue(r);
            if (r == null) {
                log.error("Error setting text: " + text, ex);
                throw new IllegalArgumentException("Role not found: " + ex.getMessage());
            }
        }
    } else {
        setValue(null);
    }
}
Also used : Role(org.openmrs.Role) UserService(org.openmrs.api.UserService)

Example 23 with Role

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

the class CheckInternetConnectivityTask method execute.

/**
 * @see org.openmrs.scheduler.tasks.AbstractTask#execute()
 */
@Override
public void execute() {
    // TODO url should be provided as a property to taskconfig
    String url = "http://www.google.com:80/index.html";
    try {
        URLConnection connection = new URL(url).openConnection();
        connection.connect();
    } catch (IOException ioe) {
        try {
            String text = "At " + new Date() + " there was an error reported connecting to the internet address " + url + ": " + ioe;
            // TODO role should be provided as a property to taskconfig
            Role role = Context.getUserService().getRole("System Developer");
            Collection<User> users = Context.getUserService().getUsersByRole(role);
            Context.getAlertService().saveAlert(new Alert(text, users));
        } catch (Exception e) {
            // Uh oh, just log it.
            log.error("Failed to check internet connectivity", e);
        }
    }
}
Also used : Role(org.openmrs.Role) Collection(java.util.Collection) Alert(org.openmrs.notification.Alert) IOException(java.io.IOException) URLConnection(java.net.URLConnection) URL(java.net.URL) Date(java.util.Date) IOException(java.io.IOException)

Example 24 with Role

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

the class HibernateAdministrationDAOTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see HibernateAdministrationDAO#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    Role role = new Role();
    role.setRole("Bowling race car driver");
    role.setDescription("description");
    Errors errors = new BindException(role, "type");
    dao.validate(role, errors);
    Assert.assertFalse(errors.hasFieldErrors("role"));
}
Also used : Role(org.openmrs.Role) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 25 with Role

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

the class HibernateAdministrationDAOTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see HibernateAdministrationDAO#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    String errorCode = "error.exceededMaxLengthOfField";
    String[] RoleFeilds = new String[] { "role", "description" };
    Role role = new Role();
    role.setRole("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    role.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(role, "type");
    dao.validate(role, errors);
    for (String feilds : RoleFeilds) {
        FieldError fielderror = errors.getFieldError(feilds);
        Assert.assertTrue(errorCode.equals(fielderror.getCode()));
    }
}
Also used : Role(org.openmrs.Role) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) FieldError(org.springframework.validation.FieldError) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Role (org.openmrs.Role)42 Test (org.junit.Test)27 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)26 User (org.openmrs.User)15 BindException (org.springframework.validation.BindException)8 Errors (org.springframework.validation.Errors)8 Privilege (org.openmrs.Privilege)7 EncounterRole (org.openmrs.EncounterRole)6 HashSet (java.util.HashSet)5 Person (org.openmrs.Person)5 PersonName (org.openmrs.PersonName)4 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 Encounter (org.openmrs.Encounter)3 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 EncounterType (org.openmrs.EncounterType)2 RelationshipType (org.openmrs.RelationshipType)2