Subversion Repositories SmartDukaan

Rev

Rev 4939 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4806 varun.gupt 1
package in.shop2020.support.controllers;
2
 
3
import java.util.List;
4
 
5
import in.shop2020.thrift.clients.HelperClient;
6
import in.shop2020.utils.HelperService.Client;
7
import in.shop2020.utils.HelperServiceException;
8
import in.shop2020.utils.QuickLink;
9
 
10
import javax.servlet.ServletRequest;
11
import javax.servlet.http.HttpServletRequest;
12
 
13
import org.apache.struts2.interceptor.ServletRequestAware;
14
import org.apache.thrift.TException;
15
import org.apache.thrift.transport.TTransportException;
16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18
 
19
import com.opensymphony.xwork2.ValidationAwareSupport;
20
 
21
/**
22
 * @author Varun Gupta
23
 */
24
public class QuicklinksController extends ValidationAwareSupport implements ServletRequestAware {
25
 
26
    private static Logger logger = LoggerFactory.getLogger(VendorReconciliationController.class);
27
 
28
	private ServletRequest request;
29
	private String url;
30
	private String text;
31
 
32
	private List<QuickLink> quicklinks;
33
 
34
	public String index()	{
35
		populateQuicklinks();
36
		return "index";
37
	}
38
 
39
	public String create()	{
40
		if (url.equals("") || text.equals(""))	{
41
			addActionError("URL or Text field cannot be left blank");
42
			return "index";
43
		}
44
		try	{
45
			HelperClient helperClient = new HelperClient();
46
			Client hsc = helperClient.getClient();
47
 
48
			hsc.saveQuickLink(url, text);
49
			addActionMessage("URL ( " + url + ") is added.");
50
			populateQuicklinks();
51
 
52
		} catch (TTransportException e)	{
53
			logger.error("TTransportException " + e);
54
 
55
		} catch (HelperServiceException e) {
56
			logger.error("Helper Service Exception " + e);
57
 
58
		} catch (TException e) {
59
			logger.error("TException " + e);
60
		}
61
		return "index";
62
	}
63
 
64
	private void populateQuicklinks()	{
65
		try	{
66
			HelperClient helperClient = new HelperClient();
67
			Client hsc = helperClient.getClient();
68
 
69
			quicklinks = hsc.getQuickLinks();
70
 
71
		} catch (TTransportException e)	{
72
			logger.error("TTransportException " + e);
73
 
74
		} catch (HelperServiceException e) {
75
			logger.error("Helper Service Exception " + e);
76
 
77
		} catch (TException e) {
78
			logger.error("TException " + e);
79
		}
80
	}
81
 
82
	public List<QuickLink> getQuickLinks()	{
83
		return quicklinks;
84
	}
85
 
86
	@Override
87
	public void setServletRequest(HttpServletRequest request) {
88
		this.request = request;
89
	}
90
 
91
	public void setUrl(String url) {
92
		this.url = url;
93
	}
94
 
95
	public void setText(String text) {
96
		this.text = text;
97
	}
98
}