Search in sources :

Example 1 with AssetSpecification

use of bio.terra.service.dataset.AssetSpecification in project jade-data-repo by DataBiosphere.

the class CreateDatasetAssetStep method getNewAssetSpec.

private AssetSpecification getNewAssetSpec(FlightContext context, Dataset dataset) {
    // get Asset Model and convert it to a spec
    AssetModel assetModel = context.getInputParameters().get(JobMapKeys.REQUEST.getKeyName(), AssetModel.class);
    List<DatasetTable> datasetTables = dataset.getTables();
    Map<String, Relationship> relationshipMap = new HashMap<>();
    Map<String, DatasetTable> tablesMap = new HashMap<>();
    datasetTables.forEach(datasetTable -> tablesMap.put(datasetTable.getName(), datasetTable));
    List<Relationship> datasetRelationships = dataset.getRelationships();
    datasetRelationships.forEach(relationship -> relationshipMap.put(relationship.getName(), relationship));
    AssetSpecification assetSpecification = DatasetJsonConversion.assetModelToAssetSpecification(assetModel, tablesMap, relationshipMap);
    return assetSpecification;
}
Also used : HashMap(java.util.HashMap) Relationship(bio.terra.common.Relationship) AssetModel(bio.terra.model.AssetModel) AssetSpecification(bio.terra.service.dataset.AssetSpecification) DatasetTable(bio.terra.service.dataset.DatasetTable)

Example 2 with AssetSpecification

use of bio.terra.service.dataset.AssetSpecification in project jade-data-repo by DataBiosphere.

the class CreateDatasetAssetStep method doStep.

