use of bio.terra.common.Relationship in project jade-data-repo by DataBiosphere.
the class DatasetJsonConversion method datasetRequestToDataset.
public static Dataset datasetRequestToDataset(DatasetRequestModel datasetRequest) {
Map<String, DatasetTable> tablesMap = new HashMap<>();
Map<String, Relationship> relationshipsMap = new HashMap<>();
List<AssetSpecification> assetSpecifications = new ArrayList<>();
UUID defaultProfileId = UUID.fromString(datasetRequest.getDefaultProfileId());
List<UUID> additionalProfileIds = stringsToUUIDs(datasetRequest.getAdditionalProfileIds());
DatasetSpecificationModel datasetSpecification = datasetRequest.getSchema();
datasetSpecification.getTables().forEach(tableModel -> tablesMap.put(tableModel.getName(), tableModelToTable(tableModel)));
// Relationships are optional, so there might not be any here
if (datasetSpecification.getRelationships() != null) {
datasetSpecification.getRelationships().forEach(relationship -> relationshipsMap.put(relationship.getName(), relationshipModelToDatasetRelationship(relationship, tablesMap)));
}
List<AssetModel> assets = datasetSpecification.getAssets();
if (assets != null) {
assets.forEach(asset -> assetSpecifications.add(assetModelToAssetSpecification(asset, tablesMap, relationshipsMap)));
}
return new Dataset(new DatasetSummary().name(datasetRequest.getName()).description(datasetRequest.getDescription()).defaultProfileId(defaultProfileId).additionalProfileIds(additionalProfileIds)).tables(new ArrayList<>(tablesMap.values())).relationships(new ArrayList<>(relationshipsMap.values())).assetSpecifications(assetSpecifications);
}
use of bio.terra.common.Relationship in project jade-data-repo by DataBiosphere.
the class DatasetRelationshipDao method retrieveDatasetRelationships.
private List<Relationship> retrieveDatasetRelationships(List<UUID> columnIds, Map<UUID, DatasetTable> tables, Map<UUID, Column> columns) {
String sql = "SELECT id, name, from_table, from_column, to_table, to_column " + "FROM dataset_relationship WHERE from_column IN (:columns) OR to_column IN (:columns)";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("columns", columnIds);
return jdbcTemplate.query(sql, params, (rs, rowNum) -> new Relationship().id(rs.getObject("id", UUID.class)).name(rs.getString("name")).fromTable(tables.get(rs.getObject("from_table", UUID.class))).fromColumn(columns.get(rs.getObject("from_column", UUID.class))).toTable(tables.get(rs.getObject("to_table", UUID.class))).toColumn(columns.get(rs.getObject("to_column", UUID.class))));
}
use of bio.terra.common.Relationship 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.common.Relationship in project jade-data-repo by DataBiosphere.
the class SnapshotRelationshipDao method retrieveSnapshotRelationships.
private List<Relationship> retrieveSnapshotRelationships(List<UUID> columnIds, Map<UUID, SnapshotTable> tables, Map<UUID, Column> columns) {
String sql = "SELECT id, name, from_table, from_column, to_table, to_column " + "FROM snapshot_relationship WHERE from_column IN (:columns) OR to_column IN (:columns)";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("columns", columnIds);
return jdbcTemplate.query(sql, params, (rs, rowNum) -> new Relationship().id(rs.getObject("id", UUID.class)).name(rs.getString("name")).fromTable(tables.get(rs.getObject("from_table", UUID.class))).fromColumn(columns.get(rs.getObject("from_column", UUID.class))).toTable(tables.get(rs.getObject("to_table", UUID.class))).toColumn(columns.get(rs.getObject("to_column", UUID.class))));
}
use of bio.terra.common.Relationship in project jade-data-repo by DataBiosphere.
the class SnapshotService method createSnapshotRelationships.
/**
* Map from a list of source relationships (from a dataset or asset) into snapshot relationships.
*
* @param sourceRelationships relationships from a dataset or asset
* @param snapshotSource source with mapping between dataset tables and columns -> snapshot tables and columns
* @return a list of relationships tied to the snapshot tables
*/
public List<Relationship> createSnapshotRelationships(List<Relationship> sourceRelationships, SnapshotSource snapshotSource) {
// We'll copy the asset relationships into the snapshot.
List<Relationship> snapshotRelationships = new ArrayList<>();
// Create lookups from dataset table and column ids -> snapshot tables and columns, respectively
Map<UUID, Table> tableLookup = new HashMap<>();
Map<UUID, Column> columnLookup = new HashMap<>();
for (SnapshotMapTable mapTable : snapshotSource.getSnapshotMapTables()) {
tableLookup.put(mapTable.getFromTable().getId(), mapTable.getToTable());
for (SnapshotMapColumn mapColumn : mapTable.getSnapshotMapColumns()) {
columnLookup.put(mapColumn.getFromColumn().getId(), mapColumn.getToColumn());
}
}
for (Relationship sourceRelationship : sourceRelationships) {
UUID fromTableId = sourceRelationship.getFromTable().getId();
UUID fromColumnId = sourceRelationship.getFromColumn().getId();
UUID toTableId = sourceRelationship.getToTable().getId();
UUID toColumnId = sourceRelationship.getToColumn().getId();
if (tableLookup.containsKey(fromTableId) && tableLookup.containsKey(toTableId) && columnLookup.containsKey(fromColumnId) && columnLookup.containsKey(toColumnId)) {
Table fromTable = tableLookup.get(fromTableId);
Column fromColumn = columnLookup.get(fromColumnId);
Table toTable = tableLookup.get(toTableId);
Column toColumn = columnLookup.get(toColumnId);
snapshotRelationships.add(new Relationship().name(sourceRelationship.getName()).fromTable(fromTable).fromColumn(fromColumn).toTable(toTable).toColumn(toColumn));
}
}
return snapshotRelationships;
}
Aggregations