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