Subversion Repositories SmartDukaan

Rev

Rev 16244 | Rev 18709 | 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);
17274 manish.sha 67
    	profitMandiTicketCategoryList.add(TicketCategory.PROFITMANDI_ORDER_TRACKING_ISSUE);
16244 manish.sha 68
    }
2674 vikas 69
 
3090 mandeep.dh 70
    // Clients used at many places
71
    protected in.shop2020.model.v1.user.UserContextService.Client userContextServiceClient;
72
    protected in.shop2020.model.v1.order.TransactionService.Client transactionServiceClient;
73
    protected in.shop2020.crm.CRMService.Client crmServiceClient;
74
 
75
    protected String currentAgentEmailId = (String) SecurityUtils.getSubject().getPrincipal();
76
 
2674 vikas 77
    public void setServletResponse(HttpServletResponse response) {
78
        this.response = response;
79
    }
80
 
81
    public void setServletRequest(HttpServletRequest request) {
82
        this.request = request;
83
    }
84
 
85
    public void setSession(Map<String, Object> sessionMap) {
86
        this.session = request.getSession();
87
        this.sessionMap = sessionMap;
88
    }
3090 mandeep.dh 89
 
6153 anupam.sin 90
    static {
91
        TransactionClient tcl;
92
        try {
93
            tcl = new TransactionClient();
6206 rajveer 94
            providersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, false);
95
            providersMap.putAll(tcl.getClient().getServiceProviders(RechargeType.DTH, false));
6153 anupam.sin 96
        } catch (Exception e) {
97
            log.error("Could not get providers", e);
98
        }
99
    }
100
 
3090 mandeep.dh 101
    /**
102
     * Utility method to convert a date to a readable format 
103
     */
3106 mandeep.dh 104
    public String convertDate(Long date) {
105
        if (date == null || date == 0) {
3090 mandeep.dh 106
            return "N/A";
107
        }
108
 
4144 mandeep.dh 109
        return SDF.format(new Date(date));
3090 mandeep.dh 110
    }
3106 mandeep.dh 111
 
112
    public String getCurrentAgentEmailId() {
113
        return currentAgentEmailId;
114
    }
7572 anupam.sin 115
 
116
    public String getProductName(LineItem lineItem) {
117
        String name = ModelUtils.extractProductNameFromLineItem(lineItem);
3106 mandeep.dh 118
 
7572 anupam.sin 119
        if (lineItem.getColor() != null && !lineItem.getColor().isEmpty()) {
120
            name += "(" + lineItem.getColor() + ")";
121
        }
122
 
123
        return name;
124
    }
125
 
3090 mandeep.dh 126
    public String getAgentName() throws TException
127
    {
3390 mandeep.dh 128
        return CRMAuthorizingRealm.getAgent(currentAgentEmailId).getName();
3090 mandeep.dh 129
    }
130
 
3578 mandeep.dh 131
    public boolean canVerifyCOD() {
132
        return SecurityUtils.getSubject().hasRole("Outbound");
133
    }
134
 
135
    public boolean canViewFailedPayments() {
136
        return SecurityUtils.getSubject().hasRole("Outbound");
137
    }
138
 
4008 mandeep.dh 139
    public boolean canViewDelayedDeliveries() {
140
        return SecurityUtils.getSubject().hasRole("Outbound");
141
    }
4267 anupam.sin 142
 
143
    public boolean canViewFlaggedPayments() {
6507 anupam.sin 144
        return SecurityUtils.getSubject().hasRole("Outbound");
4267 anupam.sin 145
    }
4490 anupam.sin 146
 
147
    public boolean canViewDoaRequests() {
148
        return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
149
    }
150
 
151
    public boolean canViewReturnRequests() {
152
        return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
153
    }
4751 anupam.sin 154
 
4793 amar.kumar 155
    public boolean canManageAgents() {
156
    	return (SecurityUtils.getSubject().hasRole("TeamLead"));
157
    }
158
 
4751 anupam.sin 159
    public boolean canViewOrderCancellation() {
6507 anupam.sin 160
        return SecurityUtils.getSubject().hasRole("Outbound");
4751 anupam.sin 161
    }
5884 amar.kumar 162
 
163
    public boolean canViewStorePickupTickets() {
164
    	return (SecurityUtils.getSubject().hasRole("Outbound"));
165
    }
4008 mandeep.dh 166
 
5909 amar.kumar 167
    public boolean canViewAllOpenTickets() {
168
    	return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));
169
    }
170
 
7372 kshitij.so 171
    public boolean canViewLowInventoryCancellation() { 
172
    	return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));
173
    }
174
 
7616 manish.sha 175
    //Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
176
    public boolean canViewRTORefunds() { 
177
    	return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));
178
    }
179
    //End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
180
 
11890 kshitij.so 181
    public boolean canViewBulkOrderEnquiry() { 
182
        return (SecurityUtils.getSubject().hasRole("TeamLead"));
183
    }
184
 
14882 manish.sha 185
    public boolean canViewProfitMandiTicket(){
15698 manish.sha 186
    	return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));
14882 manish.sha 187
    }
188
 
16208 manish.sha 189
    public boolean isProfitMandiAgent(){
190
    	return SecurityUtils.getSubject().hasRole("PMAgent");
191
    }
192
 
16244 manish.sha 193
    public boolean isSaholicAndProfitMandiAllowed(){
194
    	return (SecurityUtils.getSubject().hasRole("Outbound")||SecurityUtils.getSubject().hasRole("TeamLead"));
195
    }
196
 
3106 mandeep.dh 197
    public String editNew() {
198
        return EDIT_NEW;
3090 mandeep.dh 199
    }
200
 
3106 mandeep.dh 201
    public String edit() {
202
        return EDIT;
3090 mandeep.dh 203
    }
4689 anupam.sin 204
 
205
    public CODCancelMatrix[] getCODCancelMatrix () {
206
        return CRMConstants.CODCancelMatrix.values();
207
    }
3090 mandeep.dh 208
}