Search in sources :

Example 1 with User

use of org.broadinstitute.consent.http.models.User 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 User

use of org.broadinstitute.consent.http.models.User 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 User

use of org.broadinstitute.consent.http.models.User in project consent by DataBiosphere.

the class AdminDarApprovedModel method ownersMapToTemplateList.

private List<DatasetOwnerListModel> ownersMapToTemplateList(Map<User, List<DataSet>> dataOwnersDataSets) {
    List<DatasetOwnerListModel> templateList = new ArrayList<>();
    Set<User> owners = dataOwnersDataSets.keySet();
    for (User owner : owners) {
        templateList.addAll(dataOwnersDataSets.get(owner).stream().map(dataSet -> new DatasetOwnerListModel(owner.getDisplayName(), dataSet.getName(), dataSet.getObjectId())).collect(Collectors.toList()));
    }
    return templateList;
}
Also used : User(org.broadinstitute.consent.http.models.User) ArrayList(java.util.ArrayList)

Example 4 with User

use of org.broadinstitute.consent.http.models.User in project consent by DataBiosphere.

the class VoteServiceDAOTest method testUpdateVotesWithValue_MultipleVotes.

@Test
public void testUpdateVotesWithValue_MultipleVotes() throws Exception {
    User user = createUser();
    DataAccessRequest dar = createDataAccessRequestV3();
    DataSet dataset = createDataset();
    Election election = createAccessElection(dar.getReferenceId(), dataset.getDataSetId());
    Vote vote1 = createDacVote(user.getDacUserId(), election.getElectionId());
    Vote vote2 = createDacVote(user.getDacUserId(), election.getElectionId());
    Vote vote3 = createDacVote(user.getDacUserId(), election.getElectionId());
    String rationale = "rationale";
    initService();
    List<Vote> votes = serviceDAO.updateVotesWithValue(List.of(vote1, vote2, vote3), true, rationale);
    assertNotNull(votes);
    assertFalse(votes.isEmpty());
    List<Integer> requestVoteIds = Stream.of(vote1, vote2, vote3).map(Vote::getVoteId).collect(Collectors.toList());
    votes.forEach(v -> {
        assertTrue(v.getVote());
        assertEquals(rationale, v.getRationale());
        assertTrue(requestVoteIds.contains(v.getVoteId()));
    });
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) User(org.broadinstitute.consent.http.models.User) DataSet(org.broadinstitute.consent.http.models.DataSet) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 5 with User

use of org.broadinstitute.consent.http.models.User in project consent by DataBiosphere.

the class VoteServiceDAOTest method testUpdateVotesWithValue_RPElectionWithStatus.

private void testUpdateVotesWithValue_RPElectionWithStatus(ElectionStatus status) throws Exception {
    User user = createUser();
    DataAccessRequest dar = createDataAccessRequestV3();
    DataSet dataset = createDataset();
    Election election = createRPElection(dar.getReferenceId(), dataset.getDataSetId());
    changeElectionStatus(election, status);
    Vote vote = createDacVote(user.getDacUserId(), election.getElectionId());
    String rationale = "rationale";
    initService();
    List<Vote> votes = serviceDAO.updateVotesWithValue(List.of(vote), true, rationale);
    assertNotNull(votes);
    assertFalse(votes.isEmpty());
    assertTrue(votes.get(0).getVote());
    assertEquals(rationale, votes.get(0).getRationale());
    assertEquals(vote.getVoteId(), votes.get(0).getVoteId());
}
Also used : Vote(org.broadinstitute.consent.http.models.Vote) User(org.broadinstitute.consent.http.models.User) DataSet(org.broadinstitute.consent.http.models.DataSet) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election)

Aggregations

User (org.broadinstitute.consent.http.models.User)434 Test (org.junit.Test)293 AuthUser (org.broadinstitute.consent.http.models.AuthUser)251 Response (javax.ws.rs.core.Response)92 UserRole (org.broadinstitute.consent.http.models.UserRole)88 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)86 Dac (org.broadinstitute.consent.http.models.Dac)85 DataSet (org.broadinstitute.consent.http.models.DataSet)85 Vote (org.broadinstitute.consent.http.models.Vote)84 Election (org.broadinstitute.consent.http.models.Election)82 NotFoundException (javax.ws.rs.NotFoundException)70 DarCollection (org.broadinstitute.consent.http.models.DarCollection)68 Consent (org.broadinstitute.consent.http.models.Consent)66 Date (java.util.Date)51 Produces (javax.ws.rs.Produces)50 BadRequestException (javax.ws.rs.BadRequestException)44 Path (javax.ws.rs.Path)44 GoogleUser (org.broadinstitute.consent.http.authentication.GoogleUser)44 RolesAllowed (javax.annotation.security.RolesAllowed)43 LibraryCard (org.broadinstitute.consent.http.models.LibraryCard)41