Search in sources :

Example 1 with SnapshotRequestAssetModel

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();
}
Also used : SnapshotRequestAssetModel(bio.terra.model.SnapshotRequestAssetModel) Dataset(bio.terra.service.dataset.Dataset) AssetSpecification(bio.terra.service.dataset.AssetSpecification) AssetNotFoundException(bio.terra.service.snapshot.exception.AssetNotFoundException)

Example 2 with SnapshotRequestAssetModel

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();
}
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 3 with SnapshotRequestAssetModel

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

Example 4 with SnapshotRequestAssetModel

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);
}
Also used : SnapshotRequestAssetModel(bio.terra.model.SnapshotRequestAssetModel) SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel)

Example 5 with SnapshotRequestAssetModel

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

Aggregations

SnapshotRequestAssetModel (bio.terra.model.SnapshotRequestAssetModel)5 SnapshotRequestContentsModel (bio.terra.model.SnapshotRequestContentsModel)3 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 SnapshotRequestModel (bio.terra.model.SnapshotRequestModel)1 AssetSpecification (bio.terra.service.dataset.AssetSpecification)1 Dataset (bio.terra.service.dataset.Dataset)1 RowIdMatch (bio.terra.service.snapshot.RowIdMatch)1 Snapshot (bio.terra.service.snapshot.Snapshot)1 SnapshotSource (bio.terra.service.snapshot.SnapshotSource)1 AssetNotFoundException (bio.terra.service.snapshot.exception.AssetNotFoundException)1 MismatchedValueException (bio.terra.service.snapshot.exception.MismatchedValueException)1 StepResult (bio.terra.stairway.StepResult)1