Subversion Repositories SmartDukaan

Rev

Rev 16208 | Rev 17274 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2674 vikas 1
package in.shop2020.serving.controllers;
2
 
16244 manish.sha 3
import in.shop2020.crm.TicketCategory;
7572 anupam.sin 4
import in.shop2020.model.v1.order.LineItem;
6153 anupam.sin 5
import in.shop2020.model.v1.order.RechargeType;
3390 mandeep.dh 6
import in.shop2020.serving.auth.CRMAuthorizingRealm;
6153 anupam.sin 7
import in.shop2020.thrift.clients.TransactionClient;
4689 anupam.sin 8
import in.shop2020.util.CRMConstants;
9
import in.shop2020.util.CRMConstants.CODCancelMatrix;
7572 anupam.sin 10
import in.shop2020.utils.ModelUtils;
3090 mandeep.dh 11
 
12
import java.text.SimpleDateFormat;
16244 manish.sha 13
import java.util.ArrayList;
3090 mandeep.dh 14
import java.util.Date;
16244 manish.sha 15
import java.util.List;
2674 vikas 16
import java.util.Map;
17
 
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
20
import javax.servlet.http.HttpSession;
21
 
22
import org.apache.log4j.Logger;
3090 mandeep.dh 23
import org.apache.shiro.SecurityUtils;
2674 vikas 24
import org.apache.struts2.interceptor.ServletRequestAware;
25
import org.apache.struts2.interceptor.ServletResponseAware;
26
import org.apache.struts2.interceptor.SessionAware;
3090 mandeep.dh 27
import org.apache.thrift.TException;
2674 vikas 28
 
29
import com.opensymphony.xwork2.ValidationAwareSupport;
30
 
31
/**
32
 * Base class for all user action handlers i.e. controllers
33
 * 
34
 * @author Vikas
35
 */
36
public abstract class BaseController extends ValidationAwareSupport implements
37
        ServletResponseAware, ServletRequestAware, SessionAware
38
{
39
    private static final long serialVersionUID = 3339523094497219816L;
3090 mandeep.dh 40
    protected static Logger log = Logger.getLogger(BaseController.class);
41
 
42
    protected static final String INPUT = "input";
43
    protected static final String INDEX = "index";
44
    protected static final String EDIT_NEW = "editNew";
45
    protected static final String EDIT = "edit";
46
    protected static final String SHOW = "show";
5909 amar.kumar 47
    protected static final String OPEN = "open";
3106 mandeep.dh 48
    protected static final String EXCEPTION = "exception";
6153 anupam.sin 49
 
50
    static Map<Long, String> providersMap;
3090 mandeep.dh 51
 
52
    protected final SimpleDateFormat SDF = new SimpleDateFormat("dd MMM, yyyy hh:mm a");
53
 
2674 vikas 54
    protected HttpServletResponse response;
55
    protected HttpServletRequest request;
56
    protected HttpSession session;
57
    protected Map<String, Object> sessionMap;
16244 manish.sha 58
    public static List<TicketCategory> profitMandiTicketCategoryList;
59
 
60
    static{
61
    	profitMandiTicketCategoryList = new ArrayList<TicketCategory>();
62
    	profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_CASHBACK);
63
    	profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_FEEDBACK);
64
    	profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_ORDER_NOT_SEEN);
65
    	profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_OTHER);
66
    	profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_RECHARGE_ISSUE);
67
    }
2674 vikas 68
 
3090 mandeep.dh 69
    // Clients used at many places
70
    protected in.shop2020.model.v1.user.UserContextService.Client userContextServiceClient;
71
    protected in.shop2020.model.v1.order.TransactionService.Client transactionServiceClient;
72
    protected in.shop2020.crm.CRMService.Client crmServiceClient;
73
 
74
    protected String currentAgentEmailId = (String) SecurityUtils.getSubject().getPrincipal();
75
 
2674 vikas 76
    public void setServletResponse(HttpServletResponse response) {
77
        this.response = response;
78
    }
79
 
80
    public void setServletRequest(HttpServletRequest request) {
81
        this.request = request;
82
    }
83
 
84
    public void setSession(Map<String, Object> sessionMap) {
85
        this.session = request.getSession();
86
        this.sessionMap = sessionMap;
87
    }
3090 mandeep.dh 88
 
6153 anupam.sin 89
    static {
90
        TransactionClient tcl;
91
        try {
92
            tcl = new TransactionClient();
6206 rajveer 93
            providersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, false);
94
            providersMap.putAll(tcl.getClient().getServiceProviders(RechargeType.DTH, false));
6153 anupam.sin 95
        } catch (Exception e) {
96
            log.error("Could not get providers", e);
97
        }
