Search in sources :

Example 1 with Dac

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

the class DacWithDatasetsReducer method accumulate.

@Override
public void accumulate(Map<Integer, Dac> container, RowView rowView) {
    try {
        Dac dac = container.computeIfAbsent(rowView.getColumn("dac_id", Integer.class), id -> rowView.getRow(Dac.class));
        if (Objects.nonNull(rowView.getColumn("datasetid", Integer.class))) {
            DatasetDTO dto = rowView.getRow(DatasetDTO.class);
            try {
                if (Objects.nonNull(rowView.getColumn("dataset_alias", String.class))) {
                    String dsAlias = rowView.getColumn("dataset_alias", String.class);
                    try {
                        dto.setAlias(Integer.parseInt(dsAlias));
                    } catch (Exception e) {
                        logger.error("Exception parsing dataset alias: " + dsAlias, e);
                    }
                }
                if (Objects.nonNull(rowView.getColumn("dataset_create_date", Date.class))) {
                    Date createDate = rowView.getColumn("dataset_create_date", Date.class);
                    dto.setCreateDate(createDate);
                }
                if (Objects.nonNull(rowView.getColumn("dataset_update_date", Timestamp.class))) {
                    Timestamp updateDate = rowView.getColumn("dataset_update_date", Timestamp.class);
                    dto.setUpdateDate(updateDate);
                }
            } catch (Exception e) {
            // no values for these columns
            }
            if (Objects.nonNull(rowView.getColumn("consent_data_use", String.class))) {
                String duStr = rowView.getColumn("consent_data_use", String.class);
                Optional<DataUse> du = DataUse.parseDataUse(duStr);
                du.ifPresent(dto::setDataUse);
            }
            if (Objects.nonNull(dto)) {
                dac.addDatasetDTO(dto);
            }
        }
    } catch (MappingException e) {
        logger.warn(e.getMessage());
    }
}
Also used : DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) DataUse(org.broadinstitute.consent.http.models.DataUse) Dac(org.broadinstitute.consent.http.models.Dac) Timestamp(java.sql.Timestamp) MappingException(org.jdbi.v3.core.mapper.MappingException) Date(java.sql.Date) MappingException(org.jdbi.v3.core.mapper.MappingException)

Example 2 with Dac

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

the class MetricsServiceTest method generateDac.

private Dac generateDac() {
    Dac dac = new Dac();
    dac.setDacId(1);
    dac.setDescription("description");
    dac.setName("dac1");
    User chairUser = new User();
    chairUser.setDacUserId(1);
    chairUser.setEmail("chair@test.org");
    chairUser.setDisplayName("Chair");
    UserRole chairRole = new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
    chairUser.setRoles(Collections.singletonList(chairRole));
    User memberUser = new User();
    memberUser.setDacUserId(2);
    memberUser.setEmail("member@test.org");
    memberUser.setDisplayName("Member");
    UserRole memberRole = new UserRole(UserRoles.MEMBER.getRoleId(), UserRoles.MEMBER.getRoleName());
    memberUser.setRoles(Collections.singletonList(memberRole));
    dac.setChairpersons(Collections.singletonList(chairUser));
    dac.setMembers(Collections.singletonList(memberUser));
    return dac;
}
Also used : User(org.broadinstitute.consent.http.models.User) UserRole(org.broadinstitute.consent.http.models.UserRole) Dac(org.broadinstitute.consent.http.models.Dac)

Example 3 with Dac

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

the class DacResourceTest method testFindById_success.

@Test
public void testFindById_success() {
    Dac dac = new DacBuilder().setDacId(1).setName("name").setDescription("description").build();
    when(dacService.findById(1)).thenReturn(dac);
    Response response = dacResource.findById(dac.getDacId());
    assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) DacBuilder(org.broadinstitute.consent.http.models.DacBuilder) Dac(org.broadinstitute.consent.http.models.Dac) Test(org.junit.Test)

Example 4 with Dac

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

the class DacResourceTest method testRemoveDacChairAsAdmin.

@Test
public void testRemoveDacChairAsAdmin() {
    Dac dac = buildDac(null);
    when(dacService.findById(any())).thenReturn(dac);
    User admin = buildAdmin(authUser);
    User member = buildUser();
    when(userService.findUserByEmail(authUser.getEmail())).thenReturn(admin);
    when(dacService.findUserById(member.getDacUserId())).thenReturn(member);
    Response response = dacResource.removeDacChair(authUser, dac.getDacId(), member.getDacUserId());
    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) Dac(org.broadinstitute.consent.http.models.Dac) Test(org.junit.Test)

Example 5 with Dac

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

the class ConsentElectionResource method createConsentElectionForDac.

@POST
@Consumes("application/json")
@Path("/dac/{dacId}")
@RolesAllowed({ ADMIN, CHAIRPERSON })
public Response createConsentElectionForDac(@Auth AuthUser authUser, @Context UriInfo info, @PathParam("consentId") String consentId, @PathParam("dacId") Integer dacId, Election election) {
    URI uri;
    try {
        Consent consent = consentService.getById(consentId);
        Dac dac = dacService.findById(dacId);
        if (dac == null) {
            throw new NotFoundException("Cannot find DAC with the provided id: " + dacId);
        }
        if (consent.getDacId() != null && !consent.getDacId().equals(dacId)) {
            throw new BadRequestException("Consent is already associated to a DAC.");
        }
        try {
            consentService.updateConsentDac(consentId, dacId);
        } catch (Exception e) {
            logger().error("Exception updating consent id: '" + consentId + "', with dac id: '" + dacId + "'");
            throw new InternalServerErrorException("Unable to associate consent to dac.");
        }
        uri = createElectionURI(info, election, consentId);
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
    return Response.created(uri).build();
}
Also used : Consent(org.broadinstitute.consent.http.models.Consent) Dac(org.broadinstitute.consent.http.models.Dac) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) URI(java.net.URI) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

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