From 2ad8ffd779bd641cf8b290a810744b9f2aff4899 Mon Sep 17 00:00:00 2001 From: Lars Johansson <lars.johansson@ess.eu> Date: Wed, 17 Apr 2024 14:11:51 +0200 Subject: [PATCH] Refactor configuration Add Swagger url configuration. Remove unused configuration. --- CONFIGURATION.md | 2 +- .../names/service/NotificationService.java | 12 ++++++------ src/main/resources/application.properties | 19 +++++++------------ src/test/resources/application.properties | 19 +++++++------------ 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 47c45f5b..796e7992 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -6,7 +6,6 @@ Configuration may be set using SpringBoot's configuration file (`application.pro | Variable | Default | Description | |----------------------------|---------------------------------------------|------------------------------------------------------------------------------------------------------------------------| -| NAMING_BACKEND_SWAGGER_URL | http://localhost:8080/swagger-ui.html | default url for Swagger UI | | NAMING_DATABASE_URL | jdbc:postgresql://postgres:5432/discs_names | JDBC URL for the database connection | | NAMING_DATABASE_USERNAME | discs_names | user name for the database connection | | NAMING_DATABASE_PASSWORD | discs_names | password for the database connection | @@ -18,3 +17,4 @@ Configuration may be set using SpringBoot's configuration file (`application.pro | NAMING_SMTP_PORT | 587 | port to use for SMTP, 587 for SMTP Secure | | NAMING_SMTP_USERNAME | | username for SMTP server | | NAMING_SMTP_PASSWORD | | password for SMTP server | +| NAMING_SWAGGER_URL | http://localhost:8080/swagger-ui.html | default url for Swagger UI | diff --git a/src/main/java/org/openepics/names/service/NotificationService.java b/src/main/java/org/openepics/names/service/NotificationService.java index 74d906d2..e50247c1 100644 --- a/src/main/java/org/openepics/names/service/NotificationService.java +++ b/src/main/java/org/openepics/names/service/NotificationService.java @@ -62,10 +62,10 @@ public class NotificationService { private static final String BACKEND_URL = "backendurl"; private static final String COMMA = ","; - @Value("${naming.backend.swagger.url}") - String namingBackendSwaggerUrl; @Value("${naming.mail.administrator}") String namingMailAdministrator; + @Value("${naming.swagger.url}") + String namingSwaggerUrl; private MailService mailService; @@ -131,7 +131,7 @@ public class NotificationService { ctx.setVariable("updated", updated); ctx.setVariable("deleted", deleted); ctx.setVariable(ADD_FOOTER, true); - ctx.setVariable(BACKEND_URL, namingBackendSwaggerUrl); + ctx.setVariable(BACKEND_URL, namingSwaggerUrl); TemplateEngine engine = generateTemplateEngine(); // send notification @@ -140,7 +140,7 @@ public class NotificationService { : null; String[] ccEmailAddresses = null; String[] replyToEmailAddresses = null; - String subject = CHANGES_NOTIFICATION_NAMES + " - " + namingBackendSwaggerUrl; + String subject = CHANGES_NOTIFICATION_NAMES + " - " + namingSwaggerUrl; mailService.sendEmail(toEmailAddresses, ccEmailAddresses, replyToEmailAddresses, subject, engine.process("templates/notification_names.html", ctx), false, null, null); } @@ -201,7 +201,7 @@ public class NotificationService { ctx.setVariable("updated", updated); ctx.setVariable("deleted", deleted); ctx.setVariable(ADD_FOOTER, true); - ctx.setVariable(BACKEND_URL, namingBackendSwaggerUrl); + ctx.setVariable(BACKEND_URL, namingSwaggerUrl); TemplateEngine engine = generateTemplateEngine(); // send notification @@ -210,7 +210,7 @@ public class NotificationService { : null; String[] ccEmailAddresses = null; String[] replyToEmailAddresses = null; - String subject = CHANGES_NOTIFICATION_STRUCTURES + " - " + namingBackendSwaggerUrl; + String subject = CHANGES_NOTIFICATION_STRUCTURES + " - " + namingSwaggerUrl; mailService.sendEmail(toEmailAddresses, ccEmailAddresses, replyToEmailAddresses, subject, engine.process("templates/notification_structures.html", ctx), false, null, null); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f47586a4..4c2af487 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,8 +2,8 @@ # Naming # ------------------------------------------------------------------------------ -# backend -naming.backend.swagger.url=${NAMING_BACKEND_SWAGGER_URL:http://localhost:8080/swagger-ui.html} +# configuration +spring.config.import=optional:file:.env[.properties] # logging naming.logging.stacktrace.length=10 @@ -30,19 +30,12 @@ spring.mail.properties.mail.smtp.timeout=3000 spring.mail.properties.mail.smtp.writetimeout=5000 spring.mail.debug=false -# spring -# profiles -# config +# data # datasource # jpa -spring.profiles.active=@spring.profiles.active@ - -spring.config.import=optional:file:.env[.properties] - spring.datasource.url=${NAMING_DATABASE_URL:jdbc:postgresql://postgres:5432/discs_names} spring.datasource.username=${NAMING_DATABASE_USERNAME:discs_names} spring.datasource.password=${NAMING_DATABASE_PASSWORD:discs_names} - spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.hibernate.ddl-auto=none spring.jpa.hibernate.show-sql=true @@ -71,10 +64,12 @@ openapi.info.license.name=Copyright (C) 2022 European Spallation Source ERIC. openapi.info.title=Naming REST API # springdoc -# sort the tags -# sort the operation list of each API +# api +# swagger +# url used for notification springdoc.swagger-ui.tagsSorter=alpha springdoc.swagger-ui.operationsSorter=method +naming.swagger.url=${NAMING_SWAGGER_URL:http://localhost:8080/swagger-ui.html} # metrics # actuator diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 5a3904e2..8fe76b37 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -2,8 +2,8 @@ # Naming # ------------------------------------------------------------------------------ -# backend -naming.backend.swagger.url=${NAMING_BACKEND_SWAGGER_URL:http://localhost:8080/swagger-ui.html} +# configuration +spring.config.import=optional:file:.env[.properties] # logging naming.logging.stacktrace.length=10 @@ -30,20 +30,13 @@ spring.mail.properties.mail.smtp.timeout=3000 spring.mail.properties.mail.smtp.writetimeout=5000 spring.mail.debug=false -# spring -# profiles -# config +# data # datasource # jpa -spring.profiles.active=@spring.profiles.active@ - -spring.config.import=optional:file:.env[.properties] - spring.datasource.driver-class-name=org.h2.Driver spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 spring.datasource.username=sa spring.datasource.password=sa - spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.hibernate.ddl-auto=none spring.jpa.hibernate.show-sql=true @@ -72,10 +65,12 @@ openapi.info.license.name=Copyright (C) 2022 European Spallation Source ERIC. openapi.info.title=Naming REST API # springdoc -# sort the tags -# sort the operation list of each API +# api +# swagger +# url used for notification springdoc.swagger-ui.tagsSorter=alpha springdoc.swagger-ui.operationsSorter=method +naming.swagger.url=${NAMING_SWAGGER_URL:http://localhost:8080/swagger-ui.html} # metrics # actuator -- GitLab