Search in sources :

Example 6 with Consent

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

the class DatasetResourceTest method testDisableDataSetSuccessChairperson.

@Test
public void testDisableDataSetSuccessChairperson() {
    DataSet dataSet = new DataSet();
    dataSet.setDataSetId(1);
    Consent consent = new Consent();
    consent.setDacId(1);
    when(consentService.getConsentFromDatasetID(any())).thenReturn(consent);
    when(dacUser.hasUserRole(UserRoles.ADMIN)).thenReturn(false);
    UserRole role = new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
    role.setDacId(1);
    when(dacUser.getRoles()).thenReturn(List.of(role));
    when(userService.findUserByEmail(authUser.getEmail())).thenReturn(dacUser);
    when(datasetService.findDatasetById(any())).thenReturn(dataSet);
    initResource();
    Response response = resource.disableDataSet(authUser, 1, true, null);
    assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) DataSet(org.broadinstitute.consent.http.models.DataSet) Consent(org.broadinstitute.consent.http.models.Consent) UserRole(org.broadinstitute.consent.http.models.UserRole) Test(org.junit.Test)

Example 7 with Consent

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

the class DatasetResourceTest method testDisableDataSetErrorNullConsent.

@Test
public void testDisableDataSetErrorNullConsent() {
    DataSet dataSet = new DataSet();
    dataSet.setDataSetId(1);
    Consent consent = new Consent();
    when(consentService.getConsentFromDatasetID(any())).thenReturn(consent);
    when(dacUser.hasUserRole(UserRoles.ADMIN)).thenReturn(false);
    UserRole role = new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
    role.setDacId(1);
    when(dacUser.getRoles()).thenReturn(List.of(role));
    when(userService.findUserByEmail(authUser.getEmail())).thenReturn(dacUser);
    when(datasetService.findDatasetById(any())).thenReturn(dataSet);
    initResource();
    Response response = resource.disableDataSet(authUser, 1, true, null);
    assertEquals(404, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) DataSet(org.broadinstitute.consent.http.models.DataSet) Consent(org.broadinstitute.consent.http.models.Consent) UserRole(org.broadinstitute.consent.http.models.UserRole) Test(org.junit.Test)

Example 8 with Consent

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

the class DatasetResourceTest method testDeleteErrorMismatch.

@Test
public void testDeleteErrorMismatch() {
    DataSet dataSet = new DataSet();
    dataSet.setDataSetId(1);
    Consent consent = new Consent();
    consent.setDacId(2);
    when(consentService.getConsentFromDatasetID(any())).thenReturn(consent);
    when(dacUser.hasUserRole(UserRoles.ADMIN)).thenReturn(false);
    UserRole role = new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
    role.setDacId(1);
    when(dacUser.getRoles()).thenReturn(List.of(role));
    when(userService.findUserByEmail(authUser.getEmail())).thenReturn(dacUser);
    when(datasetService.findDatasetById(any())).thenReturn(dataSet);
    initResource();
    Response response = resource.delete(authUser, 1, null);
    assertEquals(404, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) DataSet(org.broadinstitute.consent.http.models.DataSet) Consent(org.broadinstitute.consent.http.models.Consent) UserRole(org.broadinstitute.consent.http.models.UserRole) Test(org.junit.Test)

Example 9 with Consent

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

the class DatasetResourceTest method testCreateDatasetSuccess.

@Test
public void testCreateDatasetSuccess() throws Exception {
    DatasetDTO result = createMockDatasetDTO();
    Consent consent = new Consent();
    String json = createPropertiesJson("Dataset Name", "test");
    when(datasetService.getDatasetByName("test")).thenReturn(null);
    when(datasetService.createDatasetWithConsent(any(), any(), anyInt())).thenReturn(result);
    when(datasetService.createConsentForDataset(any())).thenReturn(consent);
    when(datasetService.getDatasetDTO(any())).thenReturn(result);
    when(authUser.getGoogleUser()).thenReturn(googleUser);
    when(googleUser.getEmail()).thenReturn("email@email.com");
    when(userService.findUserByEmail(any())).thenReturn(dacUser);
    when(dacUser.getDacUserId()).thenReturn(1);
    when(uriInfo.getRequestUriBuilder()).thenReturn(uriBuilder);
    when(uriBuilder.replacePath(anyString())).thenReturn(uriBuilder);
    when(uriBuilder.build(anyString())).thenReturn(new URI("/api/dataset/1"));
    initResource();
    Response response = resource.createDataset(authUser, uriInfo, json);
    assertEquals(201, response.getStatus());
    assertEquals(result, response.getEntity());
}
Also used : DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) Response(javax.ws.rs.core.Response) Consent(org.broadinstitute.consent.http.models.Consent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) URI(java.net.URI) Test(org.junit.Test)

Example 10 with Consent

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

the class ConsentElectionResource method createElectionURI.

private URI createElectionURI(UriInfo info, Election election, String consentId) throws Exception {
    // For a consent election, any dataset associated to the consent is
    // appropriate for assignment to this election.
    Optional<DataSet> dataset = dacService.findDatasetsByConsentId(consentId).stream().findFirst();
    dataset.ifPresent(dataSet -> election.setDataSetId(dataSet.getDataSetId()));
    Election newElection = electionService.createElection(election, consentId, ElectionType.TRANSLATE_DUL);
    List<Vote> votes = voteService.createVotes(newElection, ElectionType.TRANSLATE_DUL, false);
    List<Vote> dulVotes = votes.stream().filter(vote -> vote.getType().equals(VoteType.DAC.getValue())).collect(Collectors.toList());
    emailNotifierService.sendNewCaseMessageToList(dulVotes, newElection);
    return info.getRequestUriBuilder().build();
}
Also used : PathParam(javax.ws.rs.PathParam) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) Inject(com.google.inject.Inject) Path(javax.ws.rs.Path) Auth(io.dropwizard.auth.Auth) Vote(org.broadinstitute.consent.http.models.Vote) ConsentService(org.broadinstitute.consent.http.service.ConsentService) VoteService(org.broadinstitute.consent.http.service.VoteService) ElectionService(org.broadinstitute.consent.http.service.ElectionService) MediaType(javax.ws.rs.core.MediaType) VoteType(org.broadinstitute.consent.http.enumeration.VoteType) Consumes(javax.ws.rs.Consumes) ElectionType(org.broadinstitute.consent.http.enumeration.ElectionType) AuthUser(org.broadinstitute.consent.http.models.AuthUser) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI) Status(javax.ws.rs.core.Response.Status) EmailNotifierService(org.broadinstitute.consent.http.service.EmailNotifierService) DELETE(javax.ws.rs.DELETE) DataSet(org.broadinstitute.consent.http.models.DataSet) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Error(org.broadinstitute.consent.http.models.dto.Error) Collectors(java.util.stream.Collectors) Dac(org.broadinstitute.consent.http.models.Dac) NotFoundException(javax.ws.rs.NotFoundException) List(java.util.List) Response(javax.ws.rs.core.Response) DacService(org.broadinstitute.consent.http.service.DacService) Election(org.broadinstitute.consent.http.models.Election) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) Consent(org.broadinstitute.consent.http.models.Consent) Vote(org.broadinstitute.consent.http.models.Vote) DataSet(org.broadinstitute.consent.http.models.DataSet) Election(org.broadinstitute.consent.http.models.Election)

Aggregations

Consent (org.broadinstitute.consent.http.models.Consent)163 Test (org.junit.Test)127 DataSet (org.broadinstitute.consent.http.models.DataSet)86 Election (org.broadinstitute.consent.http.models.Election)72 Dac (org.broadinstitute.consent.http.models.Dac)61 User (org.broadinstitute.consent.http.models.User)56 Vote (org.broadinstitute.consent.http.models.Vote)48 ElectionReviewVote (org.broadinstitute.consent.http.models.ElectionReviewVote)32 Response (javax.ws.rs.core.Response)31 Date (java.util.Date)25 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)23 UnknownIdentifierException (org.broadinstitute.consent.http.exceptions.UnknownIdentifierException)13 NotFoundException (javax.ws.rs.NotFoundException)12 AuthUser (org.broadinstitute.consent.http.models.AuthUser)12 IOException (java.io.IOException)8 DatasetDTO (org.broadinstitute.consent.http.models.dto.DatasetDTO)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 Timestamp (java.sql.Timestamp)6 List (java.util.List)6