Rev 3224 | Rev 11851 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.controllers;import in.shop2020.datalogger.EventType;import in.shop2020.model.v1.user.PromotionException;import in.shop2020.model.v1.user.PromotionService;import in.shop2020.model.v1.user.UserContextService;import in.shop2020.serving.interceptors.TrackingInterceptor;import in.shop2020.thrift.clients.PromotionClient;import in.shop2020.thrift.clients.UserClient;import in.shop2020.utils.DataLogger;import org.apache.log4j.Logger;import org.apache.struts2.convention.annotation.InterceptorRef;import org.apache.struts2.convention.annotation.InterceptorRefs;import org.apache.struts2.convention.annotation.Result;import org.apache.struts2.convention.annotation.Results;@SuppressWarnings("serial")@InterceptorRefs({@InterceptorRef("myDefault")})@Results({@Result(name = "redirect", type = "redirectAction", params = {"actionName" , "cart"})})public class PromotionController extends BaseController {public PromotionController() {super();}private static Logger log = Logger.getLogger(Class.class);public String create() {String action = request.getParameter("action");log.info("Action is: " + action);UserClient userServiceClient = null;PromotionClient promotionServiceClient = null;try {long cartId = userinfo.getCartId();if(action == null || action.isEmpty()) {addActionError("Invalid Request Action");return "redirect";}String couponCode = request.getParameter("coupon_code");if (action.equalsIgnoreCase("applycoupon")) {if (couponCode == null || couponCode.isEmpty()) {addActionError("Coupon Code field cannot be left empty");return "redirect";}boolean qualifiesForCoupon = true;if(couponCode.equalsIgnoreCase("SGalaxy")) {if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());//TODO: Affiliate based qualification should be inside serviceif (affId != 5) { //For MySmartPricequalifiesForCoupon = false;}} else {qualifiesForCoupon = false;}}if(qualifiesForCoupon) {promotionServiceClient = new PromotionClient();PromotionService.Client promotionClient = promotionServiceClient.getClient();promotionClient.applyCoupon(couponCode, cartId);DataLogger.logData(EventType.COUPON_APPLIED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), couponCode);} else {addActionError("You are not eligible for this coupon");}}else if (action.equals("removecoupon")) {userServiceClient = new UserClient();UserContextService.Client userClient = userServiceClient.getClient();userClient.removeCoupon(cartId);DataLogger.logData(EventType.COUPON_REMOVED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), couponCode);}} catch (PromotionException e) {log.info("Invalid coupon: " + e.getMessage());addActionError(e.getMessage());} catch (Exception e) {log.error("Unable to apply or remove coupon", e);}return "redirect";}}