Search in sources :

Example 11 with DatasetModel

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

the class DatasetIntegrationTest method datasetHappyPath.

@Test
public void datasetHappyPath() throws Exception {
    DatasetSummaryModel summaryModel = dataRepoFixtures.createDataset(steward(), "it-dataset-omop.json");
    datasetId = summaryModel.getId();
    logger.info("dataset id is " + summaryModel.getId());
    assertThat(summaryModel.getName(), startsWith(omopDatasetName));
    assertThat(summaryModel.getDescription(), equalTo(omopDatasetDesc));
    DatasetModel datasetModel = dataRepoFixtures.getDataset(steward(), summaryModel.getId());
    assertThat(datasetModel.getName(), startsWith(omopDatasetName));
    assertThat(datasetModel.getDescription(), equalTo(omopDatasetDesc));
    // There is a delay from when a resource is created in SAM to when it is available in an enumerate call.
    boolean metExpectation = TestUtils.eventualExpect(5, 60, true, () -> {
        EnumerateDatasetModel enumerateDatasetModel = dataRepoFixtures.enumerateDatasets(steward());
        boolean found = false;
        for (DatasetSummaryModel oneDataset : enumerateDatasetModel.getItems()) {
            if (oneDataset.getId().equals(datasetModel.getId())) {
                assertThat(oneDataset.getName(), startsWith(omopDatasetName));
                assertThat(oneDataset.getDescription(), equalTo(omopDatasetDesc));
                found = true;
                break;
            }
        }
        return found;
    });
    assertTrue("dataset was found in enumeration", metExpectation);
    // test allowable permissions
    dataRepoFixtures.addDatasetPolicyMember(steward(), summaryModel.getId(), IamRole.CUSTODIAN, custodian().getEmail());
    DataRepoResponse<EnumerateDatasetModel> enumDatasets = dataRepoFixtures.enumerateDatasetsRaw(custodian());
    assertThat("Custodian is authorized to enumerate datasets", enumDatasets.getStatusCode(), equalTo(HttpStatus.OK));
}
Also used : DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) 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 12 with DatasetModel

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

the class DatasetIntegrationTest method getRowIds.

private List<String> getRowIds(BigQuery bigQuery, DatasetModel dataset, String tableName, Long n) throws InterruptedException {
    String tableRef = BigQueryFixtures.makeTableRef(dataset, tableName);
    String sql = String.format("SELECT %s FROM %s LIMIT %s", PdaoConstant.PDAO_ROW_ID_COLUMN, tableRef, n);
    TableResult result = BigQueryFixtures.queryWithRetry(sql, bigQuery);
    assertThat("got right num of row ids back", result.getTotalRows(), equalTo(n));
    return StreamSupport.stream(result.getValues().spliterator(), false).map(fieldValues -> fieldValues.get(0).getStringValue()).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) SnapshotModel(bio.terra.model.SnapshotModel) TestConfiguration(bio.terra.common.configuration.TestConfiguration) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) StorageOptions(com.google.cloud.storage.StorageOptions) ByteBuffer(java.nio.ByteBuffer) BigQuery(com.google.cloud.bigquery.BigQuery) Assert.assertThat(org.junit.Assert.assertThat) After(org.junit.After) TableResult(com.google.cloud.bigquery.TableResult) SpringRunner(org.springframework.test.context.junit4.SpringRunner) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) DataDeletionTableModel(bio.terra.model.DataDeletionTableModel) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) Matchers.startsWith(org.hamcrest.Matchers.startsWith) ConfigEnum(bio.terra.service.configuration.ConfigEnum) IamRole(bio.terra.service.iam.IamRole) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) BigQueryFixtures(bio.terra.integration.BigQueryFixtures) DataDeletionGcsFileModel(bio.terra.model.DataDeletionGcsFileModel) DataRepoClient(bio.terra.integration.DataRepoClient) TestUtils(bio.terra.common.TestUtils) Matchers.equalTo(org.hamcrest.Matchers.equalTo) WriteChannel(com.google.cloud.WriteChannel) Storage(com.google.cloud.storage.Storage) IngestResponseModel(bio.terra.model.IngestResponseModel) DatasetSpecificationModel(bio.terra.model.DatasetSpecificationModel) AssetModel(bio.terra.model.AssetModel) RunWith(org.junit.runner.RunWith) DataRepoResponse(bio.terra.integration.DataRepoResponse) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) JsonLoader(bio.terra.common.fixtures.JsonLoader) StreamSupport(java.util.stream.StreamSupport) LinkedList(java.util.LinkedList) Before(org.junit.Before) Charsets(com.google.common.base.Charsets) BlobInfo(com.google.cloud.storage.BlobInfo) Logger(org.slf4j.Logger) Assert.assertTrue(org.junit.Assert.assertTrue) AuthService(bio.terra.common.auth.AuthService) Test(org.junit.Test) IOException(java.io.IOException) HttpStatus(org.springframework.http.HttpStatus) DataDeletionRequest(bio.terra.model.DataDeletionRequest) UsersBase(bio.terra.integration.UsersBase) IngestRequestModel(bio.terra.model.IngestRequestModel) AutoConfigureMockMvc(org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc) JobModel(bio.terra.model.JobModel) SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) PdaoConstant(bio.terra.common.PdaoConstant) Integration(bio.terra.common.category.Integration) DataRepoFixtures(bio.terra.integration.DataRepoFixtures) DatasetModel(bio.terra.model.DatasetModel) Collections(java.util.Collections) DatasetFixtures(bio.terra.common.fixtures.DatasetFixtures) TableResult(com.google.cloud.bigquery.TableResult)

