Search in sources :

Example 1 with DatasetDTO

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

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

the class DataSetPropertiesMapper method map.

public DatasetDTO map(ResultSet r, StatementContext ctx) throws SQLException {
    DatasetDTO dataSetDTO;
    Integer dataSetId = r.getInt("dataSetId");
    String consentId = r.getString("consentId");
    Integer alias = r.getInt("alias");
    if (!dataSets.containsKey(dataSetId)) {
        dataSetDTO = new DatasetDTO(new ArrayList<>());
        if (hasColumn(r, "dac_id")) {
            int dacId = r.getInt("dac_id");
            if (dacId > 0) {
                dataSetDTO.setDacId(dacId);
            }
        }
        dataSetDTO.setConsentId(consentId);
        dataSetDTO.setAlias(alias);
        dataSetDTO.setDataSetId(dataSetId);
        dataSetDTO.setActive(r.getBoolean("active"));
        dataSetDTO.setTranslatedUseRestriction(r.getString("translatedUseRestriction"));
        if (hasColumn(r, "datause")) {
            dataSetDTO.setDataUse(DataUse.parseDataUse(r.getString("datause")).orElse(null));
        }
        if (hasColumn(r, "createdate")) {
            dataSetDTO.setCreateDate(r.getDate("createdate"));
        }
        if (hasColumn(r, "create_user_id")) {
            int userId = r.getInt("create_user_id");
            if (userId > 0) {
                dataSetDTO.setCreateUserId(userId);
            }
        }
        if (hasColumn(r, "update_date")) {
            dataSetDTO.setUpdateDate(r.getTimestamp("update_date"));
        }
        if (hasColumn(r, "update_user_id")) {
            int userId = r.getInt("update_user_id");
            if (userId > 0) {
                dataSetDTO.setUpdateUserId(userId);
            }
        }
        DataSetPropertyDTO property = new DataSetPropertyDTO("Dataset Name", r.getString("name"));
        dataSetDTO.addProperty(property);
        property = new DataSetPropertyDTO(r.getString(PROPERTY_KEY), r.getString(PROPERTY_PROPERTYVALUE));
        if (property.getPropertyName() != null) {
            dataSetDTO.addProperty(property);
        }
        dataSetDTO.setNeedsApproval(r.getBoolean("needs_approval"));
        dataSetDTO.setObjectId(r.getString("objectId"));
        dataSets.put(dataSetId, dataSetDTO);
    } else {
        dataSetDTO = dataSets.get(dataSetId);
        DataSetPropertyDTO property = new DataSetPropertyDTO(r.getString(PROPERTY_KEY), r.getString(PROPERTY_PROPERTYVALUE));
        if (property.getPropertyName() != null) {
            dataSetDTO.addProperty(property);
        }
    }
    return dataSetDTO;
}
Also used : DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) DataSetPropertyDTO(org.broadinstitute.consent.http.models.dto.DataSetPropertyDTO) ArrayList(java.util.ArrayList)

Example 3 with DatasetDTO

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

the class DatasetResourceTest method testDescribeDataSetSuccess.

@Test
public void testDescribeDataSetSuccess() {
    DatasetDTO testDTO = createMockDatasetDTO();
    when(datasetService.getDatasetDTO(any())).thenReturn(testDTO);
    initResource();
    Response response = resource.describeDataSet(1);
    assertEquals(200, response.getStatus());
}
Also used : DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) Response(javax.ws.rs.core.Response) Test(org.junit.Test)

Example 4 with DatasetDTO

use of org.broadinstitute.consent.http.models.dto.DatasetDTO 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 5 with DatasetDTO

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

the class DatasetResource method downloadDataSets.

@POST
@Path("/download")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
public Response downloadDataSets(List<Integer> idList) {
    try {
        String msg = "GETing DataSets to download";
        logger().debug(msg);
        JSONObject json = new JSONObject();
        Collection<Dictionary> headers = datasetService.describeDictionaryByReceiveOrder();
        StringBuilder sb = new StringBuilder();
        String TSV_DELIMITER = "\t";
        for (Dictionary header : headers) {
            if (sb.length() > 0)
                sb.append(TSV_DELIMITER);
            sb.append(header.getKey());
        }
        sb.append(END_OF_LINE);
        if (CollectionUtils.isEmpty(idList)) {
            json.put("datasets", sb.toString());
            return Response.ok(json.toString(), MediaType.APPLICATION_JSON).build();
        }
        Collection<DatasetDTO> rows = datasetService.describeDataSetsByReceiveOrder(idList);
        for (DatasetDTO row : rows) {
            StringBuilder sbr = new StringBuilder();
            DataSetPropertyDTO property = new DataSetPropertyDTO("Consent ID", row.getConsentId());
            List<DataSetPropertyDTO> props = row.getProperties();
            props.add(property);
            for (DataSetPropertyDTO prop : props) {
                if (sbr.length() > 0)
                    sbr.append(TSV_DELIMITER);
                sbr.append(prop.getPropertyValue());
            }
            sbr.append(END_OF_LINE);
            sb.append(sbr);
        }
        String tsv = sb.toString();
        json.put("datasets", tsv);
        return Response.ok(json.toString(), MediaType.APPLICATION_JSON).build();
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
}
Also used : DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) Dictionary(org.broadinstitute.consent.http.models.Dictionary) JSONObject(org.json.JSONObject) DataSetPropertyDTO(org.broadinstitute.consent.http.models.dto.DataSetPropertyDTO) ClientErrorException(javax.ws.rs.ClientErrorException) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PermitAll(javax.annotation.security.PermitAll)

Aggregations

DatasetDTO (org.broadinstitute.consent.http.models.dto.DatasetDTO)29 Test (org.junit.Test)15 DataSet (org.broadinstitute.consent.http.models.DataSet)13 DataSetPropertyDTO (org.broadinstitute.consent.http.models.dto.DataSetPropertyDTO)10 NotFoundException (javax.ws.rs.NotFoundException)8 Consent (org.broadinstitute.consent.http.models.Consent)8 ArrayList (java.util.ArrayList)5 Timestamp (java.sql.Timestamp)4 Dac (org.broadinstitute.consent.http.models.Dac)4 DataUse (org.broadinstitute.consent.http.models.DataUse)4 User (org.broadinstitute.consent.http.models.User)4 Gson (com.google.gson.Gson)3 URI (java.net.URI)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3