diff --git a/application/src/main/java/cz/muni/pa165/service/ApplicationService.java b/application/src/main/java/cz/muni/pa165/service/ApplicationService.java index 1a1ce76547eb1c216d7a437814fd2800a7485495..cfdd2fdcc25e1ae16f59c7e49fe21e70a1942c0a 100644 --- a/application/src/main/java/cz/muni/pa165/service/ApplicationService.java +++ b/application/src/main/java/cz/muni/pa165/service/ApplicationService.java @@ -7,7 +7,7 @@ import cz.muni.pa165.exceptions.ResourceNotFoundException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.ParameterizedTypeReference; +import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.Resource; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; @@ -17,10 +17,7 @@ import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClientException; import java.time.LocalDate; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; /** * @author Michal Badin @@ -30,12 +27,13 @@ public class ApplicationService { private static final Logger log = LoggerFactory.getLogger(ApplicationService.class); private static final String NOTIFICATION_MODULE_DOCKER = "http://notification:8083"; private static final String NOTIFICATION_MODULE_LOCALHOST = "http://localhost:8083"; - private String NOTIFICATION_MODULE_URL; private static final String NOTIFICATION_MODULE_URI_NEW = "/notification/application/new"; private static final String NOTIFICATION_MODULE_URI_STATUS = "/notification/application/status"; - private static final List<String> NOTIFICATION_RECEIVERS = List.of("formula.team.management@gmail.com"); + @Value("${notification.receivers}") + private final List<String> notificationReceivers = new ArrayList<>(); private final ApplicationRepository applicationRepository; private final WebClient webClient; + private String NOTIFICATION_MODULE_URL; @Autowired public ApplicationService(ApplicationRepository applicationRepository, WebClient.Builder webClientBuilder) { @@ -44,8 +42,7 @@ public class ApplicationService { //if running in docker, modules cannot communicate through localhost if (System.getenv("DOCKER") != null) { NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_DOCKER; - } - else { + } else { NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_LOCALHOST; } this.webClient = webClientBuilder.baseUrl(NOTIFICATION_MODULE_URL).build(); @@ -63,8 +60,8 @@ public class ApplicationService { var savedApplication = applicationRepository.save(application); try { - sendPostRequest(savedApplication, NOTIFICATION_MODULE_URI_NEW, List.of(savedApplication.getEmail())); - } catch (WebClientException e) { + sendPostRequest(savedApplication, NOTIFICATION_MODULE_URI_NEW, notificationReceivers); + } catch (WebClientException e) { log.debug(String.format("The notification module is not reachable on the URL: %s, exception %s", NOTIFICATION_MODULE_URL + NOTIFICATION_MODULE_URI_NEW, e)); } @@ -90,7 +87,7 @@ public class ApplicationService { if (savedApplication.getStatus() != ApplicationStatusEnum.PENDING) { try { - sendPostRequest(savedApplication, NOTIFICATION_MODULE_URI_STATUS, NOTIFICATION_RECEIVERS); + sendPostRequest(savedApplication, NOTIFICATION_MODULE_URI_STATUS, List.of(savedApplication.getEmail())); } catch (WebClientException e) { log.debug(String.format("The notification module is not reachable on the URL: %s, exception %s", NOTIFICATION_MODULE_URL + NOTIFICATION_MODULE_URI_STATUS, e)); } diff --git a/application/src/main/resources/application.properties b/application/src/main/resources/application.properties index 698b657daaa27aed0566ba8ed7402c942f2bf35b..a41e2a36375436609b3fed5d065ae2da58843478 100644 --- a/application/src/main/resources/application.properties +++ b/application/src/main/resources/application.properties @@ -16,4 +16,7 @@ appconfig.enablecache=false management.endpoints.web.exposure.include=health,metrics,loggers,beans,prometheus management.endpoint.health.show-details=always management.endpoint.health.show-components=always -management.endpoint.health.probes.enabled=true \ No newline at end of file +management.endpoint.health.probes.enabled=true + +#notification receivers +notification.receivers=formula.team.management@gmail.com \ No newline at end of file diff --git a/core/src/main/java/cz/muni/pa165/service/CarComponentService.java b/core/src/main/java/cz/muni/pa165/service/CarComponentService.java index f16c6749fd49cb521cc05ae19bfb1f5651c486de..6fd277748b653db0b3b583ccc8af40312f4d2a8f 100644 --- a/core/src/main/java/cz/muni/pa165/service/CarComponentService.java +++ b/core/src/main/java/cz/muni/pa165/service/CarComponentService.java @@ -7,12 +7,11 @@ import cz.muni.pa165.exceptions.ResourceNotFoundException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.ParameterizedTypeReference; +import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.Resource; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.client.*; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClientException; @@ -22,13 +21,14 @@ import java.util.*; public class CarComponentService extends DomainService<CarComponent> { private static final Logger log = LoggerFactory.getLogger(CarComponentService.class); - private final CarComponentRepository componentRepository; - private final WebClient webClient; private static final String NOTIFICATION_MODULE_DOCKER = "http://notification:8083"; private static final String NOTIFICATION_MODULE_LOCALHOST = "http://localhost:8083"; - private String NOTIFICATION_MODULE_URL; private static final String NOTIFICATION_MODULE_URI = "/notification/component"; - private static final List<String> NOTIFICATION_RECEIVERS = List.of("formula.team.management@gmail.com"); + private final CarComponentRepository componentRepository; + private final WebClient webClient; + @Value("${notification.receivers}") + private final List<String> notificationReceivers = new ArrayList<>(); + private String NOTIFICATION_MODULE_URL; @Autowired public CarComponentService(CarComponentRepository repository, WebClient.Builder webClientBuilder) { @@ -38,8 +38,7 @@ public class CarComponentService extends DomainService<CarComponent> { //if running in docker, modules cannot communicate through localhost if (System.getenv("DOCKER") != null) { NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_DOCKER; - } - else { + } else { NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_LOCALHOST; } this.webClient = webClientBuilder.baseUrl(NOTIFICATION_MODULE_URL).build(); @@ -83,7 +82,7 @@ public class CarComponentService extends DomainService<CarComponent> { private void sendPostRequest(CarComponent component) { Map<String, Object> notification = new HashMap<>(); notification.put("carComponent", component); - notification.put("receivers", NOTIFICATION_RECEIVERS); + notification.put("receivers", notificationReceivers); webClient.post() .uri(NOTIFICATION_MODULE_URI) diff --git a/core/src/main/resources/application.properties b/core/src/main/resources/application.properties index d0fa9b659da46c81276396a3e129a6eaadeb6dc2..f2c74faaa1f71d839634e9d836e4c670ba93150f 100644 --- a/core/src/main/resources/application.properties +++ b/core/src/main/resources/application.properties @@ -34,4 +34,7 @@ management.endpoint.health.probes.enabled=true management.info.env.enabled=true info.app.encoding=UTF-8 info.app.java.source=17 -info.app.java.target=17 \ No newline at end of file +info.app.java.target=17 + +#notification receivers +notification.receivers=formula.team.management@gmail.com \ No newline at end of file