use of bio.terra.model.AssetTableModel in project jade-data-repo by DataBiosphere.
the class DatasetValidationsTest method testInvalidAssetTable.
@Test
public void testInvalidAssetTable() throws Exception {
AssetTableModel invalidAssetTable = new AssetTableModel().name("mismatched_table_name").columns(Collections.emptyList());
AssetModel asset = new AssetModel().name("bad_asset").rootTable("mismatched_table_name").tables(Collections.singletonList(invalidAssetTable)).follow(Collections.singletonList("participant_sample"));
DatasetRequestModel req = buildDatasetRequest();
req.getSchema().assets(Collections.singletonList(asset));
ErrorModel errorModel = expectBadDatasetCreateRequest(req);
checkValidationErrorModel(errorModel, new String[] { "NotNull", "InvalidAssetTable", "InvalidRootColumn" });
}
use of bio.terra.model.AssetTableModel in project jade-data-repo by DataBiosphere.
the class DatasetRequestValidator method validateAsset.
private void validateAsset(AssetModel asset, Errors errors, SchemaValidationContext context) {
List<AssetTableModel> assetTables = asset.getTables();
String rootTable = asset.getRootTable();
String rootColumn = asset.getRootColumn();
if (assetTables != null) {
boolean hasRootTable = false;
for (AssetTableModel assetTable : assetTables) {
validateAssetTable(assetTable, errors, context);
if (assetTable.getName().equals(rootTable)) {
if (!context.isValidTableColumn(rootTable, rootColumn)) {
errors.rejectValue("schema", "InvalidRootColumn", "Invalid root table column. Table: " + rootTable + " Column: " + rootColumn);
} else if (context.isArrayColumn(rootTable, rootColumn)) {
errors.rejectValue("schema", "InvalidArrayRootColumn", "Invalid use of array column as asset root. Table: " + rootTable + " Column: " + rootColumn);
}
hasRootTable = true;
}
}
if (!hasRootTable) {
errors.rejectValue("schema", "NoRootTable");
}
}
List<String> follows = asset.getFollow();
if (follows != null) {
if (follows.stream().anyMatch(relationshipName -> !context.isValidRelationship(relationshipName))) {
errors.rejectValue("schema", "InvalidFollowsRelationship");
}
}
// TODO: There is another validation that can be done here to make sure that the graph is connected that has
// been left out to avoid complexity before we know if we're going keep using this or not.
}
use of bio.terra.model.AssetTableModel in project jade-data-repo by DataBiosphere.
the class DatasetValidationsTest method testInvalidAssetTableColumn.
@Test
public void testInvalidAssetTableColumn() throws Exception {
// participant is a valid table but date_collected is in the sample table
AssetTableModel invalidAssetTable = new AssetTableModel().name("participant").columns(Collections.singletonList("date_collected"));
AssetModel asset = new AssetModel().name("mismatched").rootTable("participant").rootColumn("date_collected").tables(Collections.singletonList(invalidAssetTable)).follow(Collections.singletonList("participant_sample"));
DatasetRequestModel req = buildDatasetRequest();
req.getSchema().assets(Collections.singletonList(asset));
ErrorModel errorModel = expectBadDatasetCreateRequest(req);
checkValidationErrorModel(errorModel, new String[] { "InvalidAssetTableColumn", "InvalidRootColumn" });
}
use of bio.terra.model.AssetTableModel in project jade-data-repo by DataBiosphere.
the class DatasetValidationsTest method testArrayAssetRootColumn.
@Test
public void testArrayAssetRootColumn() throws Exception {
ColumnModel arrayColumn = new ColumnModel().name("array_data").arrayOf(true).datatype("string");
DatasetRequestModel req = buildDatasetRequest();
req.getSchema().getTables().stream().filter(table -> table.getName().equals("sample")).findFirst().ifPresent(sampleTable -> {
ArrayList<ColumnModel> columns = new ArrayList<>(sampleTable.getColumns());
columns.add(arrayColumn);
sampleTable.setColumns(columns);
});
AssetTableModel assetTable = new AssetTableModel().name("sample").columns(Collections.emptyList());
AssetModel asset = new AssetModel().name("bad_root").rootTable("sample").rootColumn(arrayColumn.getName()).tables(Collections.singletonList(assetTable)).follow(Collections.singletonList("participant_sample"));
req.getSchema().setAssets(Collections.singletonList(asset));
ErrorModel errorModel = expectBadDatasetCreateRequest(req);
checkValidationErrorModel(errorModel, new String[] { "InvalidArrayRootColumn" });
}
use of bio.terra.model.AssetTableModel in project jade-data-repo by DataBiosphere.
the class AssetModelValidator method validateTables.
private void validateTables(List<AssetTableModel> assetTables, Errors errors) {
if (assetTables != null) {
for (AssetTableModel assetTable : assetTables) {
String tableName = assetTable.getName();
List<String> columns = assetTable.getColumns();
if (tableName != null && columns != null) {
if (ValidationUtils.hasDuplicates(columns)) {
errors.rejectValue("columns", "DuplicateColumnNames");
}
}
}
// errors.rejectValue("rootTable", "NoRootTable"); // breaking here!
}
}
Aggregations