Search in sources :

Example 1 with SnapshotRequestContentsModel

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

the class CreateSnapshotPrimaryDataFullViewStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    /*
         * from the dataset tables, we will need to get the table's live views
         */
    SnapshotRequestContentsModel contentsModel = snapshotReq.getContents().get(0);
    Snapshot snapshot = snapshotDao.retrieveSnapshotByName(snapshotReq.getName());
    Dataset dataset = datasetservice.retrieveByName(contentsModel.getDatasetName());
    bigQueryPdao.createSnapshotWithLiveViews(snapshot, dataset);
    return StepResult.getStepResultSuccess();
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) Dataset(bio.terra.service.dataset.Dataset) SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel)

Example 2 with SnapshotRequestContentsModel

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

the class CreateSnapshotPrimaryDataRowIdsStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    // TODO: this assumes single-dataset snapshots, will need to add a loop for multiple
    SnapshotRequestContentsModel contentsModel = snapshotReq.getContents().get(0);
    Snapshot snapshot = snapshotDao.retrieveSnapshotByName(snapshotReq.getName());
    SnapshotSource source = snapshot.getSnapshotSources().get(0);
    SnapshotRequestRowIdModel rowIdModel = contentsModel.getRowIdSpec();
    // for each table, make sure all of the row ids match
    for (SnapshotRequestRowIdTableModel table : rowIdModel.getTables()) {
        List<String> rowIds = table.getRowIds();
        if (!rowIds.isEmpty()) {
            RowIdMatch rowIdMatch = bigQueryPdao.matchRowIds(snapshot, source, table.getTableName(), rowIds);
            if (!rowIdMatch.getUnmatchedInputValues().isEmpty()) {
                String unmatchedValues = String.join("', '", rowIdMatch.getUnmatchedInputValues());
                String message = String.format("Mismatched row ids: '%s'", unmatchedValues);
                FlightUtils.setErrorResponse(context, message, HttpStatus.BAD_REQUEST);
                return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, new MismatchedValueException(message));
            }
        }
    }
    bigQueryPdao.createSnapshotWithProvidedIds(snapshot, contentsModel);
    return StepResult.getStepResultSuccess();
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) SnapshotRequestRowIdTableModel(bio.terra.model.SnapshotRequestRowIdTableModel) RowIdMatch(bio.terra.service.snapshot.RowIdMatch) SnapshotSource(bio.terra.service.snapshot.SnapshotSource) SnapshotRequestRowIdModel(bio.terra.model.SnapshotRequestRowIdModel) SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) MismatchedValueException(bio.terra.service.snapshot.exception.MismatchedValueException) StepResult(bio.terra.stairway.StepResult)

Example 3 with SnapshotRequestContentsModel

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

the class CreateSnapshotPrimaryDataAssetStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    /*
         * map field ids into row ids and validate
         * then pass the row id array into create snapshot
         */
    SnapshotRequestContentsModel contentsModel = snapshotReq.getContents().get(0);
    SnapshotRequestAssetModel assetSpec = contentsModel.getAssetSpec();
    Snapshot snapshot = snapshotDao.retrieveSnapshotByName(snapshotReq.getName());
    SnapshotSource source = snapshot.getSnapshotSources().get(0);
    RowIdMatch rowIdMatch = bigQueryPdao.mapValuesToRows(snapshot, source, assetSpec.getRootValues());
    if (rowIdMatch.getUnmatchedInputValues().size() != 0) {
        String unmatchedValues = String.join("', '", rowIdMatch.getUnmatchedInputValues());
        String message = String.format("Mismatched input values: '%s'", unmatchedValues);
        FlightUtils.setErrorResponse(context, message, HttpStatus.BAD_REQUEST);
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, new MismatchedValueException(message));
    }
    bigQueryPdao.createSnapshot(snapshot, rowIdMatch.getMatchingRowIds());
    return StepResult.getStepResultSuccess();
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) RowIdMatch(bio.terra.service.snapshot.RowIdMatch) SnapshotRequestAssetModel(bio.terra.model.SnapshotRequestAssetModel) SnapshotSource(bio.terra.service.snapshot.SnapshotSource) SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) MismatchedValueException(bio.terra.service.snapshot.exception.MismatchedValueException) StepResult(bio.terra.stairway.StepResult)

Example 4 with SnapshotRequestContentsModel

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

the class SnapshotValidationTest method testSnapshotDatasetNameInvalid.

@Test
public void testSnapshotDatasetNameInvalid() throws Exception {
    // snapshotByAssetRequest is assumed to be valid, we will just mess with the dataset name in the contents
    SnapshotRequestContentsModel contents = snapshotByAssetRequest.getContents().get(0);
    contents.setDatasetName("no spaces");
    expectBadSnapshotCreateRequest(snapshotByAssetRequest);
    contents.setDatasetName("no-dashes");
    expectBadSnapshotCreateRequest(snapshotByAssetRequest);
    contents.setDatasetName("");
    expectBadSnapshotCreateRequest(snapshotByAssetRequest);
    // Make a 64 character string, it should be considered too long by the validation.
    String tooLong = StringUtils.repeat("a", 64);
    contents.setDatasetName(tooLong);
    expectBadSnapshotCreateRequest(snapshotByAssetRequest);
}
Also used : SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with SnapshotRequestContentsModel

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

the class SnapshotValidationTest method makeSnapshotRowIdsRequest.

// Generate a valid snapshot-by-rowId request, we will tweak individual pieces to test validation below
public SnapshotRequestModel makeSnapshotRowIdsRequest() {
    SnapshotRequestRowIdTableModel snapshotRequestTableModel = new SnapshotRequestRowIdTableModel().tableName("snapshot").columns(Arrays.asList("col1", "col2", "col3")).rowIds(Arrays.asList("row1", "row2", "row3"));
    SnapshotRequestRowIdModel rowIdSpec = new SnapshotRequestRowIdModel().tables(Collections.singletonList(snapshotRequestTableModel));
    SnapshotRequestContentsModel snapshotRequestContentsModel = new SnapshotRequestContentsModel().datasetName("dataset").mode(SnapshotRequestContentsModel.ModeEnum.BYROWID).rowIdSpec(rowIdSpec);
    return new SnapshotRequestModel().contents(Collections.singletonList(snapshotRequestContentsModel));
}
Also used : SnapshotRequestRowIdTableModel(bio.terra.model.SnapshotRequestRowIdTableModel) SnapshotRequestRowIdModel(bio.terra.model.SnapshotRequestRowIdModel) 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