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());
}
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());
}
Aggregations