Search in sources :

Example 6 with SnapshotRequestContentsModel

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

the class SnapshotValidationTest method makeSnapshotByQueryRequest.

// Generate a valid snapshot-by-query request, we will tweak individual pieces to test validation below
public SnapshotRequestModel makeSnapshotByQueryRequest() {
    SnapshotRequestQueryModel querySpec = new SnapshotRequestQueryModel().assetName("asset").query("SELECT * FROM dataset");
    SnapshotRequestContentsModel snapshotRequestContentsModel = new SnapshotRequestContentsModel().datasetName("dataset").mode(SnapshotRequestContentsModel.ModeEnum.BYQUERY).querySpec(querySpec);
    return new SnapshotRequestModel().contents(Collections.singletonList(snapshotRequestContentsModel));
}
Also used : SnapshotRequestQueryModel(bio.terra.model.SnapshotRequestQueryModel) SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel)

Example 7 with SnapshotRequestContentsModel

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

the class SnapshotConnectedTest method makeSnapshotTestRequest.

private SnapshotRequestModel makeSnapshotTestRequest(DatasetSummaryModel datasetSummaryModel, String resourcePath) throws Exception {
    SnapshotRequestModel snapshotRequest = jsonLoader.loadObject(resourcePath, SnapshotRequestModel.class);
    SnapshotRequestContentsModel content = snapshotRequest.getContents().get(0);
    // TODO SingleDatasetSnapshot
    String newDatasetName = datasetSummaryModel.getName();
    String origDatasetName = content.getDatasetName();
    // swap in the correct dataset name (with the id at the end)
    content.setDatasetName(newDatasetName);
    snapshotRequest.profileId(datasetSummaryModel.getDefaultProfileId());
    if (content.getMode().equals(SnapshotRequestContentsModel.ModeEnum.BYQUERY)) {
        // if its by query, also set swap in the correct dataset name in the query
        String query = content.getQuerySpec().getQuery();
        content.getQuerySpec().setQuery(query.replace(origDatasetName, newDatasetName));
    }
    return snapshotRequest;
}
Also used : SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel)

Example 8 with SnapshotRequestContentsModel

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

the class SnapshotService method makeSnapshotFromSnapshotRequest.

/**
 * Make a Snapshot structure with all of its parts from an incoming snapshot request.
 * Note that the structure does not have UUIDs or created dates filled in. Those are
 * updated by the DAO when it stores the snapshot in the repository metadata.
 *
 * @param snapshotRequestModel
 * @return Snapshot
 */
public Snapshot makeSnapshotFromSnapshotRequest(SnapshotRequestModel snapshotRequestModel) {
    // Make this early so we can hook up back links to it
    Snapshot snapshot = new Snapshot();
    List<SnapshotRequestContentsModel> requestContentsList = snapshotRequestModel.getContents();
    // TODO: for MVM we only allow one source list
    if (requestContentsList.size() > 1) {
        throw new ValidationException("Only a single snapshot contents entry is currently allowed.");
    }
    SnapshotRequestContentsModel requestContents = requestContentsList.get(0);
    Dataset dataset = datasetService.retrieveByName(requestContents.getDatasetName());
    SnapshotSource snapshotSource = new SnapshotSource().snapshot(snapshot).dataset(dataset);
    switch(snapshotRequestModel.getContents().get(0).getMode()) {
        case BYASSET:
            // TODO: When we implement explicit definition of snapshot tables, we will handle that here.
            // For now, we generate the snapshot tables directly from the asset tables of the one source
            // allowed in a snapshot.
            AssetSpecification assetSpecification = getAssetSpecificationFromRequest(requestContents);
            snapshotSource.assetSpecification(assetSpecification);
            conjureSnapshotTablesFromAsset(snapshotSource.getAssetSpecification(), snapshot, snapshotSource);
            break;
        case BYFULLVIEW:
            conjureSnapshotTablesFromDatasetTables(snapshot, snapshotSource);
            break;
        case BYQUERY:
            SnapshotRequestQueryModel queryModel = requestContents.getQuerySpec();
            String assetName = queryModel.getAssetName();
            String snapshotQuery = queryModel.getQuery();
            Query query = Query.parse(snapshotQuery);
            List<String> datasetNames = query.getDatasetNames();
            // TODO this makes the assumption that there is only one dataset
            // (based on the validation flight step that already occurred.)
            // This will change when more than 1 dataset is allowed
            String datasetName = datasetNames.get(0);
            Dataset queryDataset = datasetService.retrieveByName(datasetName);
            AssetSpecification queryAssetSpecification = queryDataset.getAssetSpecificationByName(assetName).orElseThrow(() -> new AssetNotFoundException("This dataset does not have an asset specification with name: " + assetName));
            snapshotSource.assetSpecification(queryAssetSpecification);
            // TODO this is wrong? why dont we just pass the assetSpecification?
            conjureSnapshotTablesFromAsset(snapshotSource.getAssetSpecification(), snapshot, snapshotSource);
            break;
        case BYROWID:
            SnapshotRequestRowIdModel requestRowIdModel = requestContents.getRowIdSpec();
            conjureSnapshotTablesFromRowIds(requestRowIdModel, snapshot, snapshotSource);
            break;
        default:
            throw new InvalidSnapshotException("Snapshot does not have required mode information");
    }
    return snapshot.name(snapshotRequestModel.getName()).description(snapshotRequestModel.getDescription()).snapshotSources(Collections.singletonList(snapshotSource)).profileId(UUID.fromString(snapshotRequestModel.getProfileId())).relationships(createSnapshotRelationships(dataset.getRelationships(), snapshotSource));
}
Also used : ValidationException(bio.terra.app.controller.exception.ValidationException) Query(bio.terra.grammar.Query) SnapshotRequestQueryModel(bio.terra.model.SnapshotRequestQueryModel) Dataset(bio.terra.service.dataset.Dataset) SnapshotRequestRowIdModel(bio.terra.model.SnapshotRequestRowIdModel) SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) AssetSpecification(bio.terra.service.dataset.AssetSpecification) AssetNotFoundException(bio.terra.service.snapshot.exception.AssetNotFoundException) InvalidSnapshotException(bio.terra.service.snapshot.exception.InvalidSnapshotException)