Example 13 with DatasetModel

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

the class AccessTest method checkShared.

@Test
public void checkShared() 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 = "datarepo_" + 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);
    assertThat("custodian can access the bq snapshot after it has been shared", custodianHasAccess, equalTo(true));
    SnapshotSummaryModel snapshotSummaryModel = dataRepoFixtures.createSnapshot(custodian(), datasetSummaryModel, "ingest-test-snapshot.json");
    SnapshotModel snapshotModel = dataRepoFixtures.getSnapshot(custodian(), snapshotSummaryModel.getId());
    BigQuery bigQuery = BigQueryFixtures.getBigQuery(snapshotModel.getDataProject(), readerToken);
    try {
        BigQueryFixtures.datasetExists(bigQuery, snapshotModel.getDataProject(), snapshotModel.getName());
        fail("reader shouldn't be able to access bq dataset before it is shared with them");
    } catch (IllegalStateException e) {
        assertThat("checking message for exception error", e.getMessage(), equalTo("existence check failed for ".concat(snapshotSummaryModel.getName())));
    }
    dataRepoFixtures.addSnapshotPolicyMember(custodian(), snapshotSummaryModel.getId(), IamRole.READER, reader().getEmail());
    AuthenticatedUserRequest authenticatedReaderRequest = new AuthenticatedUserRequest().email(reader().getEmail()).token(Optional.of(readerToken));
    assertThat("correctly added reader", iamService.isAuthorized(authenticatedReaderRequest, IamResourceType.DATASNAPSHOT, snapshotSummaryModel.getId(), IamAction.READ_DATA), equalTo(true));
    boolean readerHasAccess = BigQueryFixtures.hasAccess(bigQuery, snapshotModel.getDataProject(), snapshotModel.getName());
    assertThat("reader can access the snapshot after it has been shared", readerHasAccess, equalTo(true));
}
Also used : BigQuery(com.google.cloud.bigquery.BigQuery) SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) IngestRequestModel(bio.terra.model.IngestRequestModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) DatasetModel(bio.terra.model.DatasetModel) SnapshotModel(bio.terra.model.SnapshotModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 14 with DatasetModel

use of bio.terra.model.DatasetModel 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 15 with DatasetModel

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

the class SnapshotTest method snapshotByFullViewHappyPathTest.

@Test
public void snapshotByFullViewHappyPathTest() throws Exception {
    DatasetModel dataset = dataRepoFixtures.getDataset(steward(), datasetId);
    String datasetName = dataset.getName();
    SnapshotRequestModel requestModel = jsonLoader.loadObject("ingest-test-snapshot-fullviews.json", SnapshotRequestModel.class);
    // swap in the correct dataset name (with the id at the end)
    requestModel.getContents().get(0).setDatasetName(datasetName);
    SnapshotSummaryModel snapshotSummary = dataRepoFixtures.createSnapshotWithRequest(steward(), datasetName, requestModel);
    TimeUnit.SECONDS.sleep(10);
    createdSnapshotIds.add(snapshotSummary.getId());
    SnapshotModel snapshot = dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId());
    assertEquals("new snapshot has been created", snapshot.getName(), requestModel.getName());
    assertEquals("all 5 relationships come through", snapshot.getRelationships().size(), 5);
}
Also used : SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) DatasetModel(bio.terra.model.DatasetModel) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) SnapshotModel(bio.terra.model.SnapshotModel) EnumerateSnapshotModel(bio.terra.model.EnumerateSnapshotModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

DatasetModel (bio.terra.model.DatasetModel)18 Test (org.junit.Test)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 EnumerateDatasetModel (bio.terra.model.EnumerateDatasetModel)11 BigQuery (com.google.cloud.bigquery.BigQuery)7 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)6 SnapshotModel (bio.terra.model.SnapshotModel)6 SnapshotSummaryModel (bio.terra.model.SnapshotSummaryModel)6 SnapshotRequestModel (bio.terra.model.SnapshotRequestModel)5 DataDeletionRequest (bio.terra.model.DataDeletionRequest)4 IngestRequestModel (bio.terra.model.IngestRequestModel)4 DataDeletionTableModel (bio.terra.model.DataDeletionTableModel)3 EnumerateSnapshotModel (bio.terra.model.EnumerateSnapshotModel)3 JobModel (bio.terra.model.JobModel)3 IamRole (bio.terra.service.iam.IamRole)3 TableResult (com.google.cloud.bigquery.TableResult)3 UUID (java.util.UUID)3 Before (org.junit.Before)3 PdaoConstant (bio.terra.common.PdaoConstant)2 AuthService (bio.terra.common.auth.AuthService)2