diff --git a/backend/src/main/java/com/bakdata/conquery/models/config/DatabaseConfig.java b/backend/src/main/java/com/bakdata/conquery/models/config/DatabaseConfig.java index b42aa9bf0e..86a6aaa039 100644 --- a/backend/src/main/java/com/bakdata/conquery/models/config/DatabaseConfig.java +++ b/backend/src/main/java/com/bakdata/conquery/models/config/DatabaseConfig.java @@ -2,9 +2,11 @@ import lombok.Builder; import lombok.Data; +import lombok.extern.jackson.Jacksonized; @Data @Builder +@Jacksonized public class DatabaseConfig { private static final String DEFAULT_PRIMARY_COLUMN = "pid"; diff --git a/backend/src/main/java/com/bakdata/conquery/models/config/SqlConnectorConfig.java b/backend/src/main/java/com/bakdata/conquery/models/config/SqlConnectorConfig.java index 2a65aa5ca6..cfce88537b 100644 --- a/backend/src/main/java/com/bakdata/conquery/models/config/SqlConnectorConfig.java +++ b/backend/src/main/java/com/bakdata/conquery/models/config/SqlConnectorConfig.java @@ -3,15 +3,20 @@ import java.util.Map; import com.bakdata.conquery.models.datasets.Dataset; +import com.fasterxml.jackson.annotation.JsonIgnore; +import io.dropwizard.validation.ValidationMethod; +import jakarta.validation.Valid; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.extern.jackson.Jacksonized; @Data @Builder +@Jacksonized @NoArgsConstructor @AllArgsConstructor public class SqlConnectorConfig { @@ -27,10 +32,19 @@ public class SqlConnectorConfig { * Keys must match the name of existing {@link Dataset}s. */ @Getter(AccessLevel.PRIVATE) - private Map databaseConfigs; + private Map databaseConfigs; public DatabaseConfig getDatabaseConfig(Dataset dataset) { return databaseConfigs.get(dataset.getName()); } + @JsonIgnore + @ValidationMethod(message = "At lease 1 DatabaseConfig has to be present if SqlConnector config is enabled") + public boolean isValidSqlConnectorConfig() { + if (!enabled) { + return true; + } + return databaseConfigs != null && !databaseConfigs.isEmpty(); + } + } diff --git a/backend/src/main/java/com/bakdata/conquery/models/datasets/Table.java b/backend/src/main/java/com/bakdata/conquery/models/datasets/Table.java index 8439974550..26a5c19389 100644 --- a/backend/src/main/java/com/bakdata/conquery/models/datasets/Table.java +++ b/backend/src/main/java/com/bakdata/conquery/models/datasets/Table.java @@ -41,7 +41,7 @@ public class Table extends Labeled implements NamespacedIdentifiable findPrimaryColumn(Table table, DatabaseConfig sqlConfig) { - String primaryColumnName = table.getPrimaryColum() == null - ? sqlConfig.getPrimaryColumn() - : table.getPrimaryColum().getName(); + public static Field findPrimaryColumn(Table table, DatabaseConfig databaseConfig) { + String primaryColumnName = table.getPrimaryColumn() == null + ? databaseConfig.getPrimaryColumn() + : table.getPrimaryColumn().getName(); return DSL.field(DSL.name(table.getName(), primaryColumnName)); } diff --git a/backend/src/test/java/com/bakdata/conquery/integration/common/RequiredTable.java b/backend/src/test/java/com/bakdata/conquery/integration/common/RequiredTable.java index 55a3155cfd..3de4cf93bf 100644 --- a/backend/src/test/java/com/bakdata/conquery/integration/common/RequiredTable.java +++ b/backend/src/test/java/com/bakdata/conquery/integration/common/RequiredTable.java @@ -40,7 +40,7 @@ public class RequiredTable { public Table toTable(Dataset dataset, CentralRegistry centralRegistry) { Table table = new Table(); - table.setPrimaryColum(primaryColumn.toColumn(table, centralRegistry)); + table.setPrimaryColumn(primaryColumn.toColumn(table, centralRegistry)); table.setDataset(dataset); table.setName(name); table.setColumns(Arrays.stream(columns)