Skip to content

Commit

Permalink
Release 1.1.0 (#19)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
manzarul authored Nov 15, 2019
1 parent a510fc0 commit 8db928f
Show file tree
Hide file tree
Showing 60 changed files with 2,625 additions and 607 deletions.
19 changes: 18 additions & 1 deletion all-actors/src/main/java/org/sunbird/NotificationValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.sunbird.message.IResponseMessage;
import org.sunbird.message.IUserResponseMessage;
import org.sunbird.message.ResponseCode;
import org.sunbird.pojo.NotificationMode;
import org.sunbird.pojo.NotificationRequest;

/** Validates send notification api request */
public class NotificationValidator {
private static final int MAX_NOTIFICATION_SIZE = 1000;

public static void validate(NotificationRequest notificationRequest) throws BaseException {
validateModeType(notificationRequest.getMode());
validateIds(notificationRequest.getIds());
// in case of topic based notification id not required.
if (StringUtils.isBlank(
notificationRequest.getConfig() != null
? notificationRequest.getConfig().getTopic()
: "")) {
validateIds(notificationRequest.getIds());
}
// for checking mandatory params of string type
checkMandatoryParamsPresent(notificationRequest.getDeliveryType(), JsonKey.DELIVERY_TYPE);
}
Expand Down Expand Up @@ -66,4 +74,13 @@ private static void validateIds(List<String> ids) throws BaseException {
ResponseCode.CLIENT_ERROR.getCode());
}
}

public static void validateMaxSupportedIds(List<String> ids) throws BaseException {
if (ids.size() > MAX_NOTIFICATION_SIZE) {
throw new BaseException(
IUserResponseMessage.INVALID_REQUESTED_DATA,
MessageFormat.format(IResponseMessage.MAX_NOTIFICATION_SIZE, MAX_NOTIFICATION_SIZE),
ResponseCode.CLIENT_ERROR.getCode());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
package org.sunbird.notification.actor;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
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;
import org.sunbird.JsonKey;
import org.sunbird.NotificationRequestMapper;
import org.sunbird.NotificationValidator;
import org.sunbird.actor.core.ActorConfig;
import org.sunbird.message.IResponseMessage;
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.FCMResponse;
import org.sunbird.notification.utils.NotificationConstant;
import org.sunbird.pojo.NotificationRequest;
import org.sunbird.request.Request;
import org.sunbird.response.Response;
import org.sunbird.util.Constant;
import org.sunbird.util.validator.OtpRequestValidator;

/** @author manzarul */
@ActorConfig(
tasks = {JsonKey.NOTIFICATION},
tasks = {JsonKey.NOTIFICATION, JsonKey.VERIFY_OTP},
asyncTasks = {}
)
public class NotificationActor extends BaseActor {
Expand All @@ -33,27 +43,64 @@ public void onReceive(Request request) throws Throwable {
String operation = request.getOperation();
if (NOTIFICATION.equalsIgnoreCase(operation)) {
notify(request);
} else if (JsonKey.VERIFY_OTP.equalsIgnoreCase(operation)) {
verifyOtp(request);

} else {
onReceiveUnsupportedMessage(request.getOperation());
}

logger.info("onReceive method call End");
}

public void notify(Request request) throws BaseException {
boolean isSyncDelivery = false;
logger.info("Call started for notify method");
List<NotificationRequest> notificationRequestList =
NotificationRequestMapper.toList(
(List<Map<String, Object>>) request.getRequest().get(JsonKey.NOTIFICATIONS));
List<String> ids = new ArrayList<String>();
for (NotificationRequest notificationRequest : notificationRequestList) {
if (CollectionUtils.isNotEmpty(notificationRequest.getIds())) {
ids.addAll(notificationRequest.getIds());
}
NotificationValidator.validate(notificationRequest);
}
Map<String, Object> requestMap = request.getRequest();
List<FCMResponse> responses = null;
Response response = new Response();
responses = Dispatcher.dispatch(requestMap, false);
response.getResult().put(Constant.RESPONSE, responses);
logger.info("response got from notification service " + responses);
NotificationValidator.validateMaxSupportedIds(ids);
NotificationRouter routes = new NotificationRouter();
String deliveryMode = request.getManagerName();
if (StringUtils.isNotBlank(deliveryMode) && "sync".equalsIgnoreCase(deliveryMode)) {
isSyncDelivery = true;
}
Response response = routes.route(notificationRequestList, false, isSyncDelivery);
logger.info("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");
Map<String, Object> requestMap = request.getRequest();
boolean response =
OtpRequestValidator.isOtpVerifyRequestValid(
(String) requestMap.get(NotificationConstant.KEY),
(String) request.get(NotificationConstant.VALUE));
if (!response) {
throw new ActorServiceException.InvalidRequestData(
IUserResponseMessage.INVALID_REQUESTED_DATA,
MessageFormat.format(
IResponseMessage.INVALID_REQUESTED_DATA, NotificationConstant.VERIFY_OTP),
ResponseCode.CLIENT_ERROR.getCode());
}
NotificationRouter routes = new NotificationRouter();
OTPRequest otpRequest =
new OTPRequest(
(String) requestMap.get(NotificationConstant.KEY),
null,
0,
0,
null,
(String) request.get(NotificationConstant.VALUE));
Response responseData = routes.verifyOtp(otpRequest);
logger.info("response got from notification service " + response);
sender().tell(responseData, getSelf());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/** */
package org.sunbird.notification.dispatcher;

import java.util.List;
import java.util.Map;
import org.sunbird.notification.utils.FCMResponse;
import org.sunbird.pojo.NotificationRequest;

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

public List<FCMResponse> dispatch(Map<String, Object> data, boolean isDryRun);
public FCMResponse dispatch(NotificationRequest data, boolean isDryRun, boolean isSync);
}
Loading

0 comments on commit 8db928f

Please sign in to comment.