use of org.broadinstitute.consent.http.models.UserRole in project consent by DataBiosphere.
the class UserWithRolesMapper method addRole.
private void addRole(ResultSet r, User user) throws SQLException {
if (r.getObject("user_role_id") != null && r.getObject("user_id") != null && r.getObject("role_id") != null) {
Integer dacId = (r.getObject("dac_id") == null) ? null : r.getInt("dac_id");
UserRole role = new UserRole(r.getInt("user_role_id"), r.getInt("user_id"), r.getInt("role_id"), r.getString("name"), dacId);
user.addRole(role);
}
}
use of org.broadinstitute.consent.http.models.UserRole in project consent by DataBiosphere.
the class UserWithRolesReducer method accumulate.
@Override
public void accumulate(Map<Integer, User> map, RowView rowView) {
User user = map.computeIfAbsent(rowView.getColumn("dacuserid", Integer.class), id -> rowView.getRow(User.class));
try {
if (Objects.nonNull(rowView.getColumn("user_role_id", Integer.class))) {
UserRole ur = rowView.getRow(UserRole.class);
user.addRole(ur);
}
} catch (MappingException e) {
// Ignore any attempt to map a column that doesn't exist
}
try {
if (Objects.nonNull(rowView.getColumn("i_id", Integer.class))) {
Institution institution = rowView.getRow(Institution.class);
// There are unusual cases where we somehow create an institution with null values
if (Objects.nonNull(institution.getId())) {
user.setInstitution(institution);
}
}
} catch (MappingException e) {
// Ignore institution mapping errors, possible for new users to not have an institution
}
// Below only adds LC if not currently saved on the array
try {
if (Objects.nonNull(rowView.getColumn("lc_id", Integer.class))) {
LibraryCard lc = rowView.getRow(LibraryCard.class);
try {
if (Objects.nonNull(rowView.getColumn("lci_id", Integer.class))) {
Institution institution = rowView.getRow(Institution.class);
// There are unusual cases where we somehow create an institution with null values
if (Objects.nonNull(institution.getId())) {
lc.setInstitution(institution);
}
}
} catch (MappingException e) {
// Ignore institution mapping errors
}
if (Objects.isNull(user.getLibraryCards()) || user.getLibraryCards().stream().noneMatch(card -> card.getId().equals(lc.getId()))) {
user.addLibraryCard(lc);
}
}
} catch (MappingException e) {
// Ignore exceptions here, user may not have a library card issued under this instiution
}
try {
if (Objects.nonNull(rowView.getColumn("up_property_id", Integer.class))) {
UserProperty p = rowView.getRow(UserProperty.class);
user.addProperty(p);
// Note that the completed field is deprecated and will be removed in a future PR.
if (p.getPropertyKey().equalsIgnoreCase(UserFields.COMPLETED.getValue())) {
user.setProfileCompleted(Boolean.valueOf(p.getPropertyValue()));
}
}
} catch (MappingException e) {
// Ignore any attempt to map a column that doesn't exist
}
}
use of org.broadinstitute.consent.http.models.UserRole in project consent by DataBiosphere.
the class UserServiceTest method testCreateUserInvalidRoleCase2.
@Test(expected = BadRequestException.class)
public void testCreateUserInvalidRoleCase2() {
User u = generateUser();
List<UserRole> roles = List.of(generateRole(UserRoles.MEMBER.getRoleId()));
u.setRoles(roles);
initService();
service.createUser(u);
}
use of org.broadinstitute.consent.http.models.UserRole in project consent by DataBiosphere.
the class MetricsServiceTest method generateDac.
private Dac generateDac() {
Dac dac = new Dac();
dac.setDacId(1);
dac.setDescription("description");
dac.setName("dac1");
User chairUser = new User();
chairUser.setDacUserId(1);
chairUser.setEmail("chair@test.org");
chairUser.setDisplayName("Chair");
UserRole chairRole = new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
chairUser.setRoles(Collections.singletonList(chairRole));
User memberUser = new User();
memberUser.setDacUserId(2);
memberUser.setEmail("member@test.org");
memberUser.setDisplayName("Member");
UserRole memberRole = new UserRole(UserRoles.MEMBER.getRoleId(), UserRoles.MEMBER.getRoleName());
memberUser.setRoles(Collections.singletonList(memberRole));
dac.setChairpersons(Collections.singletonList(chairUser));
dac.setMembers(Collections.singletonList(memberUser));
return dac;
}
use of org.broadinstitute.consent.http.models.UserRole in project consent by DataBiosphere.
the class UserServiceTest method testFindUserByIdWithRoles.
@Test
public void testFindUserByIdWithRoles() {
User u = generateUser();
List<UserRole> roleList = List.of(generateRole(UserRoles.RESEARCHER.getRoleId()), generateRole(UserRoles.MEMBER.getRoleId()));
u.setRoles(roleList);
when(userDAO.findUserById(any())).thenReturn(u);
initService();
User user = service.findUserById(u.getDacUserId());
assertNotNull(user);
assertEquals(u.getEmail(), user.getEmail());
assertFalse(u.getRoles().isEmpty());
assertEquals(2, u.getRoles().size());
}
Aggregations