Search in sources :

Example 96 with Dac

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

the class MetricsServiceTest method initializeMetricsDAOCalls.

private void initializeMetricsDAOCalls(int darCount, int datasetCount) {
    when(darDAO.findAllDataAccessRequests()).thenReturn(generateDars(darCount));
    when(dataSetDAO.findDatasetsByIdList(any())).thenReturn(generateDatasets(datasetCount));
    when(electionDAO.findLastElectionsByReferenceIds(any())).thenReturn(Collections.emptyList());
    when(matchDAO.findMatchesForPurposeIds(any())).thenReturn(Collections.emptyList());
    when(electionDAO.findAllDacsForElectionIds(any())).thenReturn(Collections.emptyList());
    Dac dac = generateDac();
    when(dacService.findAllDacsWithMembers()).thenReturn(Collections.singletonList(dac));
    List<DatasetDTO> datasetDTOS = generateDatasetDTO(datasetCount);
    when(dataSetDAO.findDatasetsWithDacs()).thenReturn(new HashSet<>(datasetDTOS));
}
Also used : DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) Dac(org.broadinstitute.consent.http.models.Dac)

Example 97 with Dac

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

the class DarCollectionServiceDAOTest method setUpDarCollectionWithDacDataset.

private DarCollection setUpDarCollectionWithDacDataset() {
    Dac dac = createDac();
    createUserWithRoleInDac(UserRoles.CHAIRPERSON.getRoleId(), dac.getDacId());
    createUserWithRoleInDac(UserRoles.MEMBER.getRoleId(), dac.getDacId());
    Consent consent = createConsent(dac.getDacId());
    DataSet dataset = createDataset();
    createAssociation(consent.getConsentId(), dataset.getDataSetId());
    DarCollection collection = createDarCollectionWithSingleDataAccessRequest();
    DataAccessRequest dar = collection.getDars().values().stream().findFirst().orElse(null);
    assertNotNull(dar);
    assertNotNull(dar.getData());
    dar.getData().setDatasetIds(List.of(dataset.getDataSetId()));
    Date now = new Date();
    dataAccessRequestDAO.updateDataByReferenceIdVersion2(dar.getReferenceId(), dar.getUserId(), now, now, now, dar.getData());
    return darCollectionDAO.findDARCollectionByReferenceId(dar.getReferenceId());
}
Also used : Consent(org.broadinstitute.consent.http.models.Consent) DataSet(org.broadinstitute.consent.http.models.DataSet) Dac(org.broadinstitute.consent.http.models.Dac) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Date(java.util.Date) DarCollection(org.broadinstitute.consent.http.models.DarCollection)

Example 98 with Dac

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

the class DataAccessRequestServiceTest method testDescribeDataAccessRequestManageV2.

@Test
public void testDescribeDataAccessRequestManageV2() {
    User user = new User();
    Integer genericId = 1;
    DataAccessRequest dar = generateDataAccessRequest();
    dar.setData(new DataAccessRequestData());
    dar.getData().setDatasetIds(Collections.singletonList(genericId));
    when(dataAccessRequestDAO.findAllDataAccessRequests()).thenReturn(Collections.singletonList(dar));
    when(dacService.filterDataAccessRequestsByDac(any(), any())).thenReturn(Collections.singletonList(dar));
    Election e = new Election();
    e.setReferenceId(dar.getReferenceId());
    e.setElectionId(genericId);
    when(electionDAO.findLastElectionsByReferenceIdsAndType(any(), any())).thenReturn(Collections.singletonList(e));
    Vote v = new Vote();
    v.setVoteId(genericId);
    v.setElectionId(e.getElectionId());
    when(voteDAO.findVotesByElectionIds(any())).thenReturn(Collections.singletonList(v));
    Dac d = new Dac();
    d.setDacId(genericId);
    d.addDatasetId(genericId);
    when(dacDAO.findDacsForDatasetIds(any())).thenReturn(Collections.singleton(d));
    initService();
    List<DataAccessRequestManage> manages = service.describeDataAccessRequestManageV2(user, UserRoles.ADMIN);
    assertNotNull(manages);
    assertFalse(manages.isEmpty());
    assertEquals(dar.getReferenceId(), manages.get(0).getDar().getReferenceId());
    assertEquals(1, manages.size());
    assertEquals(e.getElectionId(), manages.get(0).getElection().getElectionId());
    assertEquals(d.getDacId(), manages.get(0).getDac().getDacId());
    assertFalse(manages.get(0).getVotes().isEmpty());
}
Also used : DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) Vote(org.broadinstitute.consent.http.models.Vote) User(org.broadinstitute.consent.http.models.User) AuthUser(org.broadinstitute.consent.http.models.AuthUser) DataAccessRequestManage(org.broadinstitute.consent.http.models.DataAccessRequestManage) Dac(org.broadinstitute.consent.http.models.Dac) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 99 with Dac

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

