Search in sources :

Example 26 with Vote

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

the class DarCollectionServiceDAOTest method testCreateElectionsForDarCollectionChair.

/**
 * This test covers the case where:
 *  - User is a chairperson
 *  - Collection has 1 DAR/Dataset combinations
 *  - Elections created should be for the DAR/Dataset for the user
 */
@Test
public void testCreateElectionsForDarCollectionChair() throws Exception {
    initService();
    DarCollection collection = setUpDarCollectionWithDacDataset();
    Optional<DataAccessRequest> dar = collection.getDars().values().stream().findFirst();
    assertTrue(dar.isPresent());
    Integer datasetId = dar.get().getData().getDatasetIds().get(0);
    assertNotNull(datasetId);
    Optional<Dac> dac = dacDAO.findDacsForDatasetIds(List.of(datasetId)).stream().findFirst();
    assertTrue(dac.isPresent());
    List<User> dacUsers = dacDAO.findMembersByDacId(dac.get().getDacId());
    Optional<User> chair = dacUsers.stream().filter(u -> u.hasUserRole(UserRoles.CHAIRPERSON)).findFirst();
    assertTrue(chair.isPresent());
    List<String> referenceIds = serviceDAO.createElectionsForDarCollection(chair.get(), collection);
    List<Election> createdElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar.get().getReferenceId()));
    List<Vote> createdVotes = voteDAO.findVotesByElectionIds(createdElections.stream().map(Election::getElectionId).collect(Collectors.toList()));
    assertTrue(referenceIds.contains(dar.get().getReferenceId()));
    // Ensure that we have an access and rp election
    assertFalse(createdElections.isEmpty());
    assertTrue(createdElections.stream().anyMatch(e -> e.getElectionType().equals(ElectionType.DATA_ACCESS.getValue())));
    assertTrue(createdElections.stream().anyMatch(e -> e.getElectionType().equals(ElectionType.RP.getValue())));
    // Ensure that we have primary vote types
    assertFalse(createdVotes.isEmpty());
    assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.CHAIRPERSON.getValue())));
    assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.FINAL.getValue())));
    assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.DAC.getValue())));
    assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.AGREEMENT.getValue())));
}
Also used : ElectionStatus(org.broadinstitute.consent.http.enumeration.ElectionStatus) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Dataset(org.broadinstitute.consent.http.models.Dataset) Date(java.util.Date) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserRole(org.broadinstitute.consent.http.models.UserRole) Vote(org.broadinstitute.consent.http.models.Vote) Assert.assertTrue(org.junit.Assert.assertTrue) User(org.broadinstitute.consent.http.models.User) Test(org.junit.Test) UserRoles(org.broadinstitute.consent.http.enumeration.UserRoles) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Collectors(java.util.stream.Collectors) Dac(org.broadinstitute.consent.http.models.Dac) DAOTestHelper(org.broadinstitute.consent.http.db.DAOTestHelper) List(java.util.List) VoteType(org.broadinstitute.consent.http.enumeration.VoteType) Election(org.broadinstitute.consent.http.models.Election) Assert.assertFalse(org.junit.Assert.assertFalse) ElectionType(org.broadinstitute.consent.http.enumeration.ElectionType) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) Consent(org.broadinstitute.consent.http.models.Consent) Vote(org.broadinstitute.consent.http.models.Vote) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 27 with Vote

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

the class DarCollectionServiceDAOTest method testCreateElectionsForDarCollectionWithMultipleDatasetsForAdmin.

/**
 * This test covers the case where:
 *  - User is an admin
 *  - Collection has 2 DAR/Dataset combinations
 *  - User is an Admin
 *  - Elections created should only be for ALL the DAR/Dataset combinations
 */
