use of bio.terra.common.Relationship in project jade-data-repo by DataBiosphere.
the class SnapshotDaoTest method happyInOutTest.
@Test
public void happyInOutTest() throws Exception {
snapshotRequest.name(snapshotRequest.getName() + UUID.randomUUID().toString());
String flightId = "happyInOutTest_flightId";
Snapshot snapshot = snapshotService.makeSnapshotFromSnapshotRequest(snapshotRequest);
snapshotId = snapshotDao.createAndLock(snapshot, flightId);
snapshotDao.unlock(snapshotId, flightId);
Snapshot fromDB = snapshotDao.retrieveSnapshot(snapshotId);
assertThat("snapshot name set correctly", fromDB.getName(), equalTo(snapshot.getName()));
assertThat("snapshot description set correctly", fromDB.getDescription(), equalTo(snapshot.getDescription()));
assertThat("correct number of tables created", fromDB.getTables().size(), equalTo(2));
assertThat("correct number of sources created", fromDB.getSnapshotSources().size(), equalTo(1));
// verify source and map
SnapshotSource source = fromDB.getSnapshotSources().get(0);
assertThat("source points back to snapshot", source.getSnapshot().getId(), equalTo(snapshot.getId()));
assertThat("source points to the asset spec", source.getAssetSpecification().getId(), equalTo(dataset.getAssetSpecifications().get(0).getId()));
assertThat("correct number of map tables", source.getSnapshotMapTables().size(), equalTo(2));
// Verify map table
SnapshotMapTable mapTable = source.getSnapshotMapTables().stream().filter(t -> t.getFromTable().getName().equals("thetable")).findFirst().orElseThrow(AssertionError::new);
Table datasetTable = dataset.getTables().stream().filter(t -> t.getName().equals("thetable")).findFirst().orElseThrow(AssertionError::new);
Table snapshotTable = snapshot.getTables().stream().filter(t -> t.getName().equals("thetable")).findFirst().orElseThrow(AssertionError::new);
assertThat("correct map table dataset table", mapTable.getFromTable().getId(), equalTo(datasetTable.getId()));
assertThat("correct map table snapshot table", mapTable.getToTable().getId(), equalTo(snapshotTable.getId()));
assertThat("correct number of map columns", mapTable.getSnapshotMapColumns().size(), equalTo(1));
// Verify map columns
SnapshotMapColumn mapColumn = mapTable.getSnapshotMapColumns().get(0);
// Why is dataset columns Collection and not List?
Column datasetColumn = datasetTable.getColumns().iterator().next();
Column snapshotColumn = snapshotTable.getColumns().get(0);
assertThat("correct map column dataset column", mapColumn.getFromColumn().getId(), equalTo(datasetColumn.getId()));
assertThat("correct map column snapshot column", mapColumn.getToColumn().getId(), equalTo(snapshotColumn.getId()));
List<Relationship> relationships = fromDB.getRelationships();
assertThat("a relationship comes back", relationships.size(), equalTo(1));
Relationship relationship = relationships.get(0);
Table fromTable = relationship.getFromTable();
Column fromColumn = relationship.getFromColumn();
Table toTable = relationship.getToTable();
Column toColumn = relationship.getToColumn();
assertThat("from table name matches", fromTable.getName(), equalTo("thetable"));
assertThat("from column name matches", fromColumn.getName(), equalTo("thecolumn"));
assertThat("to table name matches", toTable.getName(), equalTo("anothertable"));
assertThat("to column name matches", toColumn.getName(), equalTo("anothercolumn"));
assertThat("relationship points to the snapshot table", fromTable.getId(), equalTo(snapshotTable.getId()));
}
use of bio.terra.common.Relationship in project jade-data-repo by DataBiosphere.
the class DatasetJsonConversion method relationshipModelToDatasetRelationship.
public static Relationship relationshipModelToDatasetRelationship(RelationshipModel relationshipModel, Map<String, DatasetTable> tables) {
Table fromTable = tables.get(relationshipModel.getFrom().getTable());
Table toTable = tables.get(relationshipModel.getTo().getTable());
return new Relationship().name(relationshipModel.getName()).fromTable(fromTable).fromColumn(fromTable.getColumnsMap().get(relationshipModel.getFrom().getColumn())).toTable(toTable).toColumn(toTable.getColumnsMap().get(relationshipModel.getTo().getColumn()));
}
use of bio.terra.common.Relationship in project jade-data-repo by DataBiosphere.
the class AssetDao method retrieveAssetSpecifications.
// also retrieves dependent objects
public List<AssetSpecification> retrieveAssetSpecifications(Dataset dataset) {
Map<UUID, DatasetTable> allTables = dataset.getTablesById();
Map<UUID, Column> allColumns = dataset.getAllColumnsById();
Map<UUID, Relationship> allRelationships = dataset.getRelationshipsById();
String sql = "SELECT id, name, root_table_id, root_column_id FROM asset_specification WHERE dataset_id = " + ":datasetId";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("datasetId", dataset.getId());
return jdbcTemplate.query(sql, params, (rs, rowNum) -> {
UUID specId = rs.getObject("id", UUID.class);
AssetSpecification spec = new AssetSpecification().id(specId).name(rs.getString("name"));
spec.assetTables(new ArrayList(retrieveAssetTablesAndColumns(spec, rs.getObject("root_table_id", UUID.class), rs.getObject("root_column_id", UUID.class), allTables, allColumns)));
spec.assetRelationships(retrieveAssetRelationships(spec.getId(), allRelationships));
return spec;
});
}
Aggregations