Search in sources :

Example 1 with DataAccessRequest

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

the class DarCollectionServiceDAOTest method testCreateElectionsForDarCollectionAfterCancelingEarlierElections.

@Test
public void testCreateElectionsForDarCollectionAfterCancelingEarlierElections() throws Exception {
    initService();
    DarCollection collection = setUpDarCollectionWithDacDataset();
    DataAccessRequest dar = collection.getDars().values().stream().findFirst().orElse(null);
    assertNotNull(dar);
    // create elections & votes:
    serviceDAO.createElectionsForDarCollection(collection);
    // cancel those elections:
    electionDAO.findLastElectionsByReferenceIds(List.of(dar.getReferenceId())).forEach(e -> electionDAO.updateElectionById(e.getElectionId(), ElectionStatus.CANCELED.getValue(), new Date()));
    // re-create elections & new votes:
    serviceDAO.createElectionsForDarCollection(collection);
    List<Election> createdElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar.getReferenceId()));
    // Ensure that we have the right number of access and rp elections, i.e. 1 each
    assertFalse(createdElections.isEmpty());
    assertEquals(2, createdElections.size());
    assertEquals(1, createdElections.stream().filter(e -> e.getElectionType().equals(ElectionType.DATA_ACCESS.getValue())).count());
    assertEquals(1, createdElections.stream().filter(e -> e.getElectionType().equals(ElectionType.RP.getValue())).count());
}
Also used : DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) Date(java.util.Date) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 2 with DataAccessRequest

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

the class DarCollectionServiceDAOTest method testCreateElectionsForDarCollection.

@Test
public void testCreateElectionsForDarCollection() throws Exception {
    initService();
    DarCollection collection = setUpDarCollectionWithDacDataset();
    DataAccessRequest dar = collection.getDars().values().stream().findFirst().orElse(null);
    assertNotNull(dar);
    serviceDAO.createElectionsForDarCollection(collection);
    List<Election> createdElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar.getReferenceId()));
    List<Vote> createdVotes = voteDAO.findVotesByElectionIds(createdElections.stream().map(Election::getElectionId).collect(Collectors.toList()));
    // 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) Vote(org.broadinstitute.consent.http.models.Vote) Assert.assertTrue(org.junit.Assert.assertTrue) 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) Assert.assertEquals(org.junit.Assert.assertEquals) Consent(org.broadinstitute.consent.http.models.Consent) Vote(org.broadinstitute.consent.http.models.Vote) 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 3 with DataAccessRequest

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

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

Example 5 with DataAccessRequest

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

Aggregations

DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)188 Test (org.junit.Test)120 User (org.broadinstitute.consent.http.models.User)83 Election (org.broadinstitute.consent.http.models.Election)62 AuthUser (org.broadinstitute.consent.http.models.AuthUser)53 DataAccessRequestData (org.broadinstitute.consent.http.models.DataAccessRequestData)49 DarCollection (org.broadinstitute.consent.http.models.DarCollection)44 DataSet (org.broadinstitute.consent.http.models.DataSet)41 Date (java.util.Date)36 Vote (org.broadinstitute.consent.http.models.Vote)35 NotFoundException (javax.ws.rs.NotFoundException)30 Consent (org.broadinstitute.consent.http.models.Consent)29 Response (javax.ws.rs.core.Response)27 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)21 Dac (org.broadinstitute.consent.http.models.Dac)17 Produces (javax.ws.rs.Produces)16 List (java.util.List)15 ForbiddenException (javax.ws.rs.ForbiddenException)15 RolesAllowed (javax.annotation.security.RolesAllowed)14