use of bio.terra.model.ColumnModel 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");
}
}
use of bio.terra.model.ColumnModel 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" });
}
use of bio.terra.model.ColumnModel 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" });
}
use of bio.terra.model.ColumnModel in project jade-data-repo by DataBiosphere.
the class DatasetValidationsTest method testDatePartitionWithMismatchedType.
@Test
public void testDatePartitionWithMismatchedType() throws Exception {
ColumnModel column = new ColumnModel().name("column").datatype("int64");
TableModel table = new TableModel().name("table").columns(Collections.singletonList(column)).partitionMode(TableModel.PartitionModeEnum.DATE).datePartitionOptions(new DatePartitionOptionsModel().column(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[] { "InvalidDatePartitionColumnType" });
}
use of bio.terra.model.ColumnModel in project jade-data-repo by DataBiosphere.
the class DatasetValidationsTest method testDuplicateColumnNames.
@Test
public void testDuplicateColumnNames() throws Exception {
ColumnModel column = new ColumnModel().name("id").datatype("string");
TableModel table = new TableModel().name("table").columns(Arrays.asList(column, column));
DatasetRequestModel req = buildDatasetRequest();
req.getSchema().tables(Collections.singletonList(table));
ErrorModel errorModel = expectBadDatasetCreateRequest(req);
checkValidationErrorModel(errorModel, new String[] { "DuplicateColumnNames", "InvalidRelationshipTermTableColumn", "InvalidRelationshipTermTableColumn", "InvalidAssetTable", "InvalidAssetTableColumn", "InvalidAssetTableColumn", "InvalidRootColumn" });
}
Aggregations