@Test
public void testCreateElectionsForDarCollectionWithMultipleDatasetsForAdmin() throws Exception {
    initService();
    User user = new User();
    user.addRole(new UserRole(UserRoles.ADMIN.getRoleId(), UserRoles.ADMIN.getRoleName()));
    DarCollection collection = setUpDarCollectionWithDacDataset();
    DataAccessRequest dar = collection.getDars().values().stream().findFirst().orElse(null);
    assertNotNull(dar);
    // Add another DAR with Dataset in a separate DAC to the collection
    DataAccessRequest dar2 = addDARWithDacAndDatasetToCollection(collection);
    // refresh the collection
    collection = darCollectionDAO.findDARCollectionByCollectionId(collection.getDarCollectionId());
    List<String> referenceIds = serviceDAO.createElectionsForDarCollection(user, collection);
    List<Election> createdElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar.getReferenceId()));
    List<Vote> createdVotes = voteDAO.findVotesByElectionIds(createdElections.stream().map(Election::getElectionId).collect(Collectors.toList()));
    assertTrue(referenceIds.contains(dar.getReferenceId()));
    assertTrue(referenceIds.contains(dar2.getReferenceId()));
    // Ensure that we have an access and rp election
    assertFalse(createdElections.isEmpty());
    assertTrue(createdElections.stream().anyMatch(e -> e.getElectionType().equals(ElectionType.DATA_ACCESS.getValue())));
    assertTrue(createdElections.stream().anyMatch(e -> e.getElectionType().equals(ElectionType.RP.getValue())));
    // Ensure that we have primary vote types
    assertFalse(createdVotes.isEmpty());
    assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.CHAIRPERSON.getValue())));
    assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.FINAL.getValue())));
    assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.DAC.getValue())));
    assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.AGREEMENT.getValue())));
    // Make sure that we DID create elections for the additional DAR/Dataset combination
    List<Election> additionalCreatedElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar2.getReferenceId()));
    assertFalse(additionalCreatedElections.isEmpty());
}
Also used : ElectionStatus(org.broadinstitute.consent.http.enumeration.ElectionStatus) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Dataset(org.broadinstitute.consent.http.models.Dataset) Date(java.util.Date) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserRole(org.broadinstitute.consent.http.models.UserRole) Vote(org.broadinstitute.consent.http.models.Vote) Assert.assertTrue(org.junit.Assert.assertTrue) User(org.broadinstitute.consent.http.models.User) Test(org.junit.Test) UserRoles(org.broadinstitute.consent.http.enumeration.UserRoles) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Collectors(java.util.stream.Collectors) Dac(org.broadinstitute.consent.http.models.Dac) DAOTestHelper(org.broadinstitute.consent.http.db.DAOTestHelper) List(java.util.List) VoteType(org.broadinstitute.consent.http.enumeration.VoteType) Election(org.broadinstitute.consent.http.models.Election) Assert.assertFalse(org.junit.Assert.assertFalse) ElectionType(org.broadinstitute.consent.http.enumeration.ElectionType) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) Consent(org.broadinstitute.consent.http.models.Consent) Vote(org.broadinstitute.consent.http.models.Vote) User(org.broadinstitute.consent.http.models.User) UserRole(org.broadinstitute.consent.http.models.UserRole) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 28 with Vote

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

the class VoteServiceDAOTest method testUpdateVotesWithValue_NoRationale.

@Test
public void testUpdateVotesWithValue_NoRationale() throws Exception {
    User user = createUser();
    DataAccessRequest dar = createDataAccessRequestV3();
    Dataset dataset = createDataset();
    Election election = createAccessElection(dar.getReferenceId(), dataset.getDataSetId());
    Vote vote = createFinalVote(user.getDacUserId(), election.getElectionId());
    initService();
    List<Vote> votes = serviceDAO.updateVotesWithValue(List.of(vote), true, null);
    assertNotNull(votes);
    assertFalse(votes.isEmpty());
    assertTrue(votes.get(0).getVote());
    assertNull(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) Test(org.junit.Test)

Example 29 with Vote

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

the class VoteServiceDAOTest method testUpdateVotesWithValue_MultipleElectionTypes.

@Test
public void testUpdateVotesWithValue_MultipleElectionTypes() throws Exception {
    User user = createUser();
    DataAccessRequest dar = createDataAccessRequestV3();
    Dataset dataset = createDataset();
    Election rpElection1 = createRPElection(dar.getReferenceId(), dataset.getDataSetId());
    Election rpElection2 = createRPElection(dar.getReferenceId(), dataset.getDataSetId());
    Election accessElection = createAccessElection(dar.getReferenceId(), dataset.getDataSetId());
    changeElectionStatus(rpElection1, ElectionStatus.CLOSED);
    Vote vote1 = createDacVote(user.getDacUserId(), rpElection1.getElectionId());
    Vote vote2 = createDacVote(user.getDacUserId(), rpElection2.getElectionId());
    Vote vote3 = createDacVote(user.getDacUserId(), accessElection.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 30 with Vote

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

Aggregations

Vote (org.broadinstitute.consent.http.models.Vote)167 Test (org.junit.Test)124 Election (org.broadinstitute.consent.http.models.Election)105 User (org.broadinstitute.consent.http.models.User)90 Dataset (org.broadinstitute.consent.http.models.Dataset)59 Consent (org.broadinstitute.consent.http.models.Consent)57 Dac (org.broadinstitute.consent.http.models.Dac)45 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)45 Response (javax.ws.rs.core.Response)37 AuthUser (org.broadinstitute.consent.http.models.AuthUser)30 ElectionReviewVote (org.broadinstitute.consent.http.models.ElectionReviewVote)30 UserRole (org.broadinstitute.consent.http.models.UserRole)25 Date (java.util.Date)21 NotFoundException (javax.ws.rs.NotFoundException)18 List (java.util.List)16 ArrayList (java.util.ArrayList)14 Collectors (java.util.stream.Collectors)14 ElectionType (org.broadinstitute.consent.http.enumeration.ElectionType)14 DarCollection (org.broadinstitute.consent.http.models.DarCollection)14 DataAccessRequestData (org.broadinstitute.consent.http.models.DataAccessRequestData)14