Skip to content

Commit

Permalink
Merge Code and Updated Release Version
Browse files Browse the repository at this point in the history
  • Loading branch information
pankajjangid05 committed Jun 26, 2023
2 parents 76d46c2 + 89ff3d7 commit ea19bce
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 98 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/docker-build-push-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Docker Build
on:
push:
branches:
- development
jobs:
docker-build-push:
runs-on: ubuntu-20.04
timeout-minutes: 40
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Extract version from pom.xml
id: version
run: |
echo ::set-output name=VERSION::$(grep -A 1 '<artifactId>inbound</artifactId>' pom.xml | grep -oP '(?<=<version>).*?(?=</version>)')
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{secrets.DOCKER_HUB_USERNAME}}
password: ${{secrets.DOCKER_HUB_ACCESS_TOKEN}}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: "."
push: true
tags: samagragovernance/inbound:v${{ steps.version.outputs.VERSION }}-SNAPSHOT
build-args: |
username=${{ secrets.USERNAME }},
token=${{ secrets.TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/docker-build-push-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Docker Build
on:
push:
branches:
- master
jobs:
docker-build-push:
runs-on: ubuntu-20.04
timeout-minutes: 40
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Extract version from pom.xml
id: version
run: |
echo ::set-output name=VERSION::$(grep -A 1 '<artifactId>inbound</artifactId>' pom.xml | grep -oP '(?<=<version>).*?(?=</version>)')
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{secrets.DOCKER_HUB_USERNAME}}
password: ${{secrets.DOCKER_HUB_ACCESS_TOKEN}}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: "."
push: true
tags: samagragovernance/inbound:v${{ steps.version.outputs.VERSION }}
build-args: |
username=${{ secrets.USERNAME }},
token=${{ secrets.TOKEN }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ ADD /src $HOME/src
RUN mvn package -s $HOME/settings.xml -DskipTests=true

# Package stage
FROM openjdk:11
FROM ibm-semeru-runtimes:open-11.0.18_10-jre
ENV HOME=/home/app
ENV export $(cat .env | xargs)
WORKDIR $HOME
COPY --from=build $HOME/target/*.jar app.jar

EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
ENTRYPOINT ["java","-Xmx1024m","-Xshareclasses","-XX:+CMSClassUnloadingEnabled","-XX:+UseG1GC","-XX:+ExplicitGCInvokesConcurrent","-jar","app.jar"]
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
</parent>
<groupId>com.uci</groupId>
<artifactId>inbound</artifactId>
<version>2.2.1</version>
<version>2.2.9</version>
<name>inbound</name>
<description>inbound</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>
<utils.version>2.2.4</utils.version>
<dao.version>2.2.4</dao.version>
<adapter.version>2.2.4</adapter.version>
</properties>
<!-- For Downloading repositories from github packages -->
<repositories>
Expand Down
100 changes: 100 additions & 0 deletions src/main/java/com/uci/inbound/TestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.uci.inbound;

import com.uci.dao.models.XMessageDAO;
import com.uci.dao.repository.XMessageRepository;
import com.uci.utils.bot.util.BotUtil;
import lombok.extern.java.Log;
import messagerosa.core.model.XMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

@Log
@RestController
public class TestController {

@Autowired
public XMessageRepository xMessageRepository;
LocalDateTime yesterday = LocalDateTime.now().minusMonths(1L);

long totalSuccessCount = 0;

@GetMapping("/testInboundCass")
public void getLastMsg(@RequestParam(value = "repeat", required = false) String repeat) throws InterruptedException {
int count = 10;

try {
count = Integer.parseInt(repeat);
} catch (NumberFormatException ex) {
ex.printStackTrace();
}
for (int i = 0; i < count; i++) {
int finalI = i;
getLatestXMessage("9783246247", yesterday, "SENT")
.doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) {
log.severe("Error in getLatestXMessage : " + throwable.getMessage());
}
})
.subscribe(new Consumer<XMessageDAO>() {
@Override
public void accept(XMessageDAO xMsgDao) {
totalSuccessCount++;
log.info("TestController:found xMsgDao : " + xMsgDao.getMessageId() + " count: " + totalSuccessCount);
}
});
}

// for (int i = 0; i < count; i++) {
//
// int finalI = i;
// getLatestXMessage("9783246247", yesterday, "SENT").doOnNext(lastMessageID -> {
// log.info(lastMessageID.getMessageId() + " Count : " + finalI);
// }).subscribe();
// Thread.sleep(1000);
// }
}

private Mono<XMessageDAO> getLatestXMessage(String userId, LocalDateTime yesterday, String messageState) {
return xMessageRepository.findFirstByUserIdInAndFromIdInAndMessageStateInAndTimestampAfterOrderByTimestampDesc(List.of(BotUtil.adminUserId, userId), List.of(BotUtil.adminUserId, userId), List.of("SENT", "REPLIED"), yesterday)
.collectList()
.map(new Function<List<XMessageDAO>, XMessageDAO>() {
@Override
public XMessageDAO apply(List<XMessageDAO> xMessageDAOS) {
log.info("xMsgDaos size: " + xMessageDAOS.size() + ", messageState.name: " + XMessage.MessageState.SENT.name());
if (xMessageDAOS.size() > 0) {
List<XMessageDAO> filteredList = new ArrayList<>();
for (XMessageDAO xMessageDAO : xMessageDAOS) {
if (xMessageDAO.getMessageState().equals(XMessage.MessageState.SENT.name())
|| xMessageDAO.getMessageState().equals(XMessage.MessageState.REPLIED.name())) {
filteredList.add(xMessageDAO);
}

}
if (filteredList.size() > 0) {
filteredList.sort(new Comparator<XMessageDAO>() {
@Override
public int compare(XMessageDAO o1, XMessageDAO o2) {
return o1.getTimestamp().compareTo(o2.getTimestamp());
}
});
}

return xMessageDAOS.get(0);
}
return new XMessageDAO();
}
});
}
}
102 changes: 58 additions & 44 deletions src/main/java/com/uci/inbound/incoming/CampaignController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import messagerosa.core.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -57,7 +58,8 @@ public class CampaignController {
private long cassInsertErrorCount;

@RequestMapping(value = "/start", method = RequestMethod.GET)
public ResponseEntity<String> startCampaign(@RequestParam("campaignId") String campaignId, @RequestParam(value = "page", required = false) String page) throws JsonProcessingException, JAXBException {
public ResponseEntity<String> startCampaign(@RequestParam("campaignId") String campaignId, @RequestParam(value = "page", required = false) String page,
@RequestHeader(value = "Conversation-Authorization", required = false) String conversationAuthorization) {
final long startTime = System.nanoTime();
logTimeTaken(startTime, 0, "process-start: %d ms");
log.info("Call campaign service : "+campaignId+" page : "+page);
Expand All @@ -68,51 +70,63 @@ public ResponseEntity<String> startCampaign(@RequestParam("campaignId") String c
} else {
meta = null;
}
if(conversationAuthorization != null && !conversationAuthorization.isEmpty()){
log.info("Conversation Authorization found : True");
if(meta == null){
meta = new HashMap<>();
}
meta.put("conversation-authorization", conversationAuthorization);
}
Map<String, String> finalMeta = meta;
botService.getBotNodeFromId(campaignId).subscribe(data -> {
SenderReceiverInfo from = new SenderReceiverInfo().builder().userID("9876543210").deviceType(DeviceType.PHONE).meta(meta).build();
SenderReceiverInfo to = new SenderReceiverInfo().builder().userID("admin").build();
MessageId msgId = new MessageId().builder().channelMessageId(UUID.randomUUID().toString()).replyId("7597185708").build();
XMessagePayload payload = new XMessagePayload().builder().text(BotUtil.getBotNodeData(data, "startingMessage")).build();
JsonNode adapter = BotUtil.getBotNodeAdapter(data);
log.info("adapter:" + adapter + ", node:" + data);
if (adapter.path("provider").asText().equals("firebase")) {
from.setDeviceType(DeviceType.PHONE_FCM);
} else if (adapter.path("provider").asText().equals("pwa")) {
from.setDeviceType(DeviceType.PHONE_PWA);
try{
SenderReceiverInfo from = new SenderReceiverInfo().builder().userID("9876543210").deviceType(DeviceType.PHONE).meta(finalMeta).build();
SenderReceiverInfo to = new SenderReceiverInfo().builder().userID("admin").build();
MessageId msgId = new MessageId().builder().channelMessageId(UUID.randomUUID().toString()).replyId("9876543210").build();
XMessagePayload payload = new XMessagePayload().builder().text(BotUtil.getBotNodeData(data, "startingMessage")).build();
JsonNode adapter = BotUtil.getBotNodeAdapter(data);
log.info("adapter:" + adapter + ", node:" + data);
if (adapter.path("provider").asText().equals("firebase")) {
from.setDeviceType(DeviceType.PHONE_FCM);
} else if (adapter.path("provider").asText().equals("pwa")) {
from.setDeviceType(DeviceType.PHONE_PWA);
}

Timestamp timestamp = new Timestamp(System.currentTimeMillis());

XMessage xmsg = new XMessage().builder()
.botId(UUID.fromString(BotUtil.getBotNodeData(data, "id")))
.app(BotUtil.getBotNodeData(data, "name"))
.adapterId(BotUtil.getBotNodeAdapterId(data))
.sessionId(BotUtil.newConversationSessionId())
.ownerId(BotUtil.getBotNodeData(data, "ownerID"))
.ownerOrgId(BotUtil.getBotNodeData(data, "ownerOrgID"))
.from(from)
.to(to)
.messageId(msgId)
.messageState(XMessage.MessageState.REPLIED)
.messageType(XMessage.MessageType.TEXT)
.payload(payload)
.providerURI(adapter.path("provider").asText())
.channelURI(adapter.path("channel").asText())
.timestamp(timestamp.getTime())
.tags(BotUtil.getBotNodeTags(data))
.build();

XMessageDAO currentMessageToBeInserted = XMessageDAOUtils.convertXMessageToDAO(xmsg);
xMsgRepo.insert(currentMessageToBeInserted)
.doOnError(genericError("Error in inserting current message"))
.doOnSuccess(xMessageDAO -> {
cassInsertCount++;
log.info("Data insert in Cassandra Count : "+cassInsertCount);
})
.subscribe(xMessageDAO -> {
sendEventToKafka(xmsg);
logTimeTaken(startTime, 0, "process-end: %d ms");
});
} catch(Exception ex) {
log.error("Inbound:CampaignController::startCampaign::Error: " + ex.getMessage());
}

Timestamp timestamp = new Timestamp(System.currentTimeMillis());

XMessage xmsg = new XMessage().builder()
.botId(UUID.fromString(BotUtil.getBotNodeData(data, "id")))
.app(BotUtil.getBotNodeData(data, "name"))
.adapterId(BotUtil.getBotNodeAdapterId(data))
.sessionId(BotUtil.newConversationSessionId())
.ownerId(BotUtil.getBotNodeData(data, "ownerID"))
.ownerOrgId(BotUtil.getBotNodeData(data, "ownerOrgID"))
.from(from)
.to(to)
.messageId(msgId)
.messageState(XMessage.MessageState.REPLIED)
.messageType(XMessage.MessageType.TEXT)
.payload(payload)
.providerURI(adapter.path("provider").asText())
.channelURI(adapter.path("channel").asText())
.timestamp(timestamp.getTime())
.tags(BotUtil.getBotNodeTags(data))
.build();

XMessageDAO currentMessageToBeInserted = XMessageDAOUtils.convertXMessageToDAO(xmsg);
xMsgRepo.insert(currentMessageToBeInserted)
.doOnError(genericError("Error in inserting current message"))
.doOnSuccess(xMessageDAO -> {
cassInsertCount++;
log.info("Data insert in Cassandra Count : "+cassInsertCount);
})
.subscribe(xMessageDAO -> {
sendEventToKafka(xmsg);
logTimeTaken(startTime, 0, "process-end: %d ms");
});
}
);
return new ResponseEntity<>("Notification Sending", HttpStatus.OK);
Expand Down
Loading

0 comments on commit ea19bce

Please sign in to comment.