Search in sources :

Example 1 with TableModel

use of bio.terra.model.TableModel in project jade-data-repo by DataBiosphere.

the class DatasetRequestValidator method validateTable.

private void validateTable(TableModel table, Errors errors, SchemaValidationContext context) {
    String tableName = table.getName();
    List<ColumnModel> columns = table.getColumns();
    List<String> primaryKeyList = table.getPrimaryKey();
    if (tableName != null && columns != null) {
        List<String> columnNames = columns.stream().map(ColumnModel::getName).collect(toList());
        if (ValidationUtils.hasDuplicates(columnNames)) {
            errors.rejectValue("schema", "DuplicateColumnNames");
        }
        if (primaryKeyList != null) {
            if (!columnNames.containsAll(primaryKeyList)) {
                errors.rejectValue("schema", "MissingPrimaryKeyColumn");
            }
            for (ColumnModel column : columns) {
                if (primaryKeyList.contains(column.getName()) && column.isArrayOf()) {
                    errors.rejectValue("schema", "PrimaryKeyArrayColumn");
                }
            }
        }
        context.addTable(tableName, columns);
    }
    TableModel.PartitionModeEnum mode = table.getPartitionMode();
    DatePartitionOptionsModel dateOptions = table.getDatePartitionOptions();
    IntPartitionOptionsModel intOptions = table.getIntPartitionOptions();
    if (mode == TableModel.PartitionModeEnum.DATE) {
        if (dateOptions == null) {
            errors.rejectValue("schema", "MissingDatePartitionOptions", "datePartitionOptions must be specified when using 'date' partitionMode");
        } else {
            validateDatePartitionOptions(dateOptions, columns, errors);
        }
    } else if (dateOptions != null) {
        errors.rejectValue("schema", "InvalidDatePartitionOptions", "datePartitionOptions can only be specified when using 'date' partitionMode");
    }
    if (mode == TableModel.PartitionModeEnum.INT) {
        if (intOptions == null) {
            errors.rejectValue("schema", "MissingIntPartitionOptions", "intPartitionOptions must be specified when using 'int' partitionMode");
        } else {
            validateIntPartitionOptions(intOptions, columns, errors);
        }
    } else if (intOptions != null) {
        errors.rejectValue("schema", "InvalidIntPartitionOptions", "intPartitionOptions can only be specified when using 'int' partitionMode");
    }
}
Also used : IntPartitionOptionsModel(bio.terra.model.IntPartitionOptionsModel) DatePartitionOptionsModel(bio.terra.model.DatePartitionOptionsModel) ColumnModel(bio.terra.model.ColumnModel) TableModel(bio.terra.model.TableModel) AssetTableModel(bio.terra.model.AssetTableModel)

Example 2 with TableModel

use of bio.terra.model.TableModel in project jade-data-repo by DataBiosphere.

the class DatasetValidationsTest method testPartitionOptionsWithoutMode.

@Test
public void testPartitionOptionsWithoutMode() throws Exception {
    TableModel table = new TableModel().name("table").columns(Collections.emptyList()).datePartitionOptions(new DatePartitionOptionsModel().column("foo")).intPartitionOptions(new IntPartitionOptionsModel().column("bar").min(1L).max(2L).interval(1L));
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().tables(Collections.singletonList(table)).relationships(Collections.emptyList()).assets(Collections.emptyList());
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "InvalidDatePartitionOptions", "InvalidIntPartitionOptions" });
}
Also used : IntPartitionOptionsModel(bio.terra.model.IntPartitionOptionsModel) DatasetRequestModel(bio.terra.model.DatasetRequestModel) DatePartitionOptionsModel(bio.terra.model.DatePartitionOptionsModel) ErrorModel(bio.terra.model.ErrorModel) TableModel(bio.terra.model.TableModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with TableModel

use of bio.terra.model.TableModel in project jade-data-repo by DataBiosphere.

the class DatasetValidationsTest method testArrayPrimaryKeyColumn.

@Test
public void testArrayPrimaryKeyColumn() throws Exception {
    ColumnModel column = new ColumnModel().name("array_column").datatype("string").arrayOf(true);
    TableModel table = new TableModel().name("table").columns(Collections.singletonList(column)).primaryKey(Collections.singletonList(column.getName()));
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().tables(Collections.singletonList(table)).relationships(Collections.emptyList()).assets(Collections.emptyList());
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "PrimaryKeyArrayColumn" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) ColumnModel(bio.terra.model.ColumnModel) TableModel(bio.terra.model.TableModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with TableModel

use of bio.terra.model.TableModel in project jade-data-repo by DataBiosphere.

the class DatasetValidationsTest method testMissingPrimaryKeyColumn.

@Test
public void testMissingPrimaryKeyColumn() throws Exception {
    TableModel table = new TableModel().name("table").columns(Collections.emptyList()).primaryKey(Collections.singletonList("not_a_column"));
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().tables(Collections.singletonList(table)).relationships(Collections.emptyList()).assets(Collections.emptyList());
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "MissingPrimaryKeyColumn" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) TableModel(bio.terra.model.TableModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with TableModel

use of bio.terra.model.TableModel in project jade-data-repo by DataBiosphere.

the class DatasetValidationsTest method testDuplicateTableNames.

@Test
public void testDuplicateTableNames() throws Exception {
    ColumnModel column = new ColumnModel().name("id").datatype("string");
    TableModel table = new TableModel().name("duplicate").columns(Collections.singletonList(column));
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().tables(Arrays.asList(table, table));
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "DuplicateTableNames", "InvalidRelationshipTermTableColumn", "InvalidRelationshipTermTableColumn", "InvalidAssetTable", "InvalidAssetTableColumn", "InvalidAssetTableColumn", "InvalidRootColumn" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) ColumnModel(bio.terra.model.ColumnModel) TableModel(bio.terra.model.TableModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TableModel (bio.terra.model.TableModel)15 AssetTableModel (bio.terra.model.AssetTableModel)14 ErrorModel (bio.terra.model.ErrorModel)14 Test (org.junit.Test)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 DatasetRequestModel (bio.terra.model.DatasetRequestModel)13 ColumnModel (bio.terra.model.ColumnModel)8 IntPartitionOptionsModel (bio.terra.model.IntPartitionOptionsModel)7 DatePartitionOptionsModel (bio.terra.model.DatePartitionOptionsModel)5 ConnectedTestConfiguration (bio.terra.app.configuration.ConnectedTestConfiguration)1 PDAO_PREFIX (bio.terra.common.PdaoConstant.PDAO_PREFIX)1 TestUtils (bio.terra.common.TestUtils)1 Connected (bio.terra.common.category.Connected)1 ConnectedOperations (bio.terra.common.fixtures.ConnectedOperations)1 JsonLoader (bio.terra.common.fixtures.JsonLoader)1 Names (bio.terra.common.fixtures.Names)1 BillingProfileModel (bio.terra.model.BillingProfileModel)1 DRSObject (bio.terra.model.DRSObject)1 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)1 DeleteResponseModel (bio.terra.model.DeleteResponseModel)1