Skip to content

Commit

Permalink
Merge pull request #34 from pankajjangid05/prod-development
Browse files Browse the repository at this point in the history
Prod development
  • Loading branch information
pankajjangid05 authored May 8, 2023
2 parents 467d55e + a05bcba commit bd6251c
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Maven Build
on:
push:
branches:
["release-4.*.*", "release-5.*.*", "release-v2.*.*"]
["release-4.*.*", "release-5.*.*", "release-v2.*.*", "master", "development"]
pull_request:
branches:
["release-4.*.*", "release-5.*.*", "release-v2.*.*"]
["release-4.*.*", "release-5.*.*", "release-v2.*.*", "master", "development"]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Docker Build
on:
push:
tags:
- 'v*.*.*'
["v*.*.*", "v*.*.*-*"]

jobs:
docker-build-push:
Expand Down
13 changes: 8 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
</parent>
<groupId>com.uci</groupId>
<artifactId>outbound</artifactId>
<version>2.1.0</version>
<version>2.2.1</version>
<name>outbound</name>
<description>outbound</description>

<properties>
<java.version>11</java.version>
<utils.version>2.2.1</utils.version>
<dao.version>2.2.1</dao.version>
<adapter.version>2.2.1</adapter.version>
</properties>

<!-- For Downloading repositories from github packages -->
Expand Down Expand Up @@ -85,7 +88,7 @@
<dependency>
<groupId>com.uci</groupId>
<artifactId>utils</artifactId>
<version>2.1.0</version>
<version>${utils.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -101,7 +104,7 @@
<dependency>
<groupId>com.uci</groupId>
<artifactId>adapter</artifactId>
<version>2.1.0</version>
<version>${adapter.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.projectreactor/reactor-core -->
<dependency>
Expand All @@ -122,7 +125,7 @@
<dependency>
<groupId>com.uci</groupId>
<artifactId>dao</artifactId>
<version>2.1.0</version>
<version>${dao.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -150,7 +153,7 @@
<version>4.9.3</version>
</dependency>
<!-- Minio CDN Dependencies - End -->
</dependencies>
</dependencies>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@
import com.uci.adapter.provider.factory.ProviderFactory;
import com.uci.dao.models.XMessageDAO;
import com.uci.dao.repository.XMessageRepository;
import com.uci.dao.utils.XMessageDAOUtils;
import com.uci.utils.cache.service.RedisCacheService;
import com.uci.utils.model.EmailDetails;
import com.uci.utils.service.EmailServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import messagerosa.core.model.XMessage;
import com.uci.dao.utils.XMessageDAOUtils;
import com.uci.utils.cache.service.RedisCacheService;

import io.fusionauth.client.FusionAuthClient;
import io.fusionauth.domain.api.LoginRequest;
import messagerosa.xml.XMessageParser;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.kafka.receiver.ReceiverRecord;
import javax.xml.bind.JAXBException;

import javax.xml.bind.JAXBException;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

@Component
Expand All @@ -38,42 +40,53 @@ public class OutboundKafkaController {

@Autowired
private XMessageRepository xMessageRepo;

@Autowired
private RedisCacheService redisCacheService;

private HashOperations hashOperations; //to access Redis cache

@Autowired
private EmailServiceImpl emailService;

@Value("${spring.mail.recipient}")
private String recipient;

@EventListener(ApplicationStartedEvent.class)
public void onMessage() {

reactiveKafkaReceiver
.doOnNext(new Consumer<ReceiverRecord<String, String>>() {
@Override
public void accept(ReceiverRecord<String, String> msg) {
log.info("kafka message receieved!");
log.info("kafka message receieved!");
XMessage currentXmsg = null;
try {
currentXmsg = XMessageParser.parse(new ByteArrayInputStream(msg.value().getBytes()));
sendOutboundMessage(currentXmsg);
} catch (Exception e) {
e.printStackTrace();
HashMap<String, String> attachments = new HashMap<>();
attachments.put("Exception", ExceptionUtils.getStackTrace(e));
attachments.put("XMessage", currentXmsg.toString());
sentEmail(currentXmsg, "Error in Outbound", "PFA", recipient, null, attachments);
log.error("An Error Occored : " + e.getMessage());
}

}
})
.doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable e) {
System.out.println(e.getMessage());
log.error("KafkaFlux exception", e);
HashMap<String, String> attachments = new HashMap<>();
attachments.put("Exception", ExceptionUtils.getStackTrace(e));
sentEmail(null, "Error in Outbound", "PFA", recipient, null, attachments);
log.error("KafkaFlux exception", e.getMessage());
}
})
.subscribe();
}

/**
* Send outbound message to user using the current xmsg
*
* @param currentXmsg
* @throws Exception
*/
Expand All @@ -85,13 +98,18 @@ public void sendOutboundMessage(XMessage currentXmsg) throws Exception {
.doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable e) {
log.error("Exception in processOutBoundMessageF:"+e.getMessage());
HashMap<String, String> attachments = new HashMap<>();
attachments.put("Exception", ExceptionUtils.getStackTrace(e));
attachments.put("XMessage", currentXmsg.toString());
sentEmail(currentXmsg, "Error in Outbound", "PFA", recipient, null, attachments);
log.error("Exception in processOutBoundMessageF:" + e.getMessage());
}
}).subscribe(new Consumer<XMessage>() {
@Override
public void accept(XMessage xMessage) {
if(xMessage.getApp() != null) {
try{
if (xMessage.getApp() != null) {
try {
log.info("Outbound convertXMessageToDAO : " + xMessage.toString());
XMessageDAO dao = XMessageDAOUtils.convertXMessageToDAO(xMessage);
redisCacheService.setXMessageDaoCache(xMessage.getTo().getUserID(), dao);
xMessageRepo
Expand All @@ -100,7 +118,7 @@ public void accept(XMessage xMessage) {
@Override
public void accept(Throwable e) {
redisCacheService.deleteXMessageDaoCache(xMessage.getTo().getUserID());
log.error("Exception in xMsg Dao Save:"+e.getMessage());
log.error("Exception in xMsg Dao Save:" + e.getMessage());
}
})
.subscribe(new Consumer<XMessageDAO>() {
Expand All @@ -109,25 +127,43 @@ public void accept(XMessageDAO xMessageDAO) {
log.info("XMessage Object saved is with sent user ID >> " + xMessageDAO.getUserId());
}
});
}catch(Exception e){
} catch (Exception e) {
HashMap<String, String> attachments = new HashMap<>();
attachments.put("Exception", ExceptionUtils.getStackTrace(e));
attachments.put("XMessage", currentXmsg.toString());
sentEmail(xMessage, "Error in Outbound", "PFA", recipient, null, attachments);
log.error("Exception in convertXMessageToDAO:" + e.getMessage());
try{
log.error("The current XMessage was " + xMessage.toXML());
}catch(JAXBException j) {
log.error("Unable to parse the current XMessage " + xMessage.toString());
}catch(Exception ge) {
log.error("Unable to parse the current XMessage ge " + xMessage.toString());
try {
log.error("The current XMessage was : " + xMessage.toString());
} catch (Exception ge) {
ge.printStackTrace();
log.error("Unable to parse the current XMessage : " + ge.getMessage() + " Xmessage : " + ge.getMessage());
}
e.printStackTrace();
}
} else {
log.info("XMessage -> app is empty");
log.info("XMessage -> app is empty");
}

}
});
}

private String redisKeyWithPrefix(String key) {
return System.getenv("ENV")+"-"+key;
return System.getenv("ENV") + "-" + key;
}

private void sentEmail(XMessage xMessage, String subject, String body, String recipient, String attachmentFileName, HashMap<String, String> attachments) {
log.info("Email Sending....");
EmailDetails emailDetails = new EmailDetails().builder()
.subject(subject)
.msgBody(body)
.recipient(recipient)
.attachment(xMessage == null ? "" : xMessage.toString())
.attachmentFileName(attachmentFileName)
.attachments(attachments)
.build();
// log.info("EmailDetails :" + emailDetails);
emailService.sendMailWithAttachment(emailDetails);
}
}
10 changes: 10 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,13 @@ file.cdn.selected=${SELECTED_FILE_CDN:#{"azure"}}

#for notification key enable/disable when notification triggered
fcm.notificationKeyEnable=${NOTIFICATION_KEY_ENABLE:#{"true"}}

#Email Config SMTP
spring.mail.host=${EMAIL_HOST:#{""}}
spring.mail.port=${EMAIL_PORT:#{""}}
spring.mail.username=${EMAIL_USERNAME:#{""}}
spring.mail.password=${EMAIL_PASSWORD:#{""}}
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.recipient=${RECIPIENT_EMAILS:#{""}}

2 changes: 1 addition & 1 deletion src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}:%line): %msg%n%throwable
</Pattern>
</layout>
</appender>
Expand Down

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/test.iml

This file was deleted.

0 comments on commit bd6251c

Please sign in to comment.