Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
7285 rajveer 1
package in.shop2020.support.controllers;
2
 
3
import java.util.Arrays;
4
import java.util.List;
5
 
6
import in.shop2020.model.v1.catalog.CatalogServiceException;
7
import in.shop2020.model.v1.catalog.Item;
8
import in.shop2020.model.v1.catalog.StorePricing;
9
import in.shop2020.thrift.clients.CatalogClient;
10
import in.shop2020.utils.ModelUtils;
11
 
12
import javax.servlet.http.HttpServletRequest;
13
import javax.servlet.http.HttpServletResponse;
14
 
15
import org.apache.struts2.convention.annotation.InterceptorRef;
16
import org.apache.struts2.convention.annotation.InterceptorRefs;
17
import org.apache.struts2.convention.annotation.Result;
18
import org.apache.struts2.convention.annotation.Results;
19
import org.apache.struts2.interceptor.ServletRequestAware;
20
import org.apache.struts2.interceptor.ServletResponseAware;
21
import org.apache.thrift.TException;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24
 
25
 
26
@InterceptorRefs({
27
    @InterceptorRef("defaultStack"),
28
    @InterceptorRef("login")
29
})
30
@Results({
31
    @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
32
})
33
public class StoreAdminController implements ServletRequestAware, ServletResponseAware {
34
 
35
	private static Logger logger = LoggerFactory.getLogger(StoreAdminController.class);
36
	private HttpServletRequest request;
37
	private HttpServletResponse response;
38
	private String itemString;
39
	private String id;
40
 
41
	private long itemId;
42
	private double recommendedPrice;
43
	private double minPrice;
44
	private double maxPrice;
45
	private double minAdvancePrice;
46
	private boolean activeonstore;
47
 
48
	public String index()	{
49
		return "index";
50
	}
51
 
52
	public String show()	{
53
		return "index";
54
	}
55
 
56
	public String create() {
57
		StorePricing sp = new StorePricing(itemId, recommendedPrice, minPrice, maxPrice, minAdvancePrice);
58
		try	{
59
			CatalogClient csc = new CatalogClient();
60
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
61
			catalogClient.updateStorePricing(sp);
62
			Item item = getItem(itemId);
63
			if(item.isActiveOnStore() != isActiveonstore()){
64
				item.setActiveOnStore(isActiveonstore());
65
				catalogClient.updateItem(item);
66
			}
67
		} catch (TException e) {
68
			logger.error("", e);
69
		} catch (CatalogServiceException e) {
70
			// TODO Auto-generated catch block
71
			e.printStackTrace();
72
		}
73
		return "index";
74
	}
75
 
76
	public List<Item> searchItem(){
77
		List<Item> items = null;
78
		if(itemString != null){
79
			try{
80
				CatalogClient csc = new CatalogClient();
81
				in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
82
				List<String> searchTerms = Arrays.asList(itemString.split(" "));
83
				items = catalogClient.searchItemsInRange(searchTerms, 0, 50);
84
			}catch (Exception e) {
85
				logger.error("", e);
86
			}
87
		}
88
		return items;
89
	}
90
 
91
 
92
	public StorePricing getStorePricing(){
93
		StorePricing sp = null;
94
		if(id != null){
95
			try{
96
				long itemId = Long.parseLong(id);
97
				CatalogClient csc = new CatalogClient();
98
				in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
99
				sp = catalogClient.getStorePricing(itemId);
100
			}catch (Exception e) {
101
				logger.error("", e);
102
			}
103
		}
104
		return sp;
105
	}
106
 
107
	public Item getItem(long itemId){
108
		Item item = null;
109
		try{
110
			CatalogClient csc = new CatalogClient();
111
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
112
			item = catalogClient.getItem(itemId);
113
		}catch (Exception e) {
114
			logger.error("", e);
115
		}
116
		return item;
117
	}
118
 
119
 
120
    public String getServletContextPath() {
121
        return request.getContextPath();
122
    }
123
 
124
	@Override
125
	public void setServletRequest(HttpServletRequest request) {
126
		this.request = request;
127
	}
128
 
129
	@Override
130
	public void setServletResponse(HttpServletResponse response) {
131
		this.response = response;
132
	}
133
 
134
	public String getProductNameFromItem(Item item)	{
135
		return ModelUtils.extractProductNameFromItem(item);
136
	}
137
 
138
	public void setItemString(String itemString){
139
		this.itemString = itemString;
140
	}
141
 
142
	public void setId(String id){
143
 		this.id = id;
144
	}
145
 
146
	public void setItemId(long itemId) {
147
		this.itemId = itemId;
148
	}
149
 
150
	public long getItemId() {
151
		return itemId;
152
	}
153
 
154
	public void setRecommendedPrice(double recommendedPrice) {
155
		this.recommendedPrice = recommendedPrice;
156
	}
157
 
158
	public double getRecommendedPrice() {
159
		return recommendedPrice;
160
	}
161
 
162
	public void setMinPrice(double minPrice) {
163
		this.minPrice = minPrice;
164
	}
165
 
166
	public double getMinPrice() {
167
		return minPrice;
168
	}
169
 
170
	public void setMaxPrice(double maxPrice) {
171
		this.maxPrice = maxPrice;
172
	}
173
 
174
	public double getMaxPrice() {
175
		return maxPrice;
176
	}
177
 
178
	public void setMinAdvancePrice(double minAdvancePrice) {
179
		this.minAdvancePrice = minAdvancePrice;
180
	}
181
 
182
	public double getMinAdvancePrice() {
183
		return minAdvancePrice;
184
	}
185
 
186
	public void setActiveonstore(String activeonstore) {
187
		if(activeonstore.equals("on")){
188
			this.activeonstore = true;
189
		}else{
190
			this.activeonstore = false;
191
		}
192
	}
193
 
194
	public boolean isActiveonstore() {
195
		return activeonstore;
196
	}
197
 
198
}