Search in sources :

Example 1 with DataAccessRequestManage

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

the class DataAccessRequestResourceTest method testDescribeManageDataAccessRequestsV2_WithRole.

@Test
public void testDescribeManageDataAccessRequestsV2_WithRole() {
    User researcher = new User();
    researcher.setDacUserId(1);
    researcher.setRoles(Arrays.asList(new UserRole(5, UserRoles.RESEARCHER.getRoleName())));
    when(userService.findUserByEmail(any())).thenReturn(researcher);
    DataAccessRequest dar = generateDataAccessRequest();
    DataAccessRequestManage manage = new DataAccessRequestManage();
    manage.setDar(dar);
    when(dataAccessRequestService.describeDataAccessRequestManageV2(any(), any())).thenReturn(Collections.singletonList(manage));
    resource = new DataAccessRequestResource(dataAccessRequestService, userService, consentService, electionService);
    Response response = resource.describeManageDataAccessRequestsV2(authUser, Optional.of("Researcher"));
    assertEquals(HttpStatusCodes.STATUS_CODE_OK, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) DataAccessRequestManage(org.broadinstitute.consent.http.models.DataAccessRequestManage) UserRole(org.broadinstitute.consent.http.models.UserRole) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Test(org.junit.Test)

Example 2 with DataAccessRequestManage

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

the class DataAccessRequestResourceVersion2 method getDraftManageDataAccessRequests.

@GET
@Produces("application/json")
@Path("/draft/manage")
@RolesAllowed(RESEARCHER)
public Response getDraftManageDataAccessRequests(@Auth AuthUser authUser) {
    try {
        User user = findUserByEmail(authUser.getEmail());
        List<DataAccessRequestManage> partials = dataAccessRequestService.getDraftDataAccessRequestManage(user.getDacUserId());
        return Response.ok().entity(partials).build();
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
}
Also used : AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) DataAccessRequestManage(org.broadinstitute.consent.http.models.DataAccessRequestManage) ForbiddenException(javax.ws.rs.ForbiddenException) IOException(java.io.IOException) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with DataAccessRequestManage

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

the class DataAccessRequestServiceTest method testDescribeDataAccessRequestManageV2_SO.

@Test
public void testDescribeDataAccessRequestManageV2_SO() {
    User user = new User();
    user.setInstitutionId(1);
    user.setRoles(new ArrayList<>());
    user.getRoles().add(new UserRole(7, UserRoles.SIGNINGOFFICIAL.getRoleName()));
    Integer genericId = 1;
    DataAccessRequest dar = generateDataAccessRequest();
    dar.setData(new DataAccessRequestData());
    dar.getData().setDatasetIds(Collections.singletonList(genericId));
    when(dataAccessRequestDAO.findAllDataAccessRequestsForInstitution(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.SIGNINGOFFICIAL);
    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 4 with DataAccessRequestManage

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

the class DataAccessRequestServiceTest method getDraftDataAccessRequestManage_NullUserId.

@Test
public void getDraftDataAccessRequestManage_NullUserId() {
    DataAccessRequest dar = new DataAccessRequest();
    dar.setReferenceId("referenceId");
    dar.setUserId(1);
    DataAccessRequestData data = new DataAccessRequestData();
    data.setDatasetIds(Arrays.asList(361));
    dar.setData(data);
    when(dataAccessRequestDAO.findAllDraftDataAccessRequests()).thenReturn(Arrays.asList(dar));
    initService();
    List<DataAccessRequestManage> darManages = service.getDraftDataAccessRequestManage(null);
    assertEquals(1, darManages.size());
}
Also used : DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) DataAccessRequestManage(org.broadinstitute.consent.http.models.DataAccessRequestManage) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Test(org.junit.Test)

Example 5 with DataAccessRequestManage

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

the class DataAccessRequestResourceTest method testDescribeManageDataAccessRequestsV2.

@Test
public void testDescribeManageDataAccessRequestsV2() {
    User user = new User();
    user.setRoles(Collections.singletonList(new UserRole(4, UserRoles.ADMIN.getRoleName())));
    DataAccessRequest dar = generateDataAccessRequest();
    DataAccessRequestManage manage = new DataAccessRequestManage();
    manage.setDar(dar);
    when(userService.findUserByEmail(any())).thenReturn(user);
    when(dataAccessRequestService.describeDataAccessRequestManageV2(any(), any())).thenReturn(Collections.singletonList(manage));
    resource = new DataAccessRequestResource(dataAccessRequestService, userService, consentService, electionService);
    Response response = resource.describeManageDataAccessRequestsV2(authUser, Optional.empty());
    assertEquals(HttpStatusCodes.STATUS_CODE_OK, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) DataAccessRequestManage(org.broadinstitute.consent.http.models.DataAccessRequestManage) UserRole(org.broadinstitute.consent.http.models.UserRole) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Test(org.junit.Test)

Aggregations

DataAccessRequestManage (org.broadinstitute.consent.http.models.DataAccessRequestManage)10 AuthUser (org.broadinstitute.consent.http.models.AuthUser)8 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)8 User (org.broadinstitute.consent.http.models.User)8 Test (org.junit.Test)7 DataAccessRequestData (org.broadinstitute.consent.http.models.DataAccessRequestData)6 Dac (org.broadinstitute.consent.http.models.Dac)4 Election (org.broadinstitute.consent.http.models.Election)4 UserRole (org.broadinstitute.consent.http.models.UserRole)4 Vote (org.broadinstitute.consent.http.models.Vote)4 NotFoundException (javax.ws.rs.NotFoundException)3 IOException (java.io.IOException)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 UserRoles (org.broadinstitute.consent.http.enumeration.UserRoles)2 Gson (com.google.gson.Gson)1 Inject (com.google.inject.Inject)1