diff --git a/notificationservice/Dockerfile b/notificationservice/Dockerfile
index a23aef3..7ce521e 100644
--- a/notificationservice/Dockerfile
+++ b/notificationservice/Dockerfile
@@ -1,5 +1,5 @@
FROM openjdk:19
-FROM mysql:8
+#FROM mysql:8
LABEL authors="Seth Pal"
EXPOSE 8080
ADD target/notification-app.jar notification-app.jar
diff --git a/notificationservice/docker-compose.yml b/notificationservice/docker-compose.yml
new file mode 100644
index 0000000..00b6ad2
--- /dev/null
+++ b/notificationservice/docker-compose.yml
@@ -0,0 +1,5 @@
+rabbitmq:
+ image: rabbitmq:management
+ ports:
+ - "5672:5672"
+ - "15672:15672"
\ No newline at end of file
diff --git a/notificationservice/pom.xml b/notificationservice/pom.xml
index 706a45d..deb1444 100644
--- a/notificationservice/pom.xml
+++ b/notificationservice/pom.xml
@@ -1,148 +1,148 @@
-
-
- 4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 3.1.3
-
-
- com.sepal
- notificationservice
- 0.0.1-SNAPSHOT
- notificationservice
- Notification Service using Spring Boot and RabbitMQ
-
- 19
-
-
-
- org.springframework.boot
- spring-boot-starter-amqp
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- org.projectlombok
- lombok
- true
-
-
- org.springframework.boot
- spring-boot-starter-test
-
-
-
- com.h2database
- h2
- runtime
-
-
-
- org.springframework.amqp
- spring-rabbit-test
-
-
-
- org.springframework.boot
- spring-boot-starter-mail
-
-
-
-
-
- com.twilio.sdk
- twilio
- 9.14.0
-
-
-
-
- org.springframework.boot
- spring-boot-starter-data-jpa
-
-
- org.springframework.boot
- spring-boot-starter-jdbc
-
-
-
- org.springframework.boot
- spring-boot-starter-data-jdbc
-
-
-
- org.flywaydb
- flyway-mysql
- 9.22.2
-
-
-
- org.springframework.boot
- spring-boot-devtools
- runtime
- true
-
-
- com.mysql
- mysql-connector-j
- runtime
-
-
- org.springframework.boot
- spring-boot-configuration-processor
- true
-
-
-
- org.springframework.boot
- spring-boot-starter-actuator
-
-
-
- org.springdoc
- springdoc-openapi-starter-webmvc-ui
- 2.2.0
-
-
-
- org.assertj
- assertj-core
- 3.24.2
- test
-
-
-
-
- org.hamcrest
- hamcrest
- 2.2
- test
-
-
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
- org.projectlombok
- lombok
-
-
-
-
-
- notification-app
-
-
-
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 3.1.3
+
+
+ com.sepal
+ notificationservice
+ 0.0.1-SNAPSHOT
+ notificationservice
+ Notification Service using Spring Boot and RabbitMQ
+
+ 19
+
+
+
+ org.springframework.boot
+ spring-boot-starter-amqp
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+
+
+
+ com.h2database
+ h2
+ runtime
+
+
+
+ org.springframework.amqp
+ spring-rabbit-test
+
+
+
+ org.springframework.boot
+ spring-boot-starter-mail
+
+
+
+
+
+ com.twilio.sdk
+ twilio
+ 9.14.0
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jdbc
+
+
+
+ org.flywaydb
+ flyway-mysql
+ 9.22.2
+
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ runtime
+ true
+
+
+ com.mysql
+ mysql-connector-j
+ runtime
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+ org.springdoc
+ springdoc-openapi-starter-webmvc-ui
+ 2.2.0
+
+
+
+ org.assertj
+ assertj-core
+ 3.24.2
+ test
+
+
+
+
+ org.hamcrest
+ hamcrest
+ 2.2
+ test
+
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+ notification-app
+
+
+
diff --git a/notificationservice/src/main/java/com/sepal/notificationservice/NotificationserviceApplication.java b/notificationservice/src/main/java/com/sepal/notificationservice/NotificationserviceApplication.java
index f158b28..3df148c 100644
--- a/notificationservice/src/main/java/com/sepal/notificationservice/NotificationserviceApplication.java
+++ b/notificationservice/src/main/java/com/sepal/notificationservice/NotificationserviceApplication.java
@@ -1,33 +1,48 @@
-package com.sepal.notificationservice;
-
-
-import com.twilio.Twilio;
-import jakarta.annotation.PostConstruct;
-import lombok.RequiredArgsConstructor;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-import com.sepal.notificationservice.config.TwilioConfig;
-import org.springframework.context.annotation.Configuration;
-
-@SpringBootApplication()
-@Configuration
-public class NotificationserviceApplication {
-
- @Value("${twilio.accountSID}")
- private String accountSSID;
-
- @Value("${twilio.authToken}")
- private String auth;
- public static void main(String[] args) {
- SpringApplication.run(NotificationserviceApplication.class, args);
- }
-
- @PostConstruct
- public void setup()
- {
-
- Twilio.init(accountSSID,auth);
- }
-}
+package com.sepal.notificationservice;
+
+
+import com.twilio.Twilio;
+import jakarta.annotation.PostConstruct;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+import com.sepal.notificationservice.config.TwilioConfig;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.Base64;
+
+@SpringBootApplication
+@Configuration
+public class NotificationserviceApplication {
+
+ @Value("${twilio.accountSID}")
+ private String accountSSID;
+
+ @Value("${twilio.authToken}")
+ private String auth;
+
+ public static void main(String[] args) {
+ SpringApplication.run(NotificationserviceApplication.class, args);
+ }
+
+ @PostConstruct
+ public void setup()
+ {
+ Twilio.init(decodeValue(accountSSID),decodeValue(auth));
+ }
+ public String decodeValue(String encodedValue)
+ {
+ byte[] decodedBytes = Base64.getDecoder().decode(encodedValue);
+ return new String(decodedBytes);
+ }
+
+ public String encodeValue(String encodedValue) {
+ String BasicBase64format
+ = Base64.getEncoder()
+ .encodeToString(encodedValue.getBytes());
+ return BasicBase64format;
+ }
+}
diff --git a/notificationservice/src/main/java/com/sepal/notificationservice/config/TwilioConfig.java b/notificationservice/src/main/java/com/sepal/notificationservice/config/TwilioConfig.java
index ebd6ac4..bf2fecf 100644
--- a/notificationservice/src/main/java/com/sepal/notificationservice/config/TwilioConfig.java
+++ b/notificationservice/src/main/java/com/sepal/notificationservice/config/TwilioConfig.java
@@ -1,14 +1,8 @@
package com.sepal.notificationservice.config;
-
-import com.twilio.Twilio;
-import jakarta.annotation.PostConstruct;
import lombok.Data;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
-import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
-
import java.util.Base64;
@Service
@@ -23,11 +17,19 @@ public class TwilioConfig {
private String fromNumber;
private String toNumber="+919538965414";
+
public String decodeValue(String encodedValue)
{
byte[] decodedBytes = Base64.getDecoder().decode(encodedValue);
return new String(decodedBytes);
}
+ public String encodeValue(String encodedValue) {
+ String BasicBase64format
+ = Base64.getEncoder()
+ .encodeToString(encodedValue.getBytes());
+ return BasicBase64format;
+ }
+
}
diff --git a/notificationservice/src/main/java/com/sepal/notificationservice/consumer/RabbitMQJsonConsumner.java b/notificationservice/src/main/java/com/sepal/notificationservice/consumer/RabbitMQJsonConsumner.java
index 68a7067..1f31726 100644
--- a/notificationservice/src/main/java/com/sepal/notificationservice/consumer/RabbitMQJsonConsumner.java
+++ b/notificationservice/src/main/java/com/sepal/notificationservice/consumer/RabbitMQJsonConsumner.java
@@ -11,6 +11,7 @@
import com.sepal.notificationservice.repositories.UserRepository;
import com.sepal.notificationservice.services.SendEmailService;
import com.sepal.notificationservice.services.SendSMSService;
+import com.sepal.notificationservice.services.UserService;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
@@ -49,16 +50,22 @@ public class RabbitMQJsonConsumner {
@Autowired
private NotificationRepository notificationRepository;
+ @Autowired
+ private UserService userService;
+
public RabbitMQJsonConsumner(SendEmailService sendEmailService
, SendSMSService sendSMSService
, UserRepository userRepository
- , NotificationRepository notificationRepository)
+ , NotificationRepository notificationRepository
+ ,UserService userService
+ )
{
this.sendEmailService = sendEmailService;
this.userRepository = userRepository;
this.notificationRepository = notificationRepository;
this.sendSMSService = sendSMSService;
+ this.userService=userService;
}
//Consumer is subscribed to the Queue
@@ -78,7 +85,8 @@ For that user id I will fetch the user contact (email address and mobile number)
Optional userOptional;
userOptional = userRepository.findById(Long.valueOf(notificationDto.getUserid()));
-
+ //below line need to enable once the User Service is working fine
+ //userDto=userService.getUserById(Long.valueOf(notificationDto.getUserid()));
//Check if user is present in DB or not
if(userOptional.isEmpty()){
notificationStatus= String.valueOf(Status.FAILED);
@@ -100,7 +108,6 @@ For that user id I will fetch the user contact (email address and mobile number)
notification.setStatus((Status.DELIVERED));
notification.setUser_id(notificationDto.getUserid());
notificationRepository.save(notification);
-
notificationStatus = String.valueOf(Status.DELIVERED);
}
diff --git a/notificationservice/src/main/java/com/sepal/notificationservice/controllers/NotificationHistoryController.java b/notificationservice/src/main/java/com/sepal/notificationservice/controllers/NotificationHistoryController.java
index 0ca58bf..fec729a 100644
--- a/notificationservice/src/main/java/com/sepal/notificationservice/controllers/NotificationHistoryController.java
+++ b/notificationservice/src/main/java/com/sepal/notificationservice/controllers/NotificationHistoryController.java
@@ -3,6 +3,7 @@
import com.sepal.notificationservice.dtos.NotificationHistoryResponseDto;
import com.sepal.notificationservice.services.NotificationHistoryService;
import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
@@ -15,7 +16,7 @@
@RequiredArgsConstructor
@RequestMapping("/api/v1")
public class NotificationHistoryController {
- //@Autowired
+ @Autowired
NotificationHistoryService notificationHistoryService;
public NotificationHistoryController(NotificationHistoryService notificationHistoryService) {
diff --git a/notificationservice/src/main/java/com/sepal/notificationservice/repositories/UserContactRepository.java b/notificationservice/src/main/java/com/sepal/notificationservice/repositories/UserContactRepository.java
new file mode 100644
index 0000000..3cf2878
--- /dev/null
+++ b/notificationservice/src/main/java/com/sepal/notificationservice/repositories/UserContactRepository.java
@@ -0,0 +1,12 @@
+package com.sepal.notificationservice.repositories;
+
+import com.sepal.notificationservice.models.UserContact;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+
+public interface UserContactRepository extends JpaRepository {
+
+
+}
diff --git a/notificationservice/src/main/java/com/sepal/notificationservice/services/RabbitMQJsonProducerService.java b/notificationservice/src/main/java/com/sepal/notificationservice/services/RabbitMQJsonProducerService.java
index 87427d7..a3a9b61 100644
--- a/notificationservice/src/main/java/com/sepal/notificationservice/services/RabbitMQJsonProducerService.java
+++ b/notificationservice/src/main/java/com/sepal/notificationservice/services/RabbitMQJsonProducerService.java
@@ -15,7 +15,7 @@
public class RabbitMQJsonProducerService {
- //private static final Logger LOGGER= LoggerFactory.getLogger(RabbitMQJsonProducerService.class);
+ private static final Logger LOGGER= LoggerFactory.getLogger(RabbitMQJsonProducerService.class);
@Value("${rabbitmq.exchange.name}")
private String exchange;
@Value("${rabbitmq.json.routing.key}")
@@ -32,7 +32,7 @@ public RabbitMQJsonProducerService(RabbitTemplate rabbitTemplate) {
public String sendJsonMessage(NotificationRequestDto user)
{
String message="Notification sent to registered email and mobile, kindly check your email/mobile";
- //LOGGER.info(String.format(message+"--> %s", user.toString()));
+ LOGGER.info(String.format(message+"--> %s", user.toString()));
rabbitTemplate.convertAndSend(exchange,jsonRoutingKey,user);
return message;
}
diff --git a/notificationservice/src/main/java/com/sepal/notificationservice/services/SendEmailService.java b/notificationservice/src/main/java/com/sepal/notificationservice/services/SendEmailService.java
index d3cffc1..d004ff1 100644
--- a/notificationservice/src/main/java/com/sepal/notificationservice/services/SendEmailService.java
+++ b/notificationservice/src/main/java/com/sepal/notificationservice/services/SendEmailService.java
@@ -19,7 +19,7 @@
@EnableAutoConfiguration
public class SendEmailService {
- // private static final Logger LOGGER= LoggerFactory.getLogger(SendEmailService.class);
+ private static final Logger LOGGER= LoggerFactory.getLogger(SendEmailService.class);
@Autowired
private JavaMailSender mailSender;
@@ -38,7 +38,7 @@ public NotificationResponseDto sendEmail(
message.setSubject(subject);
message.setText(body);
mailSender.send(message);
- // LOGGER.info("Mail Sent Successfully........."+mailSender);
+ LOGGER.info("Mail Sent Successfully........."+mailSender);
notificationResponseDto.setStatus(String.valueOf(Status.DELIVERED));
}catch(Exception ex)
{
diff --git a/notificationservice/src/main/java/com/sepal/notificationservice/services/SendSMSService.java b/notificationservice/src/main/java/com/sepal/notificationservice/services/SendSMSService.java
index e827785..b653956 100644
--- a/notificationservice/src/main/java/com/sepal/notificationservice/services/SendSMSService.java
+++ b/notificationservice/src/main/java/com/sepal/notificationservice/services/SendSMSService.java
@@ -16,22 +16,22 @@ public class SendSMSService {
@Autowired
TwilioConfig twilioConfig;
- //private static final Logger LOGGER= LoggerFactory.getLogger(SendSMSService.class);
+ private static final Logger LOGGER= LoggerFactory.getLogger(SendSMSService.class);
public NotificationResponseDto sendSMS(String to, String sms) {
NotificationResponseDto notificationResponseDto=new NotificationResponseDto();
try {
Message message = Message
.creator(new PhoneNumber(to)
- , new PhoneNumber(twilioConfig.decodeValue(twilioConfig.getFromNumber()))
+ , new PhoneNumber(twilioConfig.getFromNumber())
, sms)
.create();
notificationResponseDto.setStatus(String.valueOf(Status.DELIVERED));
- //LOGGER.info("SMS Sent successfully....." + message.getStatus());
+ LOGGER.info("SMS Sent successfully....." + message.getStatus());
}catch (Exception ex)
{
notificationResponseDto.setStatus(String.valueOf(Status.FAILED));
- // LOGGER.error("Kindly check if you mobile number is in verified account.....Error-->" + ex.getMessage());
+ LOGGER.error("Kindly check if you mobile number is in verified account.....Error-->" + ex.getMessage());
}
return notificationResponseDto;
}
diff --git a/notificationservice/src/main/java/com/sepal/notificationservice/services/UserService.java b/notificationservice/src/main/java/com/sepal/notificationservice/services/UserService.java
new file mode 100644
index 0000000..4ea4e5f
--- /dev/null
+++ b/notificationservice/src/main/java/com/sepal/notificationservice/services/UserService.java
@@ -0,0 +1,27 @@
+package com.sepal.notificationservice.services;
+
+import com.sepal.notificationservice.dtos.UserDto;
+import com.sepal.notificationservice.thirdpartyClients.UserDtoClient;
+import com.sepal.notificationservice.thirdpartyClients.UserServiceClient;
+import org.springframework.stereotype.Service;
+
+@Service
+public class UserService {
+ private UserServiceClient userServiceClient;
+ public UserService(UserServiceClient userServiceClient) {
+ this.userServiceClient = userServiceClient;
+ }
+
+ public UserDto getUserById(Long id) {
+
+ UserDto userDto =new UserDto();
+ UserDtoClient userDtoClient=new UserDtoClient();
+ userDtoClient=userServiceClient.getProductById(id);
+ userDto.setUserid(id);
+ userDto.setEmail(userDtoClient.getEmail());
+ userDto.setMobile(userDtoClient.getPhone());
+ return userDto;
+ }
+
+
+}
diff --git a/notificationservice/src/main/java/com/sepal/notificationservice/thirdpartyClients/UserDtoClient.java b/notificationservice/src/main/java/com/sepal/notificationservice/thirdpartyClients/UserDtoClient.java
new file mode 100644
index 0000000..370e248
--- /dev/null
+++ b/notificationservice/src/main/java/com/sepal/notificationservice/thirdpartyClients/UserDtoClient.java
@@ -0,0 +1,17 @@
+package com.sepal.notificationservice.thirdpartyClients;
+
+import jakarta.persistence.ManyToMany;
+import lombok.Data;
+
+import java.util.HashSet;
+import java.util.Set;
+
+@Data
+public class UserDtoClient {
+
+ private String name = "";
+ private String email = "";
+ private String phone = "";
+ private String password="";
+ private Set