Example 9 with SnapshotRequestContentsModel

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

the class SnapshotValidationTest method testSnapshotValuesListEmpty.

@Test
public void testSnapshotValuesListEmpty() throws Exception {
    SnapshotRequestAssetModel assetSpec = new SnapshotRequestAssetModel().assetName("asset").rootValues(Collections.emptyList());
    SnapshotRequestContentsModel snapshotRequestContentsModel = new SnapshotRequestContentsModel().datasetName("dataset").mode(SnapshotRequestContentsModel.ModeEnum.BYASSET).assetSpec(assetSpec);
    snapshotByAssetRequest.contents(Collections.singletonList(snapshotRequestContentsModel));
    expectBadSnapshotCreateRequest(snapshotByAssetRequest);
}
Also used : SnapshotRequestAssetModel(bio.terra.model.SnapshotRequestAssetModel) SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with SnapshotRequestContentsModel

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

the class SnapshotValidationTest method makeSnapshotAssetRequest.

// Generate a valid snapshot-by-asset request, we will tweak individual pieces to test validation below
public SnapshotRequestModel makeSnapshotAssetRequest() {
    SnapshotRequestAssetModel assetSpec = new SnapshotRequestAssetModel().assetName("asset").rootValues(Arrays.asList("sample 1", "sample 2", "sample 3"));
    SnapshotRequestContentsModel snapshotRequestContentsModel = new SnapshotRequestContentsModel().datasetName("dataset").mode(SnapshotRequestContentsModel.ModeEnum.BYASSET).assetSpec(assetSpec);
    return new SnapshotRequestModel().name("snapshot").description("snapshot description").addContentsItem(snapshotRequestContentsModel);
}
Also used : SnapshotRequestAssetModel(bio.terra.model.SnapshotRequestAssetModel) SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel)

Aggregations

SnapshotRequestContentsModel (bio.terra.model.SnapshotRequestContentsModel)10 SnapshotRequestModel (bio.terra.model.SnapshotRequestModel)4 SnapshotRequestAssetModel (bio.terra.model.SnapshotRequestAssetModel)3 SnapshotRequestRowIdModel (bio.terra.model.SnapshotRequestRowIdModel)3 Snapshot (bio.terra.service.snapshot.Snapshot)3 SnapshotRequestQueryModel (bio.terra.model.SnapshotRequestQueryModel)2 SnapshotRequestRowIdTableModel (bio.terra.model.SnapshotRequestRowIdTableModel)2 Dataset (bio.terra.service.dataset.Dataset)2 RowIdMatch (bio.terra.service.snapshot.RowIdMatch)2 SnapshotSource (bio.terra.service.snapshot.SnapshotSource)2 MismatchedValueException (bio.terra.service.snapshot.exception.MismatchedValueException)2 StepResult (bio.terra.stairway.StepResult)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ValidationException (bio.terra.app.controller.exception.ValidationException)1 Query (bio.terra.grammar.Query)1 AssetSpecification (bio.terra.service.dataset.AssetSpecification)1 AssetNotFoundException (bio.terra.service.snapshot.exception.AssetNotFoundException)1 InvalidSnapshotException (bio.terra.service.snapshot.exception.InvalidSnapshotException)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1