Search in sources :

Example 1 with AssetTableModel

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" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) AssetModel(bio.terra.model.AssetModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with AssetTableModel

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.
}
Also used : AssetTableModel(bio.terra.model.AssetTableModel)

Example 3 with AssetTableModel

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" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) AssetModel(bio.terra.model.AssetModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with AssetTableModel

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" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ArrayList(java.util.ArrayList) ErrorModel(bio.terra.model.ErrorModel) AssetModel(bio.terra.model.AssetModel) ColumnModel(bio.terra.model.ColumnModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with AssetTableModel

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!
    }
}
Also used : AssetTableModel(bio.terra.model.AssetTableModel)

Aggregations

AssetTableModel (bio.terra.model.AssetTableModel)5 AssetModel (bio.terra.model.AssetModel)3 DatasetRequestModel (bio.terra.model.DatasetRequestModel)3 ErrorModel (bio.terra.model.ErrorModel)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ColumnModel (bio.terra.model.ColumnModel)1 ArrayList (java.util.ArrayList)1