Skip to content
Snippets Groups Projects
Commit ef505047 authored by Michal Badin's avatar Michal Badin
Browse files

refactoring: Extracted receivers emails into application.properties

parent 1267b096
No related branches found
No related tags found
3 merge requests!54Merge develop into main,!48Scenario,!44Security
Pipeline #
This commit is part of merge request !44. Comments created here will be created in the context of that merge request.
...@@ -7,7 +7,7 @@ import cz.muni.pa165.exceptions.ResourceNotFoundException; ...@@ -7,7 +7,7 @@ import cz.muni.pa165.exceptions.ResourceNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; 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.core.io.Resource;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -17,10 +17,7 @@ import org.springframework.web.reactive.function.client.WebClient; ...@@ -17,10 +17,7 @@ import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientException; import org.springframework.web.reactive.function.client.WebClientException;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/** /**
* @author Michal Badin * @author Michal Badin
...@@ -30,12 +27,13 @@ public class ApplicationService { ...@@ -30,12 +27,13 @@ public class ApplicationService {
private static final Logger log = LoggerFactory.getLogger(ApplicationService.class); 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_DOCKER = "http://notification:8083";
private static final String NOTIFICATION_MODULE_LOCALHOST = "http://localhost: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_NEW = "/notification/application/new";
private static final String NOTIFICATION_MODULE_URI_STATUS = "/notification/application/status"; 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 ApplicationRepository applicationRepository;
private final WebClient webClient; private final WebClient webClient;
private String NOTIFICATION_MODULE_URL;
@Autowired @Autowired
public ApplicationService(ApplicationRepository applicationRepository, WebClient.Builder webClientBuilder) { public ApplicationService(ApplicationRepository applicationRepository, WebClient.Builder webClientBuilder) {
...@@ -44,8 +42,7 @@ public class ApplicationService { ...@@ -44,8 +42,7 @@ public class ApplicationService {
//if running in docker, modules cannot communicate through localhost //if running in docker, modules cannot communicate through localhost
if (System.getenv("DOCKER") != null) { if (System.getenv("DOCKER") != null) {
NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_DOCKER; NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_DOCKER;
} } else {
else {
NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_LOCALHOST; NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_LOCALHOST;
} }
this.webClient = webClientBuilder.baseUrl(NOTIFICATION_MODULE_URL).build(); this.webClient = webClientBuilder.baseUrl(NOTIFICATION_MODULE_URL).build();
...@@ -63,8 +60,8 @@ public class ApplicationService { ...@@ -63,8 +60,8 @@ public class ApplicationService {
var savedApplication = applicationRepository.save(application); var savedApplication = applicationRepository.save(application);
try { try {
sendPostRequest(savedApplication, NOTIFICATION_MODULE_URI_NEW, List.of(savedApplication.getEmail())); sendPostRequest(savedApplication, NOTIFICATION_MODULE_URI_NEW, notificationReceivers);
} catch (WebClientException e) { } 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)); 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 { ...@@ -90,7 +87,7 @@ public class ApplicationService {
if (savedApplication.getStatus() != ApplicationStatusEnum.PENDING) { if (savedApplication.getStatus() != ApplicationStatusEnum.PENDING) {
try { try {
sendPostRequest(savedApplication, NOTIFICATION_MODULE_URI_STATUS, NOTIFICATION_RECEIVERS); sendPostRequest(savedApplication, NOTIFICATION_MODULE_URI_STATUS, List.of(savedApplication.getEmail()));
} catch (WebClientException e) { } 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)); log.debug(String.format("The notification module is not reachable on the URL: %s, exception %s", NOTIFICATION_MODULE_URL + NOTIFICATION_MODULE_URI_STATUS, e));
} }
......
...@@ -16,4 +16,7 @@ appconfig.enablecache=false ...@@ -16,4 +16,7 @@ appconfig.enablecache=false
management.endpoints.web.exposure.include=health,metrics,loggers,beans,prometheus management.endpoints.web.exposure.include=health,metrics,loggers,beans,prometheus
management.endpoint.health.show-details=always management.endpoint.health.show-details=always
management.endpoint.health.show-components=always management.endpoint.health.show-components=always
management.endpoint.health.probes.enabled=true management.endpoint.health.probes.enabled=true
\ No newline at end of file
#notification receivers
notification.receivers=formula.team.management@gmail.com
\ No newline at end of file
...@@ -7,12 +7,11 @@ import cz.muni.pa165.exceptions.ResourceNotFoundException; ...@@ -7,12 +7,11 @@ import cz.muni.pa165.exceptions.ResourceNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; 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.core.io.Resource;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; 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.WebClient;
import org.springframework.web.reactive.function.client.WebClientException; import org.springframework.web.reactive.function.client.WebClientException;
...@@ -22,13 +21,14 @@ import java.util.*; ...@@ -22,13 +21,14 @@ import java.util.*;
public class CarComponentService extends DomainService<CarComponent> { public class CarComponentService extends DomainService<CarComponent> {
private static final Logger log = LoggerFactory.getLogger(CarComponentService.class); 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_DOCKER = "http://notification:8083";
private static final String NOTIFICATION_MODULE_LOCALHOST = "http://localhost: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 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 @Autowired
public CarComponentService(CarComponentRepository repository, WebClient.Builder webClientBuilder) { public CarComponentService(CarComponentRepository repository, WebClient.Builder webClientBuilder) {
...@@ -38,8 +38,7 @@ public class CarComponentService extends DomainService<CarComponent> { ...@@ -38,8 +38,7 @@ public class CarComponentService extends DomainService<CarComponent> {
//if running in docker, modules cannot communicate through localhost //if running in docker, modules cannot communicate through localhost
if (System.getenv("DOCKER") != null) { if (System.getenv("DOCKER") != null) {
NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_DOCKER; NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_DOCKER;
} } else {
else {
NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_LOCALHOST; NOTIFICATION_MODULE_URL = NOTIFICATION_MODULE_LOCALHOST;
} }
this.webClient = webClientBuilder.baseUrl(NOTIFICATION_MODULE_URL).build(); this.webClient = webClientBuilder.baseUrl(NOTIFICATION_MODULE_URL).build();
...@@ -83,7 +82,7 @@ public class CarComponentService extends DomainService<CarComponent> { ...@@ -83,7 +82,7 @@ public class CarComponentService extends DomainService<CarComponent> {
private void sendPostRequest(CarComponent component) { private void sendPostRequest(CarComponent component) {
Map<String, Object> notification = new HashMap<>(); Map<String, Object> notification = new HashMap<>();
notification.put("carComponent", component); notification.put("carComponent", component);
notification.put("receivers", NOTIFICATION_RECEIVERS); notification.put("receivers", notificationReceivers);
webClient.post() webClient.post()
.uri(NOTIFICATION_MODULE_URI) .uri(NOTIFICATION_MODULE_URI)
......
...@@ -34,4 +34,7 @@ management.endpoint.health.probes.enabled=true ...@@ -34,4 +34,7 @@ management.endpoint.health.probes.enabled=true
management.info.env.enabled=true management.info.env.enabled=true
info.app.encoding=UTF-8 info.app.encoding=UTF-8
info.app.java.source=17 info.app.java.source=17
info.app.java.target=17 info.app.java.target=17
\ No newline at end of file
#notification receivers
notification.receivers=formula.team.management@gmail.com
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment