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