use of bio.terra.model.SnapshotRequestAssetModel in project jade-data-repo by DataBiosphere.
the class SnapshotService method getAssetSpecificationFromRequest.
private AssetSpecification getAssetSpecificationFromRequest(SnapshotRequestContentsModel requestContents) {
SnapshotRequestAssetModel requestAssetModel = requestContents.getAssetSpec();
Dataset dataset = datasetService.retrieveByName(requestContents.getDatasetName());
Optional<AssetSpecification> optAsset = dataset.getAssetSpecificationByName(requestAssetModel.getAssetName());
if (!optAsset.isPresent()) {
throw new AssetNotFoundException("Asset specification not found: " + requestAssetModel.getAssetName());
}
// the map construction will go here. For MVM, we generate the mapping data directly from the asset spec.
return optAsset.get();
}
use of bio.terra.model.SnapshotRequestAssetModel 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.SnapshotRequestAssetModel 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);
}
use of bio.terra.model.SnapshotRequestAssetModel 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);
}
use of bio.terra.model.SnapshotRequestAssetModel in project jade-data-repo by DataBiosphere.
the class SnapshotValidationTest method testSnapshotAssetNameInvalid.
@Test
public void testSnapshotAssetNameInvalid() throws Exception {
SnapshotRequestAssetModel assetSpec = snapshotByAssetRequest.getContents().get(0).getAssetSpec();
assetSpec.setAssetName("no spaces");
expectBadSnapshotCreateRequest(snapshotByAssetRequest);
assetSpec.setAssetName("no-dashes");
expectBadSnapshotCreateRequest(snapshotByAssetRequest);
assetSpec.setAssetName("");
expectBadSnapshotCreateRequest(snapshotByAssetRequest);
// Make a 64 character string, it should be considered too long by the validation.
String tooLong = StringUtils.repeat("a", 64);
assetSpec.setAssetName(tooLong);
expectBadSnapshotCreateRequest(snapshotByAssetRequest);
}
Aggregations