Rev 20110 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.controllers;import in.shop2020.crm.TicketCategory;import in.shop2020.model.v1.order.LineItem;import in.shop2020.model.v1.order.OrderStatus;import in.shop2020.model.v1.order.RechargeType;import in.shop2020.model.v1.order.ReturnTransactionStatus;import in.shop2020.model.v1.order.ReturnTxnPickupStatus;import in.shop2020.serving.auth.CRMAuthorizingRealm;import in.shop2020.thrift.clients.TransactionClient;import in.shop2020.util.CRMConstants;import in.shop2020.util.CRMConstants.CODCancelMatrix;import in.shop2020.utils.ModelUtils;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Arrays;import java.util.Date;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.log4j.Logger;import org.apache.shiro.SecurityUtils;import org.apache.struts2.interceptor.ServletRequestAware;import org.apache.struts2.interceptor.ServletResponseAware;import org.apache.struts2.interceptor.SessionAware;import org.apache.thrift.TException;import com.opensymphony.xwork2.ValidationAwareSupport;/*** Base class for all user action handlers i.e. controllers** @author Vikas*/public abstract class BaseController extends ValidationAwareSupport implementsServletResponseAware, ServletRequestAware, SessionAware{private static final long serialVersionUID = 3339523094497219816L;protected static Logger log = Logger.getLogger(BaseController.class);protected static final String INPUT = "input";protected static final String INDEX = "index";protected static final String EDIT_NEW = "editNew";protected static final String EDIT = "edit";protected static final String SHOW = "show";protected static final String OPEN = "open";protected static final String EXCEPTION = "exception";static Map<Long, String> providersMap;protected final SimpleDateFormat SDF = new SimpleDateFormat("dd MMM, yyyy hh:mm a");protected HttpServletResponse response;protected HttpServletRequest request;protected HttpSession session;protected Map<String, Object> sessionMap;public static List<TicketCategory> profitMandiTicketCategoryList;static{profitMandiTicketCategoryList = new ArrayList<TicketCategory>();profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_CASHBACK);profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_FEEDBACK);profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_ORDER_NOT_SEEN);profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_OTHER);profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_RECHARGE_ISSUE);profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_ORDER_TRACKING_ISSUE);profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_REFUND_PROBLEM);profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_TECHNICAL_PROBLEM);profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_PRODUCT_ISSUE);profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_DELAYED_DELIVERY);}// Clients used at many placesprotected in.shop2020.model.v1.user.UserContextService.Client userContextServiceClient;protected in.shop2020.model.v1.order.TransactionService.Client transactionServiceClient;protected in.shop2020.crm.CRMService.Client crmServiceClient;protected String currentAgentEmailId = (String) SecurityUtils.getSubject().getPrincipal();@SuppressWarnings("serial")public static final Map<Long, String> providerNameMap = new HashMap<Long, String>() {{put(1l, "BlueDart");put(2l, "Aramex");put(3l, "Delhivery");put(4l, "SelfPickup");put(5l, "Runner");put(6l, "RedExpress");put(7l, "FedEx");put(46l, "FedEx_Surface");}};@SuppressWarnings("serial")public static final Map<ReturnTransactionStatus, List<ReturnTransactionStatus>> FORWARD_STATE_MAP = new HashMap<ReturnTransactionStatus, List<ReturnTransactionStatus>>() {{put(ReturnTransactionStatus.INITIATED, Arrays.asList(ReturnTransactionStatus.AUTHORIZED, ReturnTransactionStatus.REJECTED));put(ReturnTransactionStatus.AUTHORIZED, Arrays.asList(ReturnTransactionStatus.INPROCESS, ReturnTransactionStatus.REJECTED));put(ReturnTransactionStatus.PROCESSED, Arrays.asList(ReturnTransactionStatus.COMPLETED));put(ReturnTransactionStatus.COMPLETED, Arrays.asList(ReturnTransactionStatus.CLOSED));put(ReturnTransactionStatus.REJECTED, Arrays.asList(ReturnTransactionStatus.CLOSED));}};@SuppressWarnings("serial")public static final Map<ReturnTxnPickupStatus, ReturnTxnPickupStatus> FORWARD_STATE_MAP_PICK_UP = new HashMap<ReturnTxnPickupStatus, ReturnTxnPickupStatus>() {{put(ReturnTxnPickupStatus.PENDING, ReturnTxnPickupStatus.PICKUP_REQUESTED);put(ReturnTxnPickupStatus.PICKUP_REQUESTED, ReturnTxnPickupStatus.PICKUP_CONFIRMED);put(ReturnTxnPickupStatus.PICKUP_CONFIRMED, ReturnTxnPickupStatus.PICKUP_SCHEDULED);put(ReturnTxnPickupStatus.PICKUP_SCHEDULED, ReturnTxnPickupStatus.PICKUP_IN_TRANSIT);put(ReturnTxnPickupStatus.PICKUP_IN_TRANSIT, ReturnTxnPickupStatus.PICKUP_RECEIVED);}};public static final List<String> RECEIVE_PICKUP_STATE_CHECK = Arrays.asList("DOA_CERT_INVALID", "DOA_CERT_VALID" ,"DOA_RECEIVED_DAMAGED", "DOA_LOST_IN_TRANSIT","RET_PRODUCT_USABLE", "RET_PRODUCT_UNUSABLE" ,"RET_RECEIVED_DAMAGED", "RET_LOST_IN_TRANSIT");public void setServletResponse(HttpServletResponse response) {this.response = response;}public void setServletRequest(HttpServletRequest request) {this.request = request;}public void setSession(Map<String, Object> sessionMap) {this.session = request.getSession();this.sessionMap = sessionMap;}static {TransactionClient tcl;try {tcl = new TransactionClient();providersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, false);providersMap.putAll(tcl.getClient().getServiceProviders(RechargeType.DTH, false));} catch (Exception e) {log.error("Could not get providers", e);}}/*** Utility method to convert a date to a readable format*/public String convertDate(Long date) {if (date == null || date == 0) {return "N/A";}return SDF.format(new Date(date));}public String getCurrentAgentEmailId() {return currentAgentEmailId;}public String getProductName(LineItem lineItem) {String name = ModelUtils.extractProductNameFromLineItem(lineItem);if (lineItem.getColor() != null && !lineItem.getColor().isEmpty()) {name += "(" + lineItem.getColor() + ")";}return name;}public String getAgentName() throws TException{return CRMAuthorizingRealm.getAgent(currentAgentEmailId).getName();}public boolean canVerifyCOD() {return SecurityUtils.getSubject().hasRole("Outbound");}public boolean canViewFailedPayments() {return SecurityUtils.getSubject().hasRole("Outbound");}public boolean canViewDelayedDeliveries() {return SecurityUtils.getSubject().hasRole("Outbound");}public boolean canViewFlaggedPayments() {return SecurityUtils.getSubject().hasRole("Outbound");}public boolean canViewDoaRequests() {return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));}public boolean canViewReturnRequests() {return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));}public boolean canManageAgents() {return (SecurityUtils.getSubject().hasRole("TeamLead"));}public boolean canViewOrderCancellation() {return SecurityUtils.getSubject().hasRole("Outbound");}public boolean canViewStorePickupTickets() {return (SecurityUtils.getSubject().hasRole("Outbound"));}public boolean canViewAllOpenTickets() {return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));}public boolean canViewLowInventoryCancellation() {return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));}//Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013public boolean canViewRTORefunds() {return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));}//End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013public boolean canViewBulkOrderEnquiry() {return (SecurityUtils.getSubject().hasRole("TeamLead"));}public boolean canViewProfitMandiTicket(){return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));}public boolean isProfitMandiAgent(){return SecurityUtils.getSubject().hasRole("PMAgent");}public boolean isSaholicAndProfitMandiAllowed(){return (SecurityUtils.getSubject().hasRole("Outbound")||SecurityUtils.getSubject().hasRole("TeamLead"));}public boolean canViewDeliveryAttemptFailed(){return (SecurityUtils.getSubject().hasRole("Outbound")||SecurityUtils.getSubject().hasRole("TeamLead"));}public String editNew() {return EDIT_NEW;}public String edit() {return EDIT;}public CODCancelMatrix[] getCODCancelMatrix () {return CRMConstants.CODCancelMatrix.values();}public List<ReturnTransactionStatus> getForwardStatusForStatus(ReturnTransactionStatus returnTransactionStatus){return FORWARD_STATE_MAP.get(returnTransactionStatus);}public ReturnTxnPickupStatus getForwardStatusForPickup(ReturnTxnPickupStatus returnTxnPickupStatus){return FORWARD_STATE_MAP_PICK_UP.get(returnTxnPickupStatus);}}