@Override
public StepResult doStep(FlightContext context) {
    // TODO: Asset columns and tables need to match things in the dataset schema
    Dataset dataset = getDataset(context);
    FlightMap map = context.getWorkingMap();
    // get the dataset assets that already exist --asset name needs to be unique
    AssetSpecification newAssetSpecification = getNewAssetSpec(context, dataset);
    // add a fault that forces an exception to make sure the undo works
    try {
        configService.fault(ConfigEnum.CREATE_ASSET_FAULT, () -> {
            throw new RuntimeException("fault insertion");
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    try {
        assetDao.create(newAssetSpecification, dataset.getId());
    } catch (InvalidAssetException e) {
        FlightUtils.setErrorResponse(context, e.getMessage(), HttpStatus.BAD_REQUEST);
        map.put(DatasetWorkingMapKeys.ASSET_NAME_COLLISION, true);
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, e);
    }
    map.put(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.CREATED);
    return StepResult.getStepResultSuccess();
}
Also used : Dataset(bio.terra.service.dataset.Dataset) FlightMap(bio.terra.stairway.FlightMap) AssetSpecification(bio.terra.service.dataset.AssetSpecification) StepResult(bio.terra.stairway.StepResult) InvalidAssetException(bio.terra.service.dataset.exception.InvalidAssetException) InvalidAssetException(bio.terra.service.dataset.exception.InvalidAssetException)

Example 3 with AssetSpecification

use of bio.terra.service.dataset.AssetSpecification 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 4 with AssetSpecification

use of bio.terra.service.dataset.AssetSpecification in project jade-data-repo by DataBiosphere.

the class SnapshotService method makeSourceModelFromSource.

private SnapshotSourceModel makeSourceModelFromSource(SnapshotSource source) {
    // TODO: when source summary methods are available, use those. Here I roll my own
    Dataset dataset = source.getDataset();
    DatasetSummaryModel summaryModel = new DatasetSummaryModel().id(dataset.getId().toString()).name(dataset.getName()).description(dataset.getDescription()).defaultProfileId(dataset.getDefaultProfileId().toString()).createdDate(dataset.getCreatedDate().toString());
    SnapshotSourceModel sourceModel = new SnapshotSourceModel().dataset(summaryModel);
    AssetSpecification assetSpec = source.getAssetSpecification();
    if (assetSpec != null) {
        sourceModel.asset(assetSpec.getName());
    }
    return sourceModel;
}
Also used : Dataset(bio.terra.service.dataset.Dataset) SnapshotSourceModel(bio.terra.model.SnapshotSourceModel) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) AssetSpecification(bio.terra.service.dataset.AssetSpecification)

Example 5 with AssetSpecification

use of bio.terra.service.dataset.AssetSpecification in project jade-data-repo by DataBiosphere.

the class SnapshotDao method retrieveSnapshotSources.

private List<SnapshotSource> retrieveSnapshotSources(Snapshot snapshot) {
    // query might work, it makes debugging errors more difficult.
    class RawSourceData {

        private UUID id;

        private UUID datasetId;

        private UUID assetId;
    }
    String sql = "SELECT id, dataset_id, asset_id FROM snapshot_source WHERE snapshot_id = :snapshot_id";
    List<RawSourceData> rawList = jdbcTemplate.query(sql, new MapSqlParameterSource().addValue("snapshot_id", snapshot.getId()), (rs, rowNum) -> {
        RawSourceData raw = new RawSourceData();
        raw.id = UUID.fromString(rs.getString("id"));
        raw.datasetId = rs.getObject("dataset_id", UUID.class);
        raw.assetId = rs.getObject("asset_id", UUID.class);
        return raw;
    });
    List<SnapshotSource> snapshotSources = new ArrayList<>();
    for (RawSourceData raw : rawList) {
        Dataset dataset = datasetDao.retrieve(raw.datasetId);
        SnapshotSource snapshotSource = new SnapshotSource().id(raw.id).snapshot(snapshot).dataset(dataset);
        if (raw.assetId != null) {
            // if there is no assetId, then dont check for a spec
            // Find the matching asset in the dataset
            Optional<AssetSpecification> assetSpecification = dataset.getAssetSpecificationById(raw.assetId);
            if (!assetSpecification.isPresent()) {
                throw new CorruptMetadataException("Asset referenced by snapshot source was not found!");
            }
            snapshotSource.assetSpecification(assetSpecification.get());
        }
        // Now that we have access to all of the parts, build the map structure
        snapshotSource.snapshotMapTables(snapshotMapTableDao.retrieveMapTables(snapshot, snapshotSource));
        snapshotSources.add(snapshotSource);
    }
    return snapshotSources;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Dataset(bio.terra.service.dataset.Dataset) ArrayList(java.util.ArrayList) AssetSpecification(bio.terra.service.dataset.AssetSpecification) UUID(java.util.UUID) CorruptMetadataException(bio.terra.service.snapshot.exception.CorruptMetadataException)

Aggregations

AssetSpecification (bio.terra.service.dataset.AssetSpecification)10 Dataset (bio.terra.service.dataset.Dataset)7 AssetNotFoundException (bio.terra.service.snapshot.exception.AssetNotFoundException)3 Query (bio.terra.grammar.Query)2 SnapshotRequestQueryModel (bio.terra.model.SnapshotRequestQueryModel)2 DatasetTable (bio.terra.service.dataset.DatasetTable)2 FlightMap (bio.terra.stairway.FlightMap)2 FieldValue (com.google.cloud.bigquery.FieldValue)2 FieldValueList (com.google.cloud.bigquery.FieldValueList)2 TableResult (com.google.cloud.bigquery.TableResult)2 ST (org.stringtemplate.v4.ST)2 ValidationException (bio.terra.app.controller.exception.ValidationException)1 Column (bio.terra.common.Column)1 Relationship (bio.terra.common.Relationship)1 Table (bio.terra.common.Table)1 PdaoException (bio.terra.common.exception.PdaoException)1 InvalidQueryException (bio.terra.grammar.exception.InvalidQueryException)1 BigQueryVisitor (bio.terra.grammar.google.BigQueryVisitor)1 AssetModel (bio.terra.model.AssetModel)1 DatasetModel (bio.terra.model.DatasetModel)1