98
    }
99
 
3090 mandeep.dh 100
    /**
101
     * Utility method to convert a date to a readable format 
102
     */
3106 mandeep.dh 103
    public String convertDate(Long date) {
104
        if (date == null || date == 0) {
3090 mandeep.dh 105
            return "N/A";
106
        }
107
 
4144 mandeep.dh 108
        return SDF.format(new Date(date));
3090 mandeep.dh 109
    }
3106 mandeep.dh 110
 
111
    public String getCurrentAgentEmailId() {
112
        return currentAgentEmailId;
113
    }
7572 anupam.sin 114
 
115
    public String getProductName(LineItem lineItem) {
116
        String name = ModelUtils.extractProductNameFromLineItem(lineItem);
3106 mandeep.dh 117
 
7572 anupam.sin 118
        if (lineItem.getColor() != null && !lineItem.getColor().isEmpty()) {
119
            name += "(" + lineItem.getColor() + ")";
120
        }
121
 
122
        return name;
123
    }
124
 
3090 mandeep.dh 125
    public String getAgentName() throws TException
126
    {
3390 mandeep.dh 127
        return CRMAuthorizingRealm.getAgent(currentAgentEmailId).getName();
3090 mandeep.dh 128
    }
129
 
3578 mandeep.dh 130
    public boolean canVerifyCOD() {
131
        return SecurityUtils.getSubject().hasRole("Outbound");
132
    }
133
 
134
    public boolean canViewFailedPayments() {
135
        return SecurityUtils.getSubject().hasRole("Outbound");
136
    }
137
 
4008 mandeep.dh 138
    public boolean canViewDelayedDeliveries() {
139
        return SecurityUtils.getSubject().hasRole("Outbound");
140
    }
4267 anupam.sin 141
 
142
    public boolean canViewFlaggedPayments() {
6507 anupam.sin 143
        return SecurityUtils.getSubject().hasRole("Outbound");
4267 anupam.sin 144
    }
4490 anupam.sin 145
 
146
    public boolean canViewDoaRequests() {
147
        return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
148
    }
149
 
150
    public boolean canViewReturnRequests() {
151
        return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
152
    }
4751 anupam.sin 153
 
4793 amar.kumar 154
    public boolean canManageAgents() {
155
    	return (SecurityUtils.getSubject().hasRole("TeamLead"));
156
    }
157
 
4751 anupam.sin 158
    public boolean canViewOrderCancellation() {
6507 anupam.sin 159
        return SecurityUtils.getSubject().hasRole("Outbound");
4751 anupam.sin 160
    }
5884 amar.kumar 161
 
162
    public boolean canViewStorePickupTickets() {
163
    	return (SecurityUtils.getSubject().hasRole("Outbound"));
164
    }
4008 mandeep.dh 165
 
5909 amar.kumar 166
    public boolean canViewAllOpenTickets() {
167
    	return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));
168
    }
169
 
7372 kshitij.so 170
    public boolean canViewLowInventoryCancellation() { 
171
    	return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));
172
    }
173
 
7616 manish.sha 174
    //Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
175
    public boolean canViewRTORefunds() { 
176
    	return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));
177
    }
178
    //End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
179
 
11890 kshitij.so 180
    public boolean canViewBulkOrderEnquiry() { 
181
        return (SecurityUtils.getSubject().hasRole("TeamLead"));
182
    }
183
 
14882 manish.sha 184
    public boolean canViewProfitMandiTicket(){
15698 manish.sha 185
    	return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));
14882 manish.sha 186
    }
187
 
16208 manish.sha 188
    public boolean isProfitMandiAgent(){
189
    	return SecurityUtils.getSubject().hasRole("PMAgent");
190
    }
191
 
16244 manish.sha 192
    public boolean isSaholicAndProfitMandiAllowed(){
193
    	return (SecurityUtils.getSubject().hasRole("Outbound")||SecurityUtils.getSubject().hasRole("TeamLead"));
194
    }
195
 
3106 mandeep.dh 196
    public String editNew() {
197
        return EDIT_NEW;
3090 mandeep.dh 198
    }
199
 
3106 mandeep.dh 200
    public String edit() {
201
        return EDIT;
3090 mandeep.dh 202
    }
4689 anupam.sin 203
 
204
    public CODCancelMatrix[] getCODCancelMatrix () {
205
        return CRMConstants.CODCancelMatrix.values();
206
    }
3090 mandeep.dh 207
}