Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
7068 anupam.sin 1
package in.shop2020.recharge.controllers;
2
 
7207 anupam.sin 3
import in.shop2020.model.v1.order.HotspotStore;
4
 
7068 anupam.sin 5
import java.text.SimpleDateFormat;
6
import java.util.Date;
7207 anupam.sin 7
import java.util.HashMap;
7068 anupam.sin 8
import java.util.Map;
9
 
10
import javax.servlet.http.HttpServletRequest;
11
import javax.servlet.http.HttpServletResponse;
12
import javax.servlet.http.HttpSession;
13
 
14
import org.apache.log4j.Logger;
15
import org.apache.shiro.SecurityUtils;
16
import org.apache.struts2.interceptor.ServletRequestAware;
17
import org.apache.struts2.interceptor.ServletResponseAware;
18
import org.apache.struts2.interceptor.SessionAware;
19
 
20
import com.opensymphony.xwork2.ValidationAwareSupport;
21
 
22
/**
23
 * Base class for all user action handlers i.e. controllers
24
 * 
25
 * @author Vikas
26
 */
27
public abstract class BaseController extends ValidationAwareSupport implements
28
        ServletResponseAware, ServletRequestAware, SessionAware
29
{
30
    private static final long serialVersionUID = 3339523094497219816L;
31
    protected static Logger log = Logger.getLogger(BaseController.class);
32
 
33
    protected static final String INPUT = "input";
34
    protected static final String INDEX = "index";
35
    protected static final String EDIT_NEW = "editNew";
36
    protected static final String EDIT = "edit";
37
    protected static final String SHOW = "show";
38
    protected static final String EXCEPTION = "exception";
7207 anupam.sin 39
 
40
    public static Map<Long, HotspotStore> hotspotStores = new HashMap<Long, HotspotStore>();
7068 anupam.sin 41
 
42
    protected final SimpleDateFormat SDF = new SimpleDateFormat("dd MMM, yyyy hh:mm a");
43
 
44
    protected HttpServletResponse response;
45
    protected HttpServletRequest request;
46
    protected HttpSession session;
47
    protected Map<String, Object> sessionMap;
7207 anupam.sin 48
 
49
    protected Long storeId;
7068 anupam.sin 50
 
51
    public void setServletResponse(HttpServletResponse response) {
52
        this.response = response;
53
    }
54
 
55
    public void setServletRequest(HttpServletRequest request) {
56
        this.request = request;
7207 anupam.sin 57
        this.session = request.getSession();
7068 anupam.sin 58
    }
59
 
60
    public void setSession(Map<String, Object> sessionMap) {
61
        this.sessionMap = sessionMap;
62
    }
63
 
64
    /**
65
     * Utility method to convert a date to a readable format 
66
     */
67
    public String convertDate(Long date) {
68
        if (date == null || date == 0) {
69
            return "N/A";
70
        }
71
 
72
        return SDF.format(new Date(date));
73
    }
74
 
75
    public String index() {
76
        return INDEX;
77
    }
78
 
79
    public String editNew() {
80
        return EDIT_NEW;
81
    }
82
 
83
    public String edit() {
84
        return EDIT;
85
    }
86
 
87
    public boolean isPermitted(String permission) {
88
        return SecurityUtils.getSubject().isPermitted(permission);
89
    }
7207 anupam.sin 90
 
91
    public String getStoreCode(){
92
        return hotspotStores.get(storeId).getHotspotId();   
93
    }
94
 
95
    public String getCollectedAmount(){
96
        return hotspotStores.get(storeId).getCollectedAmount()+"";
97
    }
98
 
99
    public Long getStoreId() {
100
        return storeId;
101
    }
102
 
103
    public void setStoreId(Long storeId) {
104
        this.storeId = storeId;
105
    }
7068 anupam.sin 106
}