Skip to content

Commit

Permalink
Sb 22307, SB-22290, SB-22289 Fix (#53)
Browse files Browse the repository at this point in the history
* Release 1.1.0 (#19)

* Sb 14975 (#14)

* Issue #SC-1336 configuration changes for making controller test cases to run

* Issue #SC-1336 removed sysouts

* Issue #SC-1336 renamed method names

* Issue #SB-14975 fix: adding for sending otp

* issue #SB-14975 fix: changes for sending otp and sms

* Issue #SB-15032 fix: adding for otp verification only for phone

* Sb 15139 (#15)

* Issue #SC-1336 configuration changes for making controller test cases to run

* Issue #SC-1336 removed sysouts

* Issue #SC-1336 renamed method names

* Issue #SB-14975 fix: adding for sending otp

* issue #SB-14975 fix: changes for sending otp and sms

* Issue #SB-15032 fix: adding for otp verification only for phone

* Issue #SB-15139 feat: adding capability to send email using pre-define vm or pass your own data

* issue #SB-15139 fix: adding factory method for email service

* issue #SB-15139 fix: changes for validation of 1000 ids support and spliting some methods

* issue #SB-15139 fix: chnages based on code review comment

* issue SB-10684 fix: chnages for supporting topic based notification and refactor code for sending email notification

* Issue #SB-15139 fix changes for sync call

* Issue #SB-15139 fix: chnages for sync api

* Issue #SB-15312 iteration field value changes for notification pojo (#16)

* Sb 15312 iteration should be set to 1 by default (#17)

* Issue #SB-15312 iteration field value changes for notification pojo

* Issue #SB-15312 interation should be set to 1 by default

* Issue #SB-15312 interation should be set to 1 by default

* Issue #00 feat: integrating circeci

* Issue #00 feat: integrating circeci

* SC-1488  (#21) Add jacoco plugin

* Issue#SC-1488 ADDED JOCOCO PLUGINS

* Issue#SC-1488 ADDED JOCOC IN PARENT

* Issue#SC-1488 ADDED JOCOC IN PARENT

* Issue#SC-1488 ADDED JOCOC IN PARENT

* SC-1488 (#22)

* Issue#SC-1488 ADDED JOCOCO PLUGINS

* Issue#SC-1488 ADDED JOCOC IN PARENT

* Issue#SC-1488 ADDED JOCOC IN PARENT

* Issue#SC-1488 ADDED JOCOC IN PARENT

* Issue#SC-1488 added module path for notification-sdk in .circleci/config.yml

* Sb 18906 merging mater with release-1.1.0 (#41)

* Sb 14975 (#14)

* Issue #SC-1336 configuration changes for making controller test cases to run

* Issue #SC-1336 removed sysouts

* Issue #SC-1336 renamed method names

* Issue #SB-14975 fix: adding for sending otp

* issue #SB-14975 fix: changes for sending otp and sms

* Issue #SB-15032 fix: adding for otp verification only for phone

* Sb 15139 (#15)

* Issue #SC-1336 configuration changes for making controller test cases to run

* Issue #SC-1336 removed sysouts

* Issue #SC-1336 renamed method names

* Issue #SB-14975 fix: adding for sending otp

* issue #SB-14975 fix: changes for sending otp and sms

* Issue #SB-15032 fix: adding for otp verification only for phone

* Issue #SB-15139 feat: adding capability to send email using pre-define vm or pass your own data

* issue #SB-15139 fix: adding factory method for email service

* issue #SB-15139 fix: changes for validation of 1000 ids support and spliting some methods

* issue #SB-15139 fix: chnages based on code review comment

* issue SB-10684 fix: chnages for supporting topic based notification and refactor code for sending email notification

* Issue #SB-15139 fix changes for sync call

* Issue #SB-15139 fix: chnages for sync api

* Issue #SB-15312 iteration field value changes for notification pojo (#16)

* Sb 15312 iteration should be set to 1 by default (#17)

* Issue #SB-15312 iteration field value changes for notification pojo

* Issue #SB-15312 interation should be set to 1 by default

* Issue #SB-15312 interation should be set to 1 by default

* Issue #00 fix: circleci for 1.12

* SB-16579 (#24)

* async method call executed

* circleci file added

* test case resolved and code is async

* SC-1626 (#28)

* logs configured

* logs configured

* Create auto_build_deploy

* Update auto_build_deploy

* Update auto_build_deploy

Co-authored-by: manzarul Haque <[email protected]>
Co-authored-by: harshavardhanc <[email protected]>
Co-authored-by: amorphous-1 <[email protected]>
Co-authored-by: Anmol Gupta <[email protected]>
Co-authored-by: G33tha <[email protected]>

* Issue #SC-2173 feat: upgrade to jdk 11

* Issue #SC-2173 feat: upgrade to jdk 11

* Issue #SC-2173 feat: upgrade to jdk 11

* Issue #SC-2173 feat: upgrade to jdk 11

* Issue #SC-2173 feat: upgrade to jdk 11

* Issue #SB-22307 feat: fix for propagation of traceid

* Issue #SB-22307 feat: fix for propagation of traceid

* Issue #SB-22307 feat: fix for propagation of traceid

* Issue #SB-22307 feat: fix for propagation of traceid

* Issue #SB-22307 feat:added traceid in all methods

* Issue #SB-22307 feat: fix for propagation of traceid

Co-authored-by: manzarul Haque <[email protected]>
Co-authored-by: harshavardhanc <[email protected]>
Co-authored-by: amorphous-1 <[email protected]>
Co-authored-by: Anmol Gupta <[email protected]>
Co-authored-by: Hari-stackroute <[email protected]>
Co-authored-by: G33tha <[email protected]>
  • Loading branch information
7 people authored Feb 3, 2021
1 parent a3fc1ca commit 386093a
Show file tree
Hide file tree
Showing 48 changed files with 1,112 additions and 637 deletions.
10 changes: 5 additions & 5 deletions all-actors/src/main/java/org/sunbird/BaseActor.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.sunbird;

import akka.actor.UntypedAbstractActor;
import org.apache.log4j.Logger;
import org.sunbird.message.IResponseMessage;
import org.sunbird.message.Localizer;
import org.sunbird.message.ResponseCode;
import org.sunbird.request.LoggerUtil;
import org.sunbird.request.Request;

import java.util.Locale;
Expand All @@ -14,7 +14,7 @@
*/
public abstract class BaseActor extends UntypedAbstractActor {

private Logger logger = Logger.getLogger(BaseActor.class);
private static LoggerUtil logger = new LoggerUtil(BaseActor.class);
public abstract void onReceive(Request request) throws Throwable;
protected Localizer localizer = Localizer.getInstance();

Expand All @@ -23,11 +23,11 @@ public void onReceive(Object message) throws Throwable {
if (message instanceof Request) {
Request request = (Request) message;
String operation = request.getOperation();
logger.info("BaseActor:onReceive called for operation:" + operation);
logger.info(request.getRequestContext(),"BaseActor:onReceive called for operation:" + operation);
try {
logger.info(String.format("%s:%s:method started at %s",this.getClass().getSimpleName(),operation,System.currentTimeMillis()));
logger.info(request.getRequestContext(),String.format("%s:%s:method started at %s",this.getClass().getSimpleName(),operation,System.currentTimeMillis()));
onReceive(request);
logger.info(String.format("%s:%s:method ended at %s",this.getClass().getSimpleName(),operation,System.currentTimeMillis()));
logger.info(request.getRequestContext(),String.format("%s:%s:method ended at %s",this.getClass().getSimpleName(),operation,System.currentTimeMillis()));
} catch (Exception e) {
onReceiveException(operation, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.sunbird.message.IResponseMessage;
import org.sunbird.message.ResponseCode;
import org.sunbird.pojo.NotificationRequest;
import org.sunbird.request.LoggerUtil;

public class NotificationRequestMapper {

private static ObjectMapper mapper = new ObjectMapper();

private static Logger logger = LogManager.getLogger(NotificationRequestMapper.class);
private static LoggerUtil logger = new LoggerUtil(NotificationRequestMapper.class);

/**
* maps request to notification request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.sunbird.ActorServiceException;
import org.sunbird.BaseActor;
import org.sunbird.BaseException;
Expand All @@ -19,11 +17,10 @@
import org.sunbird.message.IUserResponseMessage;
import org.sunbird.message.ResponseCode;
import org.sunbird.notification.beans.OTPRequest;
import org.sunbird.notification.dispatcher.INotificationDispatcher;
import org.sunbird.notification.dispatcher.NotificationRouter;
import org.sunbird.notification.dispatcher.impl.FCMNotificationDispatcher;
import org.sunbird.notification.utils.NotificationConstant;
import org.sunbird.pojo.NotificationRequest;
import org.sunbird.request.LoggerUtil;
import org.sunbird.request.Request;
import org.sunbird.response.Response;
import org.sunbird.util.validator.OtpRequestValidator;
Expand All @@ -35,7 +32,7 @@
dispatcher= "notification-dispatcher"
)
public class NotificationActor extends BaseActor {
Logger logger = LogManager.getLogger(NotificationActor.class);
private static LoggerUtil logger = new LoggerUtil(NotificationActor.class);

@Override
public void onReceive(Request request) throws Throwable {
Expand All @@ -48,12 +45,12 @@ public void onReceive(Request request) throws Throwable {
} else {
onReceiveUnsupportedMessage(request.getOperation());
}
logger.info("onReceive method call End");
logger.info(request.getRequestContext(),"onReceive method call End");
}

public void notify(Request request) throws BaseException {
boolean isSyncDelivery = false;
logger.info("Call started for notify method");
logger.info(request.getRequestContext(),"Call started for notify method");
List<NotificationRequest> notificationRequestList =
NotificationRequestMapper.toList(
(List<Map<String, Object>>) request.getRequest().get(JsonKey.NOTIFICATIONS));
Expand All @@ -70,13 +67,13 @@ public void notify(Request request) throws BaseException {
if (StringUtils.isNotBlank(deliveryMode) && "sync".equalsIgnoreCase(deliveryMode)) {
isSyncDelivery = true;
}
Response response = routes.route(notificationRequestList, false, isSyncDelivery);
logger.info("response got from notification service " + response);
Response response = routes.route(notificationRequestList, false, isSyncDelivery, request.getRequestContext());
logger.info(request.getRequestContext(),"response got from notification service " + response);
sender().tell(response, getSelf());
}

public void verifyOtp(Request request) throws BaseException {
logger.info("call started for verify otp method");
logger.info(request.getRequestContext(),"call started for verify otp method");
Map<String, Object> requestMap = request.getRequest();
boolean response =
OtpRequestValidator.isOtpVerifyRequestValid(
Expand All @@ -98,8 +95,8 @@ public void verifyOtp(Request request) throws BaseException {
0,
null,
(String) request.get(NotificationConstant.VALUE));
Response responseData = routes.verifyOtp(otpRequest);
logger.info("response got from notification service " + response);
Response responseData = routes.verifyOtp(otpRequest, request.getRequestContext());
logger.info(request.getRequestContext(),"response got from notification service " + response);
sender().tell(responseData, getSelf());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import org.sunbird.notification.utils.FCMResponse;
import org.sunbird.pojo.NotificationRequest;
import org.sunbird.request.RequestContext;

/**
* This interface is responsible for handling different mode of notification
Expand All @@ -11,5 +12,5 @@
*/
public interface INotificationDispatcher {

public FCMResponse dispatch(NotificationRequest data, boolean isDryRun, boolean isSync);
public FCMResponse dispatch(NotificationRequest data, boolean isDryRun, boolean isSync, RequestContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import java.util.Properties;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
Expand All @@ -31,12 +29,13 @@
import org.sunbird.notification.dispatcher.impl.FCMNotificationDispatcher;
import org.sunbird.notification.sms.provider.ISmsProvider;
import org.sunbird.notification.sms.providerimpl.Msg91SmsProviderFactory;
import org.sunbird.notification.utils.FCMResponse;
import org.sunbird.notification.utils.NotificationConstant;
import org.sunbird.notification.utils.Util;
import org.sunbird.pojo.Config;
import org.sunbird.pojo.NotificationRequest;
import org.sunbird.pojo.OTP;
import org.sunbird.request.LoggerUtil;
import org.sunbird.request.RequestContext;
import org.sunbird.response.Response;
import org.sunbird.util.Constant;

Expand All @@ -45,10 +44,11 @@
* @author manzarul
*/
public class NotificationRouter {
private static Logger logger = LogManager.getLogger(NotificationRouter.class);
private static LoggerUtil logger = new LoggerUtil(NotificationRouter.class);
private static final String TEMPLATE_SUFFIX = ".vm";
private SyncMessageDispatcher syDispatcher = new SyncMessageDispatcher();
private ObjectMapper mapper = new ObjectMapper();

enum DeliveryMode {
phone,
email,
Expand All @@ -74,42 +74,42 @@ private ISmsProvider getSMSInstance() {
}

public Response route(
List<NotificationRequest> notificationRequestList, boolean isDryRun, boolean isSync)
List<NotificationRequest> notificationRequestList, boolean isDryRun, boolean isSync, RequestContext context)
throws BaseException {
logger.info("making call to route method");
logger.info(context, "making call to route method");
Response response = new Response();
if (CollectionUtils.isNotEmpty(notificationRequestList)) {
Map<String, Object> responseMap = new HashMap<String, Object>();
for (NotificationRequest notification : notificationRequestList) {
if (notification.getMode().equalsIgnoreCase(DeliveryMode.phone.name())
&& (notification.getDeliveryType().equalsIgnoreCase(DeliveryType.message.name())
|| notification.getDeliveryType().equalsIgnoreCase(DeliveryType.otp.name()))) {
response = handleMessageAndOTP(notification, isDryRun, responseMap, isSync);
response = handleMessageAndOTP(notification, isDryRun, responseMap, isSync, context);
} else if (notification.getMode().equalsIgnoreCase(DeliveryMode.device.name())) {
response = writeDataToKafka(notification, response, isDryRun, responseMap, isSync);
response = writeDataToKafka(notification, response, isDryRun, responseMap, isSync, context);
} else if (notification.getMode().equalsIgnoreCase(DeliveryMode.email.name())
&& notification.getDeliveryType().equalsIgnoreCase(DeliveryType.message.name())) {
String message = null;
if (notification.getTemplate() != null
&& StringUtils.isNotBlank(notification.getTemplate().getData())) {
message =
getMessage(
notification.getTemplate().getData(), notification.getTemplate().getParams());
notification.getTemplate().getData(), notification.getTemplate().getParams(), context);
notification.getTemplate().setData(message);
} else if (notification.getTemplate() != null
&& StringUtils.isNotBlank(notification.getTemplate().getId())) {
String data = createNotificationBody(notification);
String data = createNotificationBody(notification, context);
notification.getTemplate().setData(data);
}
if (isSync) {
response = syDispatcher.syncDispatch(notification, isDryRun);
response = syDispatcher.syncDispatch(notification, isDryRun, context);
} else {
response = writeDataToKafka(notification, response, isDryRun, responseMap, isSync);
response = writeDataToKafka(notification, response, isDryRun, responseMap, isSync, context);
}
}
}
} else {
logger.info(
logger.info(context,
"requested notification list is either null or empty :" + notificationRequestList);
}
return response;
Expand All @@ -119,14 +119,15 @@ private Response handleMessageAndOTP(
NotificationRequest notification,
boolean isDryRun,
Map<String, Object> responseMap,
boolean isSync)
boolean isSync,
RequestContext context)
throws BaseException {
Response response = new Response();
String message = null;
if (notification.getTemplate() != null
&& StringUtils.isNotBlank(notification.getTemplate().getData())) {
message =
getMessage(notification.getTemplate().getData(), notification.getTemplate().getParams());
getMessage(notification.getTemplate().getData(), notification.getTemplate().getParams(), context);
}

Config config = notification.getConfig();
Expand All @@ -143,28 +144,28 @@ private Response handleMessageAndOTP(
}
OTPRequest request =
new OTPRequest(ids.get(0), null, otp.getLength(), otp.getExpiryInMinute(), message, null);
boolean smsResponse = getSMSInstance().sendOtp(request);
boolean smsResponse = getSMSInstance().sendOtp(request, context);
responseMap.put(ids.get(0), smsResponse);
response.putAll(responseMap);
} else {
if (notification.getTemplate() != null) {
notification.getTemplate().setData(message);
}
if (isSync) {
response = syDispatcher.syncDispatch(notification, isDryRun);
response = syDispatcher.syncDispatch(notification, isDryRun, context);

} else {
response = writeDataToKafka(notification, response, isDryRun, responseMap, isSync);
response = writeDataToKafka(notification, response, isDryRun, responseMap, isSync, context);
}
}
return response;
}

private String createNotificationBody(NotificationRequest notification) throws BaseException {
return readVm(notification.getTemplate().getId(), notification.getTemplate().getParams());
private String createNotificationBody(NotificationRequest notification, RequestContext context) throws BaseException {
return readVm(notification.getTemplate().getId(), notification.getTemplate().getParams(), context);
}

private String readVm(String templateName, JsonNode node) throws BaseException {
private String readVm(String templateName, JsonNode node, RequestContext requestContext) throws BaseException {
VelocityEngine engine = new VelocityEngine();
VelocityContext context = getContextObj(node);
Properties p = new Properties();
Expand All @@ -181,7 +182,7 @@ private String readVm(String templateName, JsonNode node) throws BaseException {
template.merge(context, writer);
body = writer.toString();
} catch (Exception e) {
logger.error("Failed to load velocity template =" + templateName + " " + e.getMessage(), e);
logger.error(requestContext,"Failed to load velocity template =" + templateName + " " + e.getMessage(), e);
throw new ActorServiceException.InvalidRequestData(
IUserResponseMessage.TEMPLATE_NOT_FOUND,
MessageFormat.format(
Expand All @@ -193,15 +194,15 @@ private String readVm(String templateName, JsonNode node) throws BaseException {
try {
writer.close();
} catch (IOException e) {
logger.error("Failed to closed writer object =" + e.getMessage(), e);
logger.error(requestContext,"Failed to closed writer object =" + e.getMessage(), e);
}
}
}
return body;
}

public Response verifyOtp(OTPRequest otpRequest) {
boolean verificationResp = getSMSInstance().verifyOtp(otpRequest);
public Response verifyOtp(OTPRequest otpRequest, RequestContext context) {
boolean verificationResp = getSMSInstance().verifyOtp(otpRequest, context);
Response response = new Response();
if (verificationResp) {
response.put(NotificationConstant.MESSAGE, NotificationConstant.SUCCESS);
Expand All @@ -216,15 +217,16 @@ private Response writeDataToKafka(
Response response,
boolean isDryRun,
Map<String, Object> responseMap,
boolean isSync) {
FCMNotificationDispatcher.getInstance().dispatch(notification, isDryRun, isSync);
logger.info("Got response from FCM ");
boolean isSync,
RequestContext context) {
FCMNotificationDispatcher.getInstance().dispatch(notification, isDryRun, isSync, context);
logger.info(context, "Got response from FCM ");
responseMap.put(Constant.RESPONSE, NotificationConstant.SUCCESS);
response.putAll(responseMap);
return response;
}

private String getMessage(String message, JsonNode node) {
private String getMessage(String message, JsonNode node, RequestContext requestContext) {
VelocityContext context = new VelocityContext();
if (node != null) {
Map<String, String> paramValue = mapper.convertValue(node, Map.class);
Expand All @@ -242,7 +244,7 @@ private String getMessage(String message, JsonNode node) {
writer = new StringWriter();
Velocity.evaluate(context, writer, "SimpleVelocity", message);
} catch (Exception e) {
logger.error(
logger.error(requestContext,
"NotificationRouter:getMessage : Exception occurred with message =" + e.getMessage(), e);
}
return writer.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.sunbird.notification.sms.provider.ISmsProvider;
import org.sunbird.notification.sms.providerimpl.Msg91SmsProviderFactory;
import org.sunbird.pojo.NotificationRequest;
import org.sunbird.request.RequestContext;
import org.sunbird.response.Response;
import org.sunbird.util.Constant;

Expand All @@ -20,16 +21,16 @@ public class SyncMessageDispatcher {
private IEmailService emailservice;
private ISmsProvider smsProvider;

public Response syncDispatch(NotificationRequest notification, boolean isDryRun) {
public Response syncDispatch(NotificationRequest notification, boolean isDryRun, RequestContext context) {
if (notification.getMode().equalsIgnoreCase(DeliveryMode.phone.name())
&& notification.getDeliveryType().equalsIgnoreCase(DeliveryType.message.name())) {
return syncMessageDispatch(notification, isDryRun);
return syncMessageDispatch(notification, isDryRun, context);
}

return syncEmailDispatch(notification, isDryRun);
return syncEmailDispatch(notification, isDryRun, context);
}

private Response syncEmailDispatch(NotificationRequest notificationRequest, boolean isDryRun) {
private Response syncEmailDispatch(NotificationRequest notificationRequest, boolean isDryRun, RequestContext context) {
EmailRequest request =
new EmailRequest(
notificationRequest.getConfig().getSubject(),
Expand All @@ -39,17 +40,17 @@ private Response syncEmailDispatch(NotificationRequest notificationRequest, bool
null,
notificationRequest.getTemplate().getData(),
null);
boolean emailResponse = getEmailInstance().sendEmail(request);
boolean emailResponse = getEmailInstance().sendEmail(request, context);
Response response = new Response();
response.put(Constant.RESPONSE, emailResponse);
return response;
}

private Response syncMessageDispatch(NotificationRequest notificationRequest, boolean isDryRun) {
private Response syncMessageDispatch(NotificationRequest notificationRequest, boolean isDryRun, RequestContext context) {
Response response = new Response();
boolean smsResponse =
getSmsInstance()
.bulkSms(notificationRequest.getIds(), notificationRequest.getTemplate().getData());
.bulkSms(notificationRequest.getIds(), notificationRequest.getTemplate().getData(), context);
response.put(Constant.RESPONSE, smsResponse);
return response;
}
Expand Down
Loading

0 comments on commit 386093a

Please sign in to comment.