use of org.broadinstitute.consent.http.models.Institution 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.Institution in project consent by DataBiosphere.
the class InstitutionWithUsersReducer method accumulate.
@Override
public void accumulate(Map<Integer, Institution> map, RowView rowView) {
Institution institution = map.computeIfAbsent(rowView.getColumn("institution_id", Integer.class), id -> rowView.getRow(Institution.class));
User create_user = new User();
if (Objects.nonNull(rowView.getColumn("u_dacuserid", Integer.class))) {
create_user = rowView.getRow(User.class);
}
User update_user = new User();
update_user.setDacUserId(rowView.getColumn("u2_dacuserid", Integer.class));
update_user.setEmail(rowView.getColumn("u2_email", String.class));
update_user.setDisplayName(rowView.getColumn("u2_displayname", String.class));
update_user.setCreateDate(rowView.getColumn("u2_createdate", Timestamp.class));
update_user.setAdditionalEmail(rowView.getColumn("u2_additional_email", String.class));
update_user.setEmailPreference(rowView.getColumn("u2_email_preference", Boolean.class));
update_user.setEraCommonsId(rowView.getColumn("u2_era_commons_id", String.class));
institution.setCreateUser(create_user);
institution.setUpdateUser(update_user);
if (Objects.nonNull(rowView.getColumn("so_dacuserid", Integer.class))) {
SimplifiedUser so_user = new SimplifiedUser();
so_user = rowView.getRow(SimplifiedUser.class);
institution.addSigningOfficial(so_user);
}
}
use of org.broadinstitute.consent.http.models.Institution in project consent by DataBiosphere.
the class UserServiceTest method testFindUsersByInstitutionIdSuccess.
@Test
public void testFindUsersByInstitutionIdSuccess() {
when(institutionDAO.findInstitutionById(anyInt())).thenReturn(new Institution());
initService();
List<User> users = service.findUsersByInstitutionId(1);
assertNotNull(users);
assertTrue(users.isEmpty());
}
use of org.broadinstitute.consent.http.models.Institution in project consent by DataBiosphere.
the class InstitutionUtilTest method testGsonBuilderAdmin.
@Test
public void testGsonBuilderAdmin() {
Institution mockInstitution = initMockInstitution();
Gson builder = util.getGsonBuilder(true);
String json = builder.toJson(mockInstitution);
Institution deserialized = new Gson().fromJson(json, Institution.class);
assertEquals(mockInstitution.getName(), deserialized.getName());
assertEquals(mockInstitution.getCreateUserId(), deserialized.getCreateUserId());
assertEquals(mockInstitution.getUpdateUserId(), deserialized.getUpdateUserId());
assertEquals(mockInstitution.getCreateDate().toString(), deserialized.getCreateDate().toString());
assertEquals(mockInstitution.getUpdateDate().toString(), deserialized.getUpdateDate().toString());
assertEquals(mockInstitution.getId(), deserialized.getId());
}
use of org.broadinstitute.consent.http.models.Institution in project consent by DataBiosphere.
the class InstitutionResourceTest method mockInstitutionSetup.
private Institution mockInstitutionSetup() {
Institution mockInstitution = new Institution();
mockInstitution.setName("Test Name");
mockInstitution.setCreateDate(new Date());
mockInstitution.setCreateUserId(1);
mockInstitution.setUpdateDate(new Date());
mockInstitution.setUpdateUserId(1);
mockInstitution.setId(1);
return mockInstitution;
}
Aggregations