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