Search in sources :

Example 1 with Institution

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
    }
}
Also used : LibraryCard(org.broadinstitute.consent.http.models.LibraryCard) Objects(java.util.Objects) Institution(org.broadinstitute.consent.http.models.Institution) UserProperty(org.broadinstitute.consent.http.models.UserProperty) LinkedHashMapRowReducer(org.jdbi.v3.core.result.LinkedHashMapRowReducer) Map(java.util.Map) RowView(org.jdbi.v3.core.result.RowView) UserRole(org.broadinstitute.consent.http.models.UserRole) MappingException(org.jdbi.v3.core.mapper.MappingException) UserFields(org.broadinstitute.consent.http.enumeration.UserFields) User(org.broadinstitute.consent.http.models.User) LibraryCard(org.broadinstitute.consent.http.models.LibraryCard) User(org.broadinstitute.consent.http.models.User) UserProperty(org.broadinstitute.consent.http.models.UserProperty) UserRole(org.broadinstitute.consent.http.models.UserRole) Institution(org.broadinstitute.consent.http.models.Institution) MappingException(org.jdbi.v3.core.mapper.MappingException)

Example 2 with Institution

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);
    }
}
Also used : SimplifiedUser(org.broadinstitute.consent.http.service.UserService.SimplifiedUser) User(org.broadinstitute.consent.http.models.User) Institution(org.broadinstitute.consent.http.models.Institution) Timestamp(java.sql.Timestamp) SimplifiedUser(org.broadinstitute.consent.http.service.UserService.SimplifiedUser)

Example 3 with Institution

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());
}
Also used : AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) SimplifiedUser(org.broadinstitute.consent.http.service.UserService.SimplifiedUser) Institution(org.broadinstitute.consent.http.models.Institution) Test(org.junit.Test)

Example 4 with Institution

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());
}
Also used : Gson(com.google.gson.Gson) Institution(org.broadinstitute.consent.http.models.Institution) Test(org.junit.Test)

Example 5 with Institution

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;
}
Also used : Institution(org.broadinstitute.consent.http.models.Institution) Date(java.util.Date)

Aggregations

Institution (org.broadinstitute.consent.http.models.Institution)70 Test (org.junit.Test)50 User (org.broadinstitute.consent.http.models.User)32 LibraryCard (org.broadinstitute.consent.http.models.LibraryCard)16 Gson (com.google.gson.Gson)13 Response (javax.ws.rs.core.Response)11 AuthUser (org.broadinstitute.consent.http.models.AuthUser)9 Date (java.util.Date)7 NotFoundException (javax.ws.rs.NotFoundException)7 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Produces (javax.ws.rs.Produces)4 MappingException (org.jdbi.v3.core.mapper.MappingException)4 DarCollection (org.broadinstitute.consent.http.models.DarCollection)3 Election (org.broadinstitute.consent.http.models.Election)3 UserProperty (org.broadinstitute.consent.http.models.UserProperty)3 UserRole (org.broadinstitute.consent.http.models.UserRole)3 File (java.io.File)2 IOException (java.io.IOException)2 PermitAll (javax.annotation.security.PermitAll)2