diff --git a/db-scheduler-ui-starter/pom.xml b/db-scheduler-ui-starter/pom.xml index bc1c855..be11285 100644 --- a/db-scheduler-ui-starter/pom.xml +++ b/db-scheduler-ui-starter/pom.xml @@ -21,6 +21,12 @@ test + + org.projectlombok + lombok + provided + + com.github.kagkarlsson db-scheduler-spring-boot-starter diff --git a/db-scheduler-ui-starter/src/main/java/no/bekk/dbscheduler/uistarter/autoconfigure/UiApiAutoConfiguration.java b/db-scheduler-ui-starter/src/main/java/no/bekk/dbscheduler/uistarter/autoconfigure/UiApiAutoConfiguration.java index 56a5580..075769a 100644 --- a/db-scheduler-ui-starter/src/main/java/no/bekk/dbscheduler/uistarter/autoconfigure/UiApiAutoConfiguration.java +++ b/db-scheduler-ui-starter/src/main/java/no/bekk/dbscheduler/uistarter/autoconfigure/UiApiAutoConfiguration.java @@ -21,32 +21,27 @@ import no.bekk.dbscheduler.ui.controller.LogController; import no.bekk.dbscheduler.ui.controller.TaskController; import no.bekk.dbscheduler.ui.controller.UIController; -import no.bekk.dbscheduler.ui.model.DbSchedulerUiConfig; import no.bekk.dbscheduler.ui.service.LogLogic; import no.bekk.dbscheduler.ui.service.TaskLogic; import no.bekk.dbscheduler.ui.util.Caching; +import no.bekk.dbscheduler.uistarter.config.DbSchedulerUiProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @AutoConfiguration @ConditionalOnProperty(value = "db-scheduler-ui.enabled", matchIfMissing = true) +@EnableConfigurationProperties(DbSchedulerUiProperties.class) public class UiApiAutoConfiguration { private static final Logger logger = LoggerFactory.getLogger(UiApiAutoConfiguration.class); - @Value("${db-scheduler-ui.task-data:true}") - boolean showTaskData; - - @Value("${db-scheduler-ui.history:false}") - boolean showHistory; - UiApiAutoConfiguration() { logger.info("UiApiAutoConfiguration created"); } @@ -59,8 +54,8 @@ Caching caching() { @Bean @ConditionalOnMissingBean - TaskLogic taskLogic(Scheduler scheduler, Caching caching) { - return new TaskLogic(scheduler, caching, showTaskData); + TaskLogic taskLogic(Scheduler scheduler, Caching caching, DbSchedulerUiProperties properties) { + return new TaskLogic(scheduler, caching, properties.isTaskData()); } @Bean @@ -70,12 +65,16 @@ TaskLogic taskLogic(Scheduler scheduler, Caching caching) { name = "history", havingValue = "true", matchIfMissing = false) - LogLogic logLogic(DataSource dataSource, Caching caching, DbSchedulerCustomizer customizer) { + LogLogic logLogic( + DataSource dataSource, + Caching caching, + DbSchedulerCustomizer customizer, + DbSchedulerUiProperties properties) { return new LogLogic( dataSource, customizer.serializer().orElse(Serializer.DEFAULT_JAVA_SERIALIZER), caching, - showTaskData); + properties.isTaskData()); } @Bean @@ -95,12 +94,6 @@ LogController logController(LogLogic logLogic) { return new LogController(logLogic); } - @Bean - @ConditionalOnMissingBean - DbSchedulerUiConfig dbSchedulerUiConfig() { - return new DbSchedulerUiConfig(showHistory); - } - @Bean @ConditionalOnMissingBean @ConditionalOnWebApplication(type = Type.SERVLET) @@ -110,7 +103,7 @@ UIController uiController() { @Bean @ConditionalOnMissingBean - ConfigController configController() { - return new ConfigController(); + ConfigController configController(DbSchedulerUiProperties properties) { + return new ConfigController(properties.isHistory()); } } diff --git a/db-scheduler-ui-starter/src/main/java/no/bekk/dbscheduler/uistarter/config/DbSchedulerUiProperties.java b/db-scheduler-ui-starter/src/main/java/no/bekk/dbscheduler/uistarter/config/DbSchedulerUiProperties.java new file mode 100644 index 0000000..51a7c5b --- /dev/null +++ b/db-scheduler-ui-starter/src/main/java/no/bekk/dbscheduler/uistarter/config/DbSchedulerUiProperties.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) Bekk + * + *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ +package no.bekk.dbscheduler.uistarter.config; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@Setter +@Getter +@ConfigurationProperties("db-scheduler-ui") +public class DbSchedulerUiProperties { + private boolean enabled = true; + private boolean taskData = true; + private boolean history = false; +} diff --git a/db-scheduler-ui/src/main/java/no/bekk/dbscheduler/ui/controller/ConfigController.java b/db-scheduler-ui/src/main/java/no/bekk/dbscheduler/ui/controller/ConfigController.java index f1a687a..eaf857e 100644 --- a/db-scheduler-ui/src/main/java/no/bekk/dbscheduler/ui/controller/ConfigController.java +++ b/db-scheduler-ui/src/main/java/no/bekk/dbscheduler/ui/controller/ConfigController.java @@ -13,8 +13,7 @@ */ package no.bekk.dbscheduler.ui.controller; -import no.bekk.dbscheduler.ui.model.DbSchedulerUiConfig; -import org.springframework.beans.factory.annotation.Autowired; +import no.bekk.dbscheduler.ui.model.ConfigResponse; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -25,10 +24,14 @@ @RequestMapping("/db-scheduler-api/config") public class ConfigController { - @Autowired private DbSchedulerUiConfig dbSchedulerUiConfig; + private final boolean showHistory; + + public ConfigController(boolean showHistory) { + this.showHistory = showHistory; + } @GetMapping - public DbSchedulerUiConfig getConfig() { - return dbSchedulerUiConfig; + public ConfigResponse getConfig() { + return new ConfigResponse(showHistory); } } diff --git a/db-scheduler-ui/src/main/java/no/bekk/dbscheduler/ui/model/DbSchedulerUiConfig.java b/db-scheduler-ui/src/main/java/no/bekk/dbscheduler/ui/model/ConfigResponse.java similarity index 92% rename from db-scheduler-ui/src/main/java/no/bekk/dbscheduler/ui/model/DbSchedulerUiConfig.java rename to db-scheduler-ui/src/main/java/no/bekk/dbscheduler/ui/model/ConfigResponse.java index b508ad6..395e124 100644 --- a/db-scheduler-ui/src/main/java/no/bekk/dbscheduler/ui/model/DbSchedulerUiConfig.java +++ b/db-scheduler-ui/src/main/java/no/bekk/dbscheduler/ui/model/ConfigResponse.java @@ -20,7 +20,6 @@ @Getter @Setter @AllArgsConstructor -public class DbSchedulerUiConfig { - - private boolean history; +public class ConfigResponse { + private boolean showHistory; }