Search in sources :

Example 1 with Relationship

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Relationship(bio.terra.common.Relationship) UUID(java.util.UUID)

Example 2 with Relationship

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))));
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Relationship(bio.terra.common.Relationship) UUID(java.util.UUID)

Example 3 with Relationship

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;
}
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 4 with Relationship

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))));
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Relationship(bio.terra.common.Relationship) UUID(java.util.UUID)

Example 5 with Relationship

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;
}
Also used : DatasetTable(bio.terra.service.dataset.DatasetTable) Table(bio.terra.common.Table) AssetTable(bio.terra.service.dataset.AssetTable) HashMap(java.util.HashMap) AssetColumn(bio.terra.service.dataset.AssetColumn) Column(bio.terra.common.Column) Relationship(bio.terra.common.Relationship) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Aggregations

Relationship (bio.terra.common.Relationship)8 UUID (java.util.UUID)5 Column (bio.terra.common.Column)3 Table (bio.terra.common.Table)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)3 DatasetTable (bio.terra.service.dataset.DatasetTable)2 AssetModel (bio.terra.model.AssetModel)1 AssetColumn (bio.terra.service.dataset.AssetColumn)1 AssetSpecification (bio.terra.service.dataset.AssetSpecification)1 AssetTable (bio.terra.service.dataset.AssetTable)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1