Subversion Repositories SmartDukaan

Rev

Rev 5884 | Rev 6153 | 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
 
3390 mandeep.dh 3
import in.shop2020.serving.auth.CRMAuthorizingRealm;
4689 anupam.sin 4
import in.shop2020.util.CRMConstants;
5
import in.shop2020.util.CRMConstants.CODCancelMatrix;
3090 mandeep.dh 6
 
7
import java.text.SimpleDateFormat;
8
import java.util.Date;
2674 vikas 9
import java.util.Map;
10
 
11
import javax.servlet.http.HttpServletRequest;
12
import javax.servlet.http.HttpServletResponse;
13
import javax.servlet.http.HttpSession;
14
 
15
import org.apache.log4j.Logger;
3090 mandeep.dh 16
import org.apache.shiro.SecurityUtils;
2674 vikas 17
import org.apache.struts2.interceptor.ServletRequestAware;
18
import org.apache.struts2.interceptor.ServletResponseAware;
19
import org.apache.struts2.interceptor.SessionAware;
3090 mandeep.dh 20
import org.apache.thrift.TException;
2674 vikas 21
 
22
import com.opensymphony.xwork2.ValidationAwareSupport;
23
 
24
/**
25
 * Base class for all user action handlers i.e. controllers
26
 * 
27
 * @author Vikas
28
 */
29
public abstract class BaseController extends ValidationAwareSupport implements
30
        ServletResponseAware, ServletRequestAware, SessionAware
31
{
32
    private static final long serialVersionUID = 3339523094497219816L;
3090 mandeep.dh 33
    protected static Logger log = Logger.getLogger(BaseController.class);
34
 
35
    protected static final String INPUT = "input";
36
    protected static final String INDEX = "index";
37
    protected static final String EDIT_NEW = "editNew";
38
    protected static final String EDIT = "edit";
39
    protected static final String SHOW = "show";
5909 amar.kumar 40
    protected static final String OPEN = "open";
3106 mandeep.dh 41
    protected static final String EXCEPTION = "exception";
3090 mandeep.dh 42
 
43
    protected final SimpleDateFormat SDF = new SimpleDateFormat("dd MMM, yyyy hh:mm a");
44
 
2674 vikas 45
    protected HttpServletResponse response;
46
    protected HttpServletRequest request;
47
    protected HttpSession session;
48
    protected Map<String, Object> sessionMap;
49
 
3090 mandeep.dh 50
    // Clients used at many places
51
    protected in.shop2020.model.v1.user.UserContextService.Client userContextServiceClient;
52
    protected in.shop2020.model.v1.order.TransactionService.Client transactionServiceClient;
53
    protected in.shop2020.crm.CRMService.Client crmServiceClient;
54
 
55
    protected String currentAgentEmailId = (String) SecurityUtils.getSubject().getPrincipal();
56
 
2674 vikas 57
    public void setServletResponse(HttpServletResponse response) {
58
        this.response = response;
59
    }
60
 
61
    public void setServletRequest(HttpServletRequest request) {
62
        this.request = request;
63
    }
64
 
65
    public void setSession(Map<String, Object> sessionMap) {
66
        this.session = request.getSession();
67
        this.sessionMap = sessionMap;
68
    }
3090 mandeep.dh 69
 
70
    /**
71
     * Utility method to convert a date to a readable format 
72
     */
3106 mandeep.dh 73
    public String convertDate(Long date) {
74
        if (date == null || date == 0) {
3090 mandeep.dh 75
            return "N/A";
76
        }
77
 
4144 mandeep.dh 78
        return SDF.format(new Date(date));
3090 mandeep.dh 79
    }
3106 mandeep.dh 80
 
81
    public String getCurrentAgentEmailId() {
82
        return currentAgentEmailId;
83
    }
84
 
3090 mandeep.dh 85
    public String getAgentName() throws TException
86
    {
3390 mandeep.dh 87
        return CRMAuthorizingRealm.getAgent(currentAgentEmailId).getName();
3090 mandeep.dh 88
    }
89
 
3578 mandeep.dh 90
    public boolean canVerifyCOD() {
91
        return SecurityUtils.getSubject().hasRole("Outbound");
92
    }
93
 
94
    public boolean canViewFailedPayments() {
95
        return SecurityUtils.getSubject().hasRole("Outbound");
96
    }
97
 
4008 mandeep.dh 98
    public boolean canViewDelayedDeliveries() {
99
        return SecurityUtils.getSubject().hasRole("Outbound");
100
    }
4267 anupam.sin 101
 
102
    public boolean canViewFlaggedPayments() {
103
        return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
104
    }
4490 anupam.sin 105
 
106
    public boolean canViewDoaRequests() {
107
        return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
108
    }
109
 
110
    public boolean canViewReturnRequests() {
111
        return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
112
    }
4751 anupam.sin 113
 
4793 amar.kumar 114
    public boolean canManageAgents() {
115
    	return (SecurityUtils.getSubject().hasRole("TeamLead"));
116
    }
117
 
4751 anupam.sin 118
    public boolean canViewOrderCancellation() {
119
        return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
120
    }
5884 amar.kumar 121
 
122
    public boolean canViewStorePickupTickets() {
123
    	return (SecurityUtils.getSubject().hasRole("Outbound"));
124
    }
4008 mandeep.dh 125
 
5909 amar.kumar 126
    public boolean canViewAllOpenTickets() {
127
    	return (SecurityUtils.getSubject().hasRole("TeamLead")||SecurityUtils.getSubject().hasRole("Outbound"));
128
    }
129
 
3106 mandeep.dh 130
    public String editNew() {
131
        return EDIT_NEW;
3090 mandeep.dh 132
    }
133
 
3106 mandeep.dh 134
    public String edit() {
135
        return EDIT;
3090 mandeep.dh 136
    }
4689 anupam.sin 137
 
138
    public CODCancelMatrix[] getCODCancelMatrix () {
139
        return CRMConstants.CODCancelMatrix.values();
140
    }
3090 mandeep.dh 141
}