Search in sources :

Example 1 with DataUse

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

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

the class UseRestrictionConverterTest method testTranslateFalseValues.

/*
     * Test that the DataUse parser does not set false values incorrectly
     */
@Test
public void testTranslateFalseValues() {
    Client client = ClientBuilder.newClient();
    UseRestrictionConverter converter = new UseRestrictionConverter(client, config());
    String json = "{ " + "\"methods\":false, " + "\"population\":false, " + "\"controls\":false, " + "\"poa\":false, " + "\"hmb\":false " + "}";
    DataUse dataUse = converter.parseDataUsePurpose(json);
    assertNull(dataUse.getMethodsResearch());
    assertNull(dataUse.getPopulationStructure());
    assertNull(dataUse.getControlSetOption());
    assertNull(dataUse.getPopulationOriginsAncestry());
    assertNull(dataUse.getHmbResearch());
}
Also used : DataUse(org.broadinstitute.consent.http.models.DataUse) Client(javax.ws.rs.client.Client) MockServerClient(org.mockserver.client.MockServerClient) Test(org.junit.Test)

Example 3 with DataUse

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

the class UseRestrictionConverterTest method testFailedUseRestrictionConverterConnection.

/*
     * Test that when the UseRestrictionConverter makes a failed call to the ontology service, a null is returned.
     */
@Test
public void testFailedUseRestrictionConverterConnection() {
    mockDarTranslateFailure();
    Client client = ClientBuilder.newClient();
    UseRestrictionConverter converter = new UseRestrictionConverter(client, config());
    DataUse dataUse = converter.parseDataUsePurpose("{  }");
    UseRestriction restriction = converter.parseUseRestriction(dataUse);
    assertNull(restriction);
}
Also used : DataUse(org.broadinstitute.consent.http.models.DataUse) UseRestriction(org.broadinstitute.consent.http.models.grammar.UseRestriction) Client(javax.ws.rs.client.Client) MockServerClient(org.mockserver.client.MockServerClient) Test(org.junit.Test)

Example 4 with DataUse

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

the class UseRestrictionConverterTest method testTranslateDataUsePurpose.

/*
     * Test that the UseRestrictionConverter makes a call to the ontology service and gets back a valid translation
     */
@Test
public void testTranslateDataUsePurpose() {
    mockDataUseTranslateSuccess();
    Client client = ClientBuilder.newClient();
    UseRestrictionConverter converter = new UseRestrictionConverter(client, config());
    DataUse dataUse = new DataUseBuilder().setHmbResearch(true).build();
    String translation = converter.translateDataUse(dataUse, DataUseTranslationType.PURPOSE);
    assertNotNull(translation);
}
Also used : DataUse(org.broadinstitute.consent.http.models.DataUse) DataUseBuilder(org.broadinstitute.consent.http.models.DataUseBuilder) Client(javax.ws.rs.client.Client) MockServerClient(org.mockserver.client.MockServerClient) Test(org.junit.Test)

Example 5 with DataUse

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

the class UseRestrictionConverterTest method testParseDataUseInvalidOntologiesCase1.

/*
     * Testing a DataUse with invalid ontologies.
     */
@Test
public void testParseDataUseInvalidOntologiesCase1() {
    String json = "{ " + "\"hmb\":true, " + "\"ontologies\":[{},{},{}]" + "}";
    Client client = ClientBuilder.newClient();
    UseRestrictionConverter converter = new UseRestrictionConverter(client, config());
    DataUse dataUse = converter.parseDataUsePurpose(json);
    assertNotNull(dataUse);
    assertNull(dataUse.getDiseaseRestrictions());
}
Also used : DataUse(org.broadinstitute.consent.http.models.DataUse) Client(javax.ws.rs.client.Client) MockServerClient(org.mockserver.client.MockServerClient) Test(org.junit.Test)

Aggregations

DataUse (org.broadinstitute.consent.http.models.DataUse)18 Client (javax.ws.rs.client.Client)11 Test (org.junit.Test)11 MockServerClient (org.mockserver.client.MockServerClient)10 DataUseBuilder (org.broadinstitute.consent.http.models.DataUseBuilder)5 UseRestriction (org.broadinstitute.consent.http.models.grammar.UseRestriction)5 Consent (org.broadinstitute.consent.http.models.Consent)3 DatasetDTO (org.broadinstitute.consent.http.models.dto.DatasetDTO)3 Everything (org.broadinstitute.consent.http.models.grammar.Everything)3 Timestamp (java.sql.Timestamp)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 IOException (java.io.IOException)1 Date (java.sql.Date)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1