Search in sources :

Example 6 with EnumerateDatasetModel

use of bio.terra.model.EnumerateDatasetModel in project jade-data-repo by DataBiosphere.

the class AccessTest method checkCustodianPermissions.

@Test
public void checkCustodianPermissions() throws Exception {
    makeIngestTestDataset();
    IngestRequestModel request = dataRepoFixtures.buildSimpleIngest("participant", "ingest-test/ingest-test-participant.json");
    dataRepoFixtures.ingestJsonData(steward(), datasetId, request);
    request = dataRepoFixtures.buildSimpleIngest("sample", "ingest-test/ingest-test-sample.json");
    dataRepoFixtures.ingestJsonData(steward(), datasetId, request);
    DatasetModel dataset = dataRepoFixtures.getDataset(steward(), datasetId);
    String datasetBqSnapshotName = PdaoConstant.PDAO_PREFIX + dataset.getName();
    BigQuery custodianBigQuery = BigQueryFixtures.getBigQuery(dataset.getDataProject(), custodianToken);
    try {
        BigQueryFixtures.datasetExists(custodianBigQuery, dataset.getDataProject(), datasetBqSnapshotName);
        fail("custodian shouldn't be able to access bq dataset before it is shared with them");
    } catch (IllegalStateException e) {
        assertThat("checking message for pdao exception error", e.getMessage(), equalTo("existence check failed for " + datasetBqSnapshotName));
    }
    dataRepoFixtures.addDatasetPolicyMember(steward(), datasetId, IamRole.CUSTODIAN, custodian().getEmail());
    DataRepoResponse<EnumerateDatasetModel> enumDatasets = dataRepoFixtures.enumerateDatasetsRaw(custodian());
    assertThat("Custodian is authorized to enumerate datasets", enumDatasets.getStatusCode(), equalTo(HttpStatus.OK));
    boolean custodianHasAccess = BigQueryFixtures.hasAccess(custodianBigQuery, dataset.getDataProject(), datasetBqSnapshotName);
    assertTrue("custodian can access the bq snapshot after it has been shared", custodianHasAccess);
    // gets the "sample" table and makes a table ref to use in the query
    String tableRef = BigQueryFixtures.makeTableRef(dataset, dataset.getSchema().getTables().get(1).getName());
    String sql = String.format("SELECT * FROM %s LIMIT %s", tableRef, 1000);
    TableResult results = BigQueryFixtures.query(sql, custodianBigQuery);
    Assert.assertEquals(7, results.getTotalRows());
}
Also used : BigQuery(com.google.cloud.bigquery.BigQuery) TableResult(com.google.cloud.bigquery.TableResult) IngestRequestModel(bio.terra.model.IngestRequestModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) DatasetModel(bio.terra.model.DatasetModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 7 with EnumerateDatasetModel

use of bio.terra.model.EnumerateDatasetModel in project jade-data-repo by DataBiosphere.

the class DatasetService method enumerate.

public EnumerateDatasetModel enumerate(int offset, int limit, String sort, String direction, String filter, List<UUID> resources) {
    if (resources.isEmpty()) {
        return new EnumerateDatasetModel().total(0);
    }
    MetadataEnumeration<DatasetSummary> datasetEnum = datasetDao.enumerate(offset, limit, sort, direction, filter, resources);
    List<DatasetSummaryModel> summaries = datasetEnum.getItems().stream().map(DatasetJsonConversion::datasetSummaryModelFromDatasetSummary).collect(Collectors.toList());
    return new EnumerateDatasetModel().items(summaries).total(datasetEnum.getTotal());
}
Also used : DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel)

Aggregations

EnumerateDatasetModel (bio.terra.model.EnumerateDatasetModel)7 DatasetModel (bio.terra.model.DatasetModel)5 Test (org.junit.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)4 IngestRequestModel (bio.terra.model.IngestRequestModel)2 BigQuery (com.google.cloud.bigquery.BigQuery)2 UUID (java.util.UUID)2 DeleteResponseModel (bio.terra.model.DeleteResponseModel)1 JobModel (bio.terra.model.JobModel)1 SnapshotModel (bio.terra.model.SnapshotModel)1 SnapshotSummaryModel (bio.terra.model.SnapshotSummaryModel)1 TableResult (com.google.cloud.bigquery.TableResult)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ResponseEntity (org.springframework.http.ResponseEntity)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1