Search in sources :

Example 1 with AssetModel

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;
}
Also used : HashMap(java.util.HashMap) Relationship(bio.terra.common.Relationship) AssetModel(bio.terra.model.AssetModel) AssetSpecification(bio.terra.service.dataset.AssetSpecification) DatasetTable(bio.terra.service.dataset.DatasetTable)

Example 2 with AssetModel

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" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) AssetModel(bio.terra.model.AssetModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with AssetModel

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" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) AssetModel(bio.terra.model.AssetModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with AssetModel

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));
}
Also used : DatasetSpecificationModel(bio.terra.model.DatasetSpecificationModel) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) AssetModel(bio.terra.model.AssetModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) DatasetModel(bio.terra.model.DatasetModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with AssetModel

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);
    }
}
Also used : AssetModel(bio.terra.model.AssetModel) UUID(java.util.UUID) InvalidAssetException(bio.terra.service.dataset.exception.InvalidAssetException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

AssetModel (bio.terra.model.AssetModel)12 Test (org.junit.Test)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 DatasetRequestModel (bio.terra.model.DatasetRequestModel)5 ErrorModel (bio.terra.model.ErrorModel)5 UUID (java.util.UUID)4 AssetTableModel (bio.terra.model.AssetTableModel)3 Relationship (bio.terra.common.Relationship)1 ColumnModel (bio.terra.model.ColumnModel)1 DatasetModel (bio.terra.model.DatasetModel)1 DatasetSpecificationModel (bio.terra.model.DatasetSpecificationModel)1 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)1 EnumerateDatasetModel (bio.terra.model.EnumerateDatasetModel)1 AssetSpecification (bio.terra.service.dataset.AssetSpecification)1 DatasetTable (bio.terra.service.dataset.DatasetTable)1 InvalidAssetException (bio.terra.service.dataset.exception.InvalidAssetException)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1