Skip to content

Commit

Permalink
Merge pull request #2 from samagra-comms/release-4.1.0
Browse files Browse the repository at this point in the history
Release 4.1.0
  • Loading branch information
ChakshuGautam authored Jul 14, 2021
2 parents 7bbb864 + 7b73b1f commit 44badc9
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 22 deletions.
37 changes: 37 additions & 0 deletions build/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
node('build-slave') {
try {
String ANSI_GREEN = "\u001B[32m"
String ANSI_NORMAL = "\u001B[0m"
String ANSI_BOLD = "\u001B[1m"
String ANSI_RED = "\u001B[31m"
String ANSI_YELLOW = "\u001B[33m"

ansiColor('xterm') {
withEnv(["JAVA_HOME=${JAVA11_HOME}"]) {
stage('Checkout') {
if (!env.hub_org) {
println(ANSI_BOLD + ANSI_RED + "Uh Oh! Please set a Jenkins environment variable named hub_org with value as registery/sunbidrded" + ANSI_NORMAL)
error 'Please resolve the errors and rerun..'
} else
println(ANSI_BOLD + ANSI_GREEN + "Found environment variable named hub_org with value as: " + hub_org + ANSI_NORMAL)
}

cleanWs()
checkout scm
commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
build_tag = sh(script: "echo " + params.github_release_tag.split('/')[-1] + "_" + commit_hash + "_" + env.BUILD_NUMBER, returnStdout: true).trim()
echo "build_tag: " + build_tag

stage('Build') {
env.NODE_ENV = "build"
print "Environment will be : ${env.NODE_ENV}"
sh 'mvn clean install -DskipTests=true '
}
}
}
}
catch (err) {
currentBuild.result = "FAILURE"
throw err
}
}
24 changes: 16 additions & 8 deletions src/main/java/com/uci/dao/Application.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.uci.dao;

import com.datastax.driver.core.utils.UUIDs;
import com.uci.dao.models.XMessageDAO;
import com.uci.dao.repository.XMessageRepository;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -14,6 +15,8 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.function.Consumer;