the class DataAccessRequestServiceTest method testDescribeDataAccessRequestManageV2_Researcher.

@Test
public void testDescribeDataAccessRequestManageV2_Researcher() {
    User user = new User();
    user.setRoles(Arrays.asList(new UserRole(5, UserRoles.RESEARCHER.getRoleName())));
    Integer genericId = 1;
    DataAccessRequest dar = generateDataAccessRequest();
    dar.setData(new DataAccessRequestData());
    dar.getData().setDatasetIds(Collections.singletonList(genericId));
    when(dataAccessRequestDAO.findAllDarsByUserId(any())).thenReturn(Collections.singletonList(dar));
    Election e = new Election();
    e.setReferenceId(dar.getReferenceId());
    e.setElectionId(genericId);
    when(electionDAO.findLastElectionsByReferenceIdsAndType(any(), any())).thenReturn(Collections.singletonList(e));
    Vote v = new Vote();
    v.setVoteId(genericId);
    v.setElectionId(e.getElectionId());
    when(voteDAO.findVotesByElectionIds(any())).thenReturn(Collections.singletonList(v));
    Dac d = new Dac();
    d.setDacId(genericId);
    d.addDatasetId(genericId);
    when(dacDAO.findDacsForDatasetIds(any())).thenReturn(Collections.singleton(d));
    initService();
    List<DataAccessRequestManage> manages = service.describeDataAccessRequestManageV2(user, UserRoles.RESEARCHER);
    assertNotNull(manages);
    assertFalse(manages.isEmpty());
    assertEquals(dar.getReferenceId(), manages.get(0).getDar().getReferenceId());
    assertEquals(1, manages.size());
    assertEquals(e.getElectionId(), manages.get(0).getElection().getElectionId());
    assertEquals(d.getDacId(), manages.get(0).getDac().getDacId());
    assertFalse(manages.get(0).getVotes().isEmpty());
}
Also used : DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) Vote(org.broadinstitute.consent.http.models.Vote) User(org.broadinstitute.consent.http.models.User) AuthUser(org.broadinstitute.consent.http.models.AuthUser) DataAccessRequestManage(org.broadinstitute.consent.http.models.DataAccessRequestManage) UserRole(org.broadinstitute.consent.http.models.UserRole) Dac(org.broadinstitute.consent.http.models.Dac) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) Test(org.junit.Test)

Example 100 with Dac

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

the class DacServiceTest method testRemoveDacMember.

@Test
public void testRemoveDacMember() {
    Role role = new Role(UserRoles.MEMBER.getRoleId(), UserRoles.MEMBER.getRoleName());
    Dac dac = getDacs().get(0);
    User member = getDacUsers().get(1);
    dac.setChairpersons(Collections.singletonList(getDacUsers().get(0)));
    dac.setMembers(Collections.singletonList(member));
    doNothing().when(dacDAO).removeDacMember(anyInt());
    doNothing().when(voteService).deleteOpenDacVotesForUser(any(), any());
    initService();
    try {
        service.removeDacMember(role, member, dac);
    } catch (Exception e) {
        Assert.fail();
    }
    verify(dacDAO, atLeastOnce()).removeDacMember(anyInt());
    verify(voteService, atLeastOnce()).deleteOpenDacVotesForUser(any(), any());
}
Also used : Role(org.broadinstitute.consent.http.models.Role) UserRole(org.broadinstitute.consent.http.models.UserRole) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) BadRequestException(javax.ws.rs.BadRequestException) Test(org.junit.Test)

Aggregations

Dac (org.broadinstitute.consent.http.models.Dac)125 Test (org.junit.Test)99 User (org.broadinstitute.consent.http.models.User)81 Consent (org.broadinstitute.consent.http.models.Consent)65 DataSet (org.broadinstitute.consent.http.models.DataSet)58 Election (org.broadinstitute.consent.http.models.Election)53 Vote (org.broadinstitute.consent.http.models.Vote)37 AuthUser (org.broadinstitute.consent.http.models.AuthUser)30 ElectionReviewVote (org.broadinstitute.consent.http.models.ElectionReviewVote)22 Date (java.util.Date)19 Response (javax.ws.rs.core.Response)19 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)15 UserRole (org.broadinstitute.consent.http.models.UserRole)14 BadRequestException (javax.ws.rs.BadRequestException)13 NotFoundException (javax.ws.rs.NotFoundException)12 Role (org.broadinstitute.consent.http.models.Role)11 DacBuilder (org.broadinstitute.consent.http.models.DacBuilder)10 ArrayList (java.util.ArrayList)8 RolesAllowed (javax.annotation.security.RolesAllowed)8 List (java.util.List)7