Subversion Repositories SmartDukaan

Rev

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

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