Search in sources :

Example 21 with Dataset

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

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

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

the class SnapshotService method undoCreateSnapshot.

public void undoCreateSnapshot(String snapshotName) throws InterruptedException {
    // Remove any file dependencies created
    Snapshot snapshot = snapshotDao.retrieveSnapshotByName(snapshotName);
    for (SnapshotSource snapshotSource : snapshot.getSnapshotSources()) {
        Dataset dataset = datasetService.retrieve(snapshotSource.getDataset().getId());
        dependencyDao.deleteSnapshotFileDependencies(dataset, snapshot.getId().toString());
    }
    bigQueryPdao.deleteSnapshot(snapshot);
}
Also used : Dataset(bio.terra.service.dataset.Dataset)

Example 24 with Dataset

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

the class CreateSnapshotFireStoreDataStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
    // We need a complete snapshot; use the snapshotService to get one.
    Snapshot snapshot = snapshotService.retrieveByName(snapshotReq.getName());
    // bounds the intermediate size in a way.
    for (SnapshotSource snapshotSource : snapshot.getSnapshotSources()) {
        for (SnapshotMapTable mapTable : snapshotSource.getSnapshotMapTables()) {
            for (SnapshotMapColumn mapColumn : mapTable.getSnapshotMapColumns()) {
                String fromDatatype = mapColumn.getFromColumn().getType();
                if (StringUtils.equalsIgnoreCase(fromDatatype, "FILEREF") || StringUtils.equalsIgnoreCase(fromDatatype, "DIRREF")) {
                    List<String> refIds = bigQueryPdao.getSnapshotRefIds(snapshotSource.getDataset(), snapshot.getName(), mapTable.getFromTable().getName(), mapTable.getFromTable().getId().toString(), mapColumn.getFromColumn());
                    Dataset dataset = datasetService.retrieve(snapshotSource.getDataset().getId());
                    fileDao.addFilesToSnapshot(dataset, snapshot, refIds);
                    dependencyDao.storeSnapshotFileDependencies(dataset, snapshot.getId().toString(), refIds);
                }
            }
        }
    }
    return StepResult.getStepResultSuccess();
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) SnapshotMapTable(bio.terra.service.snapshot.SnapshotMapTable) SnapshotMapColumn(bio.terra.service.snapshot.SnapshotMapColumn) Dataset(bio.terra.service.dataset.Dataset) SnapshotSource(bio.terra.service.snapshot.SnapshotSource)

Example 25 with Dataset

use of bio.terra.service.dataset.Dataset 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

Dataset (bio.terra.service.dataset.Dataset)49 AssetSpecification (bio.terra.service.dataset.AssetSpecification)9 Snapshot (bio.terra.service.snapshot.Snapshot)9 FlightMap (bio.terra.stairway.FlightMap)9 UUID (java.util.UUID)9 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)8 DatasetTable (bio.terra.service.dataset.DatasetTable)8 Test (org.junit.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 IngestRequestModel (bio.terra.model.IngestRequestModel)7 SnapshotSource (bio.terra.service.snapshot.SnapshotSource)7 StepResult (bio.terra.stairway.StepResult)5 ArrayList (java.util.ArrayList)5 Column (bio.terra.common.Column)4 Table (bio.terra.common.Table)4 DataDeletionTableModel (bio.terra.model.DataDeletionTableModel)4 SnapshotRequestContentsModel (bio.terra.model.SnapshotRequestContentsModel)4 ValidationException (bio.terra.app.controller.exception.ValidationException)3 PdaoLoadStatistics (bio.terra.common.PdaoLoadStatistics)3 PdaoException (bio.terra.common.exception.PdaoException)3