/**
* @author chakshu
Expand All @@ -36,18 +39,23 @@ public static void main(String[] args) {

@Override
public void run(String... args) throws Exception {

xMessageRepository.insert(new XMessageDAO(new Long(121313), "HHBJ", "hkkh", "efef", "grdgrdg", LocalDateTime.now(),
for(int i=0; i<1000; i++){
log.info(UUIDs.timeBased().toString());
}
xMessageRepository.insert(new XMessageDAO(UUIDs.timeBased(), "HHBJ", "hkkh", "efef", "grdgrdg", LocalDateTime.now(),
"HHBJ", "hkkh", "efef", "grdgrdg", "HHBJ", "hkkh", "efef")).log().subscribe();
xMessageRepository.insert(new XMessageDAO(new Long(1213134), "HHB", "hkkh", "efef", "grdgrdg", LocalDateTime.now(),
xMessageRepository.insert(new XMessageDAO(UUIDs.timeBased(), "HHB", "hkkh", "efef", "grdgrdg", LocalDateTime.now(),
"HHBJ", "hkkh", "efef", "grdgrdg", "HHBJ", "hkkh", "efef")).log().subscribe();
LocalDateTime yesterday = LocalDateTime.now().minusDays(1L);
xMessageRepository.findAllByUserIdAndTimestampAfter("HHBJ", yesterday).subscribe(xMessageDAO -> {
log.info("XMessage List Item :>> " + counter + " " + xMessageDAO.getMessageId() + " " + xMessageDAO.getTimestamp());
counter += 1;
xMessageRepository.findAllByUserId("7837833100").subscribe(new Consumer<List<XMessageDAO>>() {
@Override
public void accept(List<XMessageDAO> xMessageDAO) {
log.info("XMessage List Item All :>> " + counter + " " + xMessageDAO.get(counter).getApp());
counter += 1;
}
});
xMessageRepository.findAllByUserIdAndTimestampAfter("HHBJ",yesterday).subscribe(xMessageDAO -> {
log.info("XMessage List Item :>> " + counter + " " + xMessageDAO.getMessageId() + " " + xMessageDAO.getTimestamp());
xMessageRepository.findAllByFromIdAndTimestampAfter("hkkh",yesterday).subscribe(xMessageDAO -> {
log.info("XMessage List Item :>> " + counter + " " + xMessageDAO.getFromId() + " " + xMessageDAO.getTimestamp());
counter += 1;
});
}
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/uci/dao/config/CassandraConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,13 @@ protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
return Collections.singletonList(specification);
}

// @Override
// protected List<DropKeyspaceSpecification> getKeyspaceDrops() {
// return Collections.singletonList(DropKeyspaceSpecification.dropKeyspace(keyspace));
// }


@Override
protected List<String> getStartupScripts() {
List<String> scripts = new ArrayList<>();
scripts.add("CREATE TABLE IF NOT EXISTS " +
keyspace + ".XMessage(id bigint," +
keyspace + ".XMessage(id uuid," +
"userId text, " +
"fromId text, " +
"channel text, " +
Expand All @@ -88,7 +85,7 @@ protected List<String> getStartupScripts() {
"messageId text, " +
"replyId text, " +
"causeId text, " +
"PRIMARY KEY ((userId), timestamp)) " +
"PRIMARY KEY ((userId,fromId), timestamp)) " +
"WITH CLUSTERING ORDER BY (timestamp DESC)");
// scripts.add("CREATE INDEX IF NOT EXISTS message_state_index\n" +
// "ON "+keyspace
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/uci/dao/models/XMessageDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.data.cassandra.core.mapping.Table;

import java.time.LocalDateTime;
import java.util.UUID;

import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.CLUSTERED;
import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.PARTITIONED;
Expand All @@ -21,11 +22,11 @@
@Table("XMessage")
public class XMessageDAO {
@Column
private Long id;
private UUID id;

@PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED)
private String userId;
@Column
@PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED)
private String fromId;
@Column
private String channel;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/uci/dao/repository/XMessageRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public interface XMessageRepository extends ReactiveCassandraRepository<XMessage

Flux<XMessageDAO> findTopByUserIdOrderByTimestampDesc(String userId);

Flux<List<XMessageDAO>> findAllByFromIdAndMessageStateOrderByTimestamp(String userID, String messageState);
@AllowFiltering
Flux<XMessageDAO> findAllByFromIdAndTimestampAfter(String userID, LocalDateTime timestamp);
}


13 changes: 9 additions & 4 deletions src/main/java/com/uci/dao/utils/XMessageDAOUtills.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.uci.dao.utils;


import com.datastax.driver.core.utils.UUIDs;
import com.uci.dao.models.XMessageDAO;
import messagerosa.core.model.XMessage;

import javax.xml.bind.JAXBException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.TimeZone;
Expand All @@ -13,7 +15,6 @@ public class XMessageDAOUtills {
public static XMessageDAO convertXMessageToDAO(XMessage xmsg) {
XMessageDAO xmsgDao = new XMessageDAO();


try {
xmsgDao.setUserId(xmsg.getTo().getUserID());
if (xmsg.getTo().getUserID().equals("Bulk")) {
Expand All @@ -34,19 +35,22 @@ public static XMessageDAO convertXMessageToDAO(XMessage xmsg) {
// Bulk SMS so no replyID
}

try {
xmsgDao.setXMessage(xmsg.toXML());
} catch (JAXBException e) {
e.printStackTrace();
}

xmsgDao.setFromId(xmsg.getFrom().getUserID());

xmsgDao.setChannel(xmsg.getChannelURI());
xmsgDao.setProvider(xmsg.getProviderURI());

xmsgDao.setXMessage(xmsg.getPayload().getText());

LocalDateTime triggerTime =
LocalDateTime.ofInstant(Instant.ofEpochMilli(xmsg.getTimestamp()),
TimeZone.getDefault().toZoneId());

xmsgDao.setTimestamp(LocalDateTime.from(triggerTime));
xmsgDao.setId(UUIDs.timeBased());

if (xmsg.getMessageState() != null) {
xmsgDao.setMessageState(xmsg.getMessageState().name());
Expand All @@ -55,4 +59,5 @@ public static XMessageDAO convertXMessageToDAO(XMessage xmsg) {
xmsgDao.setApp(xmsg.getApp());
return xmsgDao;
}

}
2 changes: 1 addition & 1 deletion src/main/resources/dao-application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cassandra.contactpoints=127.0.0.1
cassandra.contactpoints=homeserver
cassandra.port=9042
cassandra.keyspace=testKeyspace
logging.level.root=INFO

0 comments on commit 44badc9

Please sign in to comment.