Search in sources :

Example 11 with UserRole

use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.

the class UserServiceTest method testGetReferenceList.

@Test
public void testGetReferenceList() {
    List<String> regionUuids = null;
    List<String> districtUuids = null;
    List<String> communityUuids = null;
    boolean includeSupervisors = false;
    boolean filterByJurisdiction = false;
    boolean activeOnly = false;
    List<UserRole> userRoles = null;
    // 0. No conditions, test signature with userRoles varArg parameter
    List<UserReference> result = getUserService().getReferenceList(regionUuids, districtUuids, includeSupervisors, filterByJurisdiction, activeOnly);
    assertThat(result, hasSize(1));
    UserReference admin = result.get(0);
    assertThat(admin.getUserRoles(), containsInAnyOrder(UserRole.ADMIN, UserRole.NATIONAL_USER));
    // 1a. Find admin with several conditions
    activeOnly = true;
    userRoles = Arrays.asList(UserRole.ADMIN);
    result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
    assertThat(result, contains(admin));
    userRoles = Arrays.asList(UserRole.NATIONAL_USER);
    result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
    assertThat(result, contains(admin));
    userRoles = Arrays.asList(UserRole.ADMIN, UserRole.CASE_OFFICER);
    result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
    assertThat(result, contains(admin));
    // 1b. Exclude admin by role
    userRoles = Arrays.asList(UserRole.CASE_OFFICER);
    result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
    assertThat(result, is(empty()));
    // 2. Include supervisors
    userRoles = Arrays.asList(UserRole.CONTACT_OFFICER);
    RDCF rdcf = creator.createRDCF();
    UserDto supervisor = creator.createUser(rdcf, UserRole.CONTACT_SUPERVISOR);
    result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
    assertThat(result, is(empty()));
    includeSupervisors = true;
    result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
    assertThat(result, hasSize(1));
    assertThat(result.get(0).getUuid(), equalTo(supervisor.getUuid()));
    // 3. Exclude inactive user as overall condition
    getUserFacade().disableUsers(Arrays.asList(supervisor.getUuid()));
    result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
    assertThat(result, is(empty()));
    // 4. filterByJurisdiction to test that the invocation works and filters correctly concerning activeOnly
    filterByJurisdiction = true;
    result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
    assertThat(result, is(empty()));
    activeOnly = false;
    result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
    assertThat(result, hasSize(1));
    assertThat(result.get(0).getUuid(), equalTo(supervisor.getUuid()));
    // 5. regions filter
    result = getUserService().getReferenceList(Arrays.asList(rdcf.region.getUuid()), null, false, false, false);
    assertThat(result, hasSize(1));
    assertThat(result.get(0).getUuid(), equalTo(supervisor.getUuid()));
    // 6. districts filter
    result = getUserService().getReferenceList(null, Arrays.asList(rdcf.district.getUuid()), false, false, false);
    assertThat(result, hasSize(1));
    assertThat(result.get(0).getUuid(), equalTo(supervisor.getUuid()));
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) UserRole(de.symeda.sormas.api.user.UserRole) UserDto(de.symeda.sormas.api.user.UserDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 12 with UserRole

use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.

the class UserRoleConfigDao method delete.

@Override
public void delete(UserRoleConfig data) throws SQLException {
    UserRole userRole = data.getUserRole();
    super.delete(data);
    if (ConfigProvider.getUser().hasUserRole(userRole)) {
        ConfigProvider.onUserRolesConfigChanged();
    }
}
Also used : UserRole(de.symeda.sormas.api.user.UserRole)

Example 13 with UserRole

use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.

the class UserEditForm method updateFieldsByUserRole.

@SuppressWarnings("unchecked")
private void updateFieldsByUserRole() {
    final Field userRolesField = getFieldGroup().getField(UserDto.USER_ROLES);
    final Set<UserRole> userRoles = (Set<UserRole>) userRolesField.getValue();
    final JurisdictionLevel jurisdictionLevel = UserRole.getJurisdictionLevel(userRoles);
    final boolean hasAssociatedOfficer = UserRole.hasAssociatedOfficer(userRoles);
    final boolean hasOptionalHealthFacility = UserRole.hasOptionalHealthFacility(userRoles);
    final boolean isLabUser = UserRole.isLabUser(userRoles);
    final boolean isPortHealthUser = UserRole.isPortHealthUser(userRoles);
    final boolean usePointOfEntry = (isPortHealthUser && hasAssociatedOfficer) || jurisdictionLevel == JurisdictionLevel.POINT_OF_ENTRY;
    final boolean useHealthFacility = jurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY;
    final boolean useCommunity = jurisdictionLevel == JurisdictionLevel.COMMUNITY;
    final boolean useDistrict = hasAssociatedOfficer || jurisdictionLevel == JurisdictionLevel.DISTRICT || useCommunity || useHealthFacility || usePointOfEntry;
    ;
    final boolean useRegion = jurisdictionLevel == JurisdictionLevel.REGION || useDistrict;
    final ComboBox associatedOfficer = (ComboBox) getFieldGroup().getField(UserDto.ASSOCIATED_OFFICER);
    associatedOfficer.setVisible(hasAssociatedOfficer);
    setRequired(hasAssociatedOfficer && !isPortHealthUser, UserDto.ASSOCIATED_OFFICER);
    if (!hasAssociatedOfficer) {
        associatedOfficer.clear();
    }
    final ComboBox community = (ComboBox) getFieldGroup().getField(UserDto.COMMUNITY);
    community.setVisible(useCommunity);
    setRequired(useCommunity, UserDto.COMMUNITY);
    if (!useCommunity) {
        community.clear();
    }
    final ComboBox healthFacility = (ComboBox) getFieldGroup().getField(UserDto.HEALTH_FACILITY);
    healthFacility.setVisible(hasOptionalHealthFacility || useHealthFacility);
    setRequired(useHealthFacility, UserDto.HEALTH_FACILITY);
    if (!healthFacility.isVisible()) {
        healthFacility.clear();
    }
    final ComboBox laboratory = (ComboBox) getFieldGroup().getField(UserDto.LABORATORY);
    laboratory.setVisible(isLabUser);
    setRequired(isLabUser, UserDto.LABORATORY);
    if (!isLabUser) {
        laboratory.clear();
    }
    final ComboBox pointOfEntry = (ComboBox) getFieldGroup().getField(UserDto.POINT_OF_ENTRY);
    pointOfEntry.setVisible(usePointOfEntry);
    setRequired(usePointOfEntry, UserDto.POINT_OF_ENTRY);
    if (!usePointOfEntry) {
        pointOfEntry.clear();
    }
    final ComboBox district = (ComboBox) getFieldGroup().getField(UserDto.DISTRICT);
    district.setVisible(useDistrict);
    setRequired(useDistrict, UserDto.DISTRICT);
    if (!useDistrict) {
        district.clear();
    }
    final ComboBox region = (ComboBox) getFieldGroup().getField(UserDto.REGION);
    region.setVisible(useRegion);
    setRequired(useRegion, UserDto.REGION);
    if (!useRegion) {
        region.clear();
    }
}
Also used : Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) Set(java.util.Set) UserRole(de.symeda.sormas.api.user.UserRole) ComboBox(com.vaadin.v7.ui.ComboBox) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel)

