use of bio.terra.model.AssetModel in project jade-data-repo by DataBiosphere.
the class CreateDatasetAssetStep method getNewAssetSpec.
private AssetSpecification getNewAssetSpec(FlightContext context, Dataset dataset) {
// get Asset Model and convert it to a spec
AssetModel assetModel = context.getInputParameters().get(JobMapKeys.REQUEST.getKeyName(), AssetModel.class);
List<DatasetTable> datasetTables = dataset.getTables();
Map<String, Relationship> relationshipMap = new HashMap<>();
Map<String, DatasetTable> tablesMap = new HashMap<>();
datasetTables.forEach(datasetTable -> tablesMap.put(datasetTable.getName(), datasetTable));
List<Relationship> datasetRelationships = dataset.getRelationships();
datasetRelationships.forEach(relationship -> relationshipMap.put(relationship.getName(), relationship));
AssetSpecification assetSpecification = DatasetJsonConversion.assetModelToAssetSpecification(assetModel, tablesMap, relationshipMap);
return assetSpecification;
}
use of bio.terra.model.AssetModel in project jade-data-repo by DataBiosphere.
the class DatasetValidationsTest method testInvalidAssetTable.
@Test
public void testInvalidAssetTable() throws Exception {
AssetTableModel invalidAssetTable = new AssetTableModel().name("mismatched_table_name").columns(Collections.emptyList());
AssetModel asset = new AssetModel().name("bad_asset").rootTable("mismatched_table_name").tables(Collections.singletonList(invalidAssetTable)).follow(Collections.singletonList("participant_sample"));
DatasetRequestModel req = buildDatasetRequest();
req.getSchema().assets(Collections.singletonList(asset));
ErrorModel errorModel = expectBadDatasetCreateRequest(req);
checkValidationErrorModel(errorModel, new String[] { "NotNull", "InvalidAssetTable", "InvalidRootColumn" });
}
use of bio.terra.model.AssetModel in project jade-data-repo by DataBiosphere.
the class DatasetValidationsTest method testNoRootTable.
@Test
public void testNoRootTable() throws Exception {
AssetModel noRoot = new AssetModel().name("bad").tables(Collections.singletonList(buildAssetParticipantTable())).follow(Collections.singletonList("participant_sample"));
DatasetRequestModel req = buildDatasetRequest();
req.getSchema().assets(Collections.singletonList(noRoot));
ErrorModel errorModel = expectBadDatasetCreateRequest(req);
checkValidationErrorModel(errorModel, new String[] { "NotNull", "NotNull", "NoRootTable" });
}
use of bio.terra.model.AssetModel in project jade-data-repo by DataBiosphere.
the class DatasetIntegrationTest method testAssetCreationUndo.
@Test
public void testAssetCreationUndo() throws Exception {
// create a dataset
DatasetSummaryModel summaryModel = dataRepoFixtures.createDataset(steward(), "it-dataset-omop.json");
datasetId = summaryModel.getId();
DatasetModel datasetModel = dataRepoFixtures.getDataset(steward(), summaryModel.getId());
List<AssetModel> originalAssetList = datasetModel.getSchema().getAssets();
assertThat("Asset specification is as originally expected", originalAssetList.size(), equalTo(1));
AssetModel assetModel = new AssetModel().name("assetName").rootTable("person").rootColumn("person_id").tables(Arrays.asList(DatasetFixtures.buildAssetParticipantTable(), DatasetFixtures.buildAssetSampleTable())).follow(Collections.singletonList("fpk_visit_person"));
// have the asset creation fail
// by calling the fault insertion
dataRepoFixtures.setFault(steward(), ConfigEnum.CREATE_ASSET_FAULT.name(), true);
// add an asset spec
dataRepoFixtures.addDatasetAsset(steward(), datasetModel.getId(), assetModel);
// make sure undo is completed successfully
DatasetModel datasetModelWAsset = dataRepoFixtures.getDataset(steward(), datasetModel.getId());
DatasetSpecificationModel datasetSpecificationModel = datasetModelWAsset.getSchema();
List<AssetModel> assetList = datasetSpecificationModel.getAssets();
// assert that the asset isn't there
assertThat("Additional asset specification has never been added", assetList.size(), equalTo(1));
}
use of bio.terra.model.AssetModel in project jade-data-repo by DataBiosphere.
the class DatasetServiceTest method addDatasetBadAssetSpecification.
@Test
public void addDatasetBadAssetSpecification() throws Exception {
UUID datasetId = createDataset("dataset-create-test.json");
// This asset name already exists
String assetName = "sample";
// get created dataset
Dataset createdDataset = datasetDao.retrieve(datasetId);
assertThat("dataset already has two asset specs", createdDataset.getAssetSpecifications().size(), equalTo(2));
AssetModel assetModel = new AssetModel().name(assetName).rootTable("sample").rootColumn("participant_id").tables(Arrays.asList(DatasetFixtures.buildAssetParticipantTable(), DatasetFixtures.buildAssetSampleTable())).follow(Collections.singletonList("participant_sample"));
// add asset to dataset
String jobId = datasetService.addDatasetAssetSpecifications(datasetId.toString(), assetModel, testUser);
flightIdsList.add(jobId);
TestUtils.eventualExpect(5, 60, true, () -> jobService.retrieveJob(jobId, testUser).getJobStatus().equals(JobModel.JobStatusEnum.FAILED));
try {
try {
jobService.retrieveJobResult(jobId, ErrorModel.class, testUser);
fail("Expected invalid asset exception");
} catch (InvalidAssetException ex) {
assertThat("error message is correct", ex.getMessage(), equalTo("Asset name already exists: sample"));
// get dataset
Dataset dataset = datasetDao.retrieve(datasetId);
// make sure the dataset has the expected asset
assertThat("dataset has no additional asset spec", dataset.getAssetSpecifications().size(), equalTo(2));
}
} finally {
datasetDao.delete(datasetId);
}
}
Aggregations