Example 14 with UserRole

use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.

the class RoleFilter method passesFilter.

@SuppressWarnings("unchecked")
@Override
public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
    final Property<?> p = item.getItemProperty(getPropertyId());
    if (null == p) {
        return false;
    }
    Collection<UserRole> roles = (Collection<UserRole>) p.getValue();
    for (UserRole role : roles) {
        if (compareEquals(roleToFilter, role)) {
            return true;
        }
    }
    // all cases should have been processed above
    return false;
}
Also used : UserRole(de.symeda.sormas.api.user.UserRole) Collection(java.util.Collection)

Example 15 with UserRole

use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.

the class TestDataCreator method createUser.

private UserDto createUser(String regionUuid, String districtUuid, String communityUuid, String facilityUuid, String firstName, String lastName, Disease limitedDisease, UserRole... roles) {
    UserDto user1 = UserDto.build();
    user1.setFirstName(firstName);
    user1.setLastName(lastName);
    user1.setUserName(firstName + lastName);
    user1.setUserRoles(new HashSet<UserRole>(Arrays.asList(roles)));
    user1.setLimitedDisease(limitedDisease);
    UserDto user = user1;
    user.setRegion(beanTest.getRegionFacade().getReferenceByUuid(regionUuid));
    user.setDistrict(beanTest.getDistrictFacade().getReferenceByUuid(districtUuid));
    user.setCommunity(beanTest.getCommunityFacade().getReferenceByUuid(communityUuid));
    user.setHealthFacility(beanTest.getFacilityFacade().getReferenceByUuid(facilityUuid));
    user = beanTest.getUserFacade().saveUser(user);
    return user;
}
Also used : UserRole(de.symeda.sormas.api.user.UserRole) UserDto(de.symeda.sormas.api.user.UserDto)

Aggregations

UserRole (de.symeda.sormas.api.user.UserRole)29 Test (org.junit.Test)7 HashSet (java.util.HashSet)6 Case (de.symeda.sormas.app.backend.caze.Case)5 User (de.symeda.sormas.backend.user.User)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 UserDto (de.symeda.sormas.api.user.UserDto)4 User (de.symeda.sormas.app.backend.user.User)4 Predicate (javax.persistence.criteria.Predicate)4 CaseDao (de.symeda.sormas.app.backend.caze.CaseDao)3 District (de.symeda.sormas.app.backend.region.District)3 Task (de.symeda.sormas.app.backend.task.Task)3 TaskDao (de.symeda.sormas.app.backend.task.TaskDao)3 Set (java.util.Set)3 AuthProvider (de.symeda.sormas.api.AuthProvider)2 JurisdictionLevel (de.symeda.sormas.api.user.JurisdictionLevel)2 UserRight (de.symeda.sormas.api.user.UserRight)2 Community (de.symeda.sormas.app.backend.region.Community)2 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)2 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)2