Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
7285 rajveer 1
package in.shop2020.support.controllers;
2
 
7306 rajveer 3
import java.util.ArrayList;
7285 rajveer 4
import java.util.Arrays;
7382 rajveer 5
import java.util.Collection;
7285 rajveer 6
import java.util.List;
7
 
8
import in.shop2020.model.v1.catalog.CatalogServiceException;
9
import in.shop2020.model.v1.catalog.Item;
10
import in.shop2020.model.v1.catalog.StorePricing;
11
import in.shop2020.thrift.clients.CatalogClient;
12
import in.shop2020.utils.ModelUtils;
13
 
14
import javax.servlet.http.HttpServletRequest;
15
import javax.servlet.http.HttpServletResponse;
16
 
17
import org.apache.struts2.convention.annotation.InterceptorRef;
18
import org.apache.struts2.convention.annotation.InterceptorRefs;
19
import org.apache.struts2.convention.annotation.Result;
20
import org.apache.struts2.convention.annotation.Results;
21
import org.apache.struts2.interceptor.ServletRequestAware;
22
import org.apache.struts2.interceptor.ServletResponseAware;
23
import org.apache.thrift.TException;
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
7382 rajveer 26
import com.opensymphony.xwork2.ActionSupport;
7285 rajveer 27
 
28
 
29
@InterceptorRefs({
30
    @InterceptorRef("defaultStack"),
31
    @InterceptorRef("login")
32
})
33
@Results({
34
    @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
35
})
7382 rajveer 36
public class StoreAdminController extends ActionSupport implements ServletRequestAware, ServletResponseAware {
7285 rajveer 37
 
7382 rajveer 38
	private static final long serialVersionUID = 1L;
7285 rajveer 39
	private static Logger logger = LoggerFactory.getLogger(StoreAdminController.class);
40
	private HttpServletRequest request;
41
	private HttpServletResponse response;
42
	private String itemString;
43
	private String id;
44
 
45
	private long itemId;
46
	private double recommendedPrice;
47
	private double minPrice;
48
	private double maxPrice;
49
	private double minAdvancePrice;
7351 rajveer 50
	private double absoluteMinPrice;
51
 
52
 
7308 rajveer 53
	private long freebieItemId;
54
	private String bestDealText;
7285 rajveer 55
	private boolean activeonstore;
7382 rajveer 56
	private boolean allcolors;
7285 rajveer 57
 
58
	public String index()	{
59
		return "index";
60
	}
61
 
62
	public String show()	{
63
		return "index";
64
	}
65
 
66
	public String create() {
7351 rajveer 67
		StorePricing sp = new StorePricing(itemId, recommendedPrice, minPrice, maxPrice, minAdvancePrice, absoluteMinPrice, freebieItemId, bestDealText);
7285 rajveer 68
		try	{
69
			CatalogClient csc = new CatalogClient();
7436 rajveer 70
			CatalogClient cscs = new CatalogClient("catalog_service_server_host_prod", "catalog_service_server_port");
7285 rajveer 71
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
7436 rajveer 72
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClientProd= cscs.getClient();
73
 
7382 rajveer 74
			catalogClient.updateStorePricing(sp, allcolors);
7436 rajveer 75
			catalogClientProd.updateStorePricing(sp, allcolors);
7285 rajveer 76
			Item item = getItem(itemId);
77
			if(item.isActiveOnStore() != isActiveonstore()){
78
				item.setActiveOnStore(isActiveonstore());
79
				catalogClient.updateItem(item);
7436 rajveer 80
				catalogClientProd.updateItem(item);
7285 rajveer 81
			}
7382 rajveer 82
			addActionError("Pricing successfully updated");
7285 rajveer 83
		} catch (TException e) {
84
			logger.error("", e);
85
		} catch (CatalogServiceException e) {
86
			e.printStackTrace();
7382 rajveer 87
			addActionError("Unable to update pricing because: " + e.getMessage());
7285 rajveer 88
		}
7382 rajveer 89
		setId(Long.toString(itemId));
7285 rajveer 90
		return "index";
91
	}
92
 
7382 rajveer 93
	public Collection<String> getMessages(){
94
		return getActionErrors();
95
	}
96
 
7285 rajveer 97
	public List<Item> searchItem(){
98
		List<Item> items = null;
99
		if(itemString != null){
100
			try{
101
				CatalogClient csc = new CatalogClient();
102
				in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
103
				List<String> searchTerms = Arrays.asList(itemString.split(" "));
104
				items = catalogClient.searchItemsInRange(searchTerms, 0, 50);
105
			}catch (Exception e) {
106
				logger.error("", e);
107
			}
7382 rajveer 108
		}else if(id == null)
109
			{
110
				try{
111
					CatalogClient csc = new CatalogClient();
112
					in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
113
					items = catalogClient.getLatestArrivals();
114
				}catch (Exception e) {
115
					logger.error("", e);
116
				}
117
			}
7285 rajveer 118
		return items;
119
	}
120
 
121
 
122
	public StorePricing getStorePricing(){
123
		StorePricing sp = null;
124
		if(id != null){
125
			try{
126
				long itemId = Long.parseLong(id);
127
				CatalogClient csc = new CatalogClient();
128
				in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
129
				sp = catalogClient.getStorePricing(itemId);
130
			}catch (Exception e) {
131
				logger.error("", e);
132
			}
133
		}
134
		return sp;
135
	}
136
 
7306 rajveer 137
	public List<StorePricing> getStorePricings(List<Item> items){
138
		List<Long> itemIds = new ArrayList<Long>();
139
		List<StorePricing> sps = null;
140
		try{
141
			for(Item item: items){
142
				itemIds.add(item.getId());
143
			}
144
			CatalogClient csc = new CatalogClient();
145
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
146
			sps = catalogClient.getStorePricings(itemIds);
147
		}catch (Exception e) {
148
			logger.error("", e);
149
		}
150
		return sps;
151
	}
152
 
7285 rajveer 153
	public Item getItem(long itemId){
154
		Item item = null;
155
		try{
156
			CatalogClient csc = new CatalogClient();
157
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
158
			item = catalogClient.getItem(itemId);
159
		}catch (Exception e) {
160
			logger.error("", e);
161
		}
162
		return item;
163
	}
164
 
165
 
166
    public String getServletContextPath() {
167
        return request.getContextPath();
168
    }
169
 
170
	@Override
171
	public void setServletRequest(HttpServletRequest request) {
172
		this.request = request;
173
	}
174
 
175
	@Override
176
	public void setServletResponse(HttpServletResponse response) {
177
		this.response = response;
178
	}
179
 
180
	public String getProductNameFromItem(Item item)	{
181
		return ModelUtils.extractProductNameFromItem(item);
182
	}
183
 
7382 rajveer 184
	public String getItemString(){
185
		return this.itemString;	
186
	}
187
 
7285 rajveer 188
	public void setItemString(String itemString){
189
		this.itemString = itemString;
190
	}
191
 
192
	public void setId(String id){
193
 		this.id = id;
194
	}
195
 
7382 rajveer 196
	public String getId(){
197
 		return this.id;
198
	}
199
 
7285 rajveer 200
	public void setItemId(long itemId) {
201
		this.itemId = itemId;
202
	}
203
 
204
	public long getItemId() {
205
		return itemId;
206
	}
207
 
208
	public void setRecommendedPrice(double recommendedPrice) {
209
		this.recommendedPrice = recommendedPrice;
210
	}
211
 
212
	public double getRecommendedPrice() {
213
		return recommendedPrice;
214
	}
215
 
216
	public void setMinPrice(double minPrice) {
217
		this.minPrice = minPrice;
218
	}
219
 
220
	public double getMinPrice() {
221
		return minPrice;
222
	}
223
 
224
	public void setMaxPrice(double maxPrice) {
225
		this.maxPrice = maxPrice;
226
	}
227
 
228
	public double getMaxPrice() {
229
		return maxPrice;
230
	}
231
 
232
	public void setMinAdvancePrice(double minAdvancePrice) {
233
		this.minAdvancePrice = minAdvancePrice;
234
	}
235
 
236
	public double getMinAdvancePrice() {
237
		return minAdvancePrice;
238
	}
239
 
240
	public void setActiveonstore(String activeonstore) {
241
		if(activeonstore.equals("on")){
242
			this.activeonstore = true;
243
		}else{
244
			this.activeonstore = false;
245
		}
246
	}
247
 
248
	public boolean isActiveonstore() {
249
		return activeonstore;
250
	}
251
 
7308 rajveer 252
	public void setFreebieItemId(long freebieItemId) {
253
		this.freebieItemId = freebieItemId;
254
	}
255
 
256
	public long getFreebieItemId() {
257
		return freebieItemId;
258
	}
259
 
260
	public void setBestDealText(String bestDealText) {
261
		this.bestDealText = bestDealText;
262
	}
263
 
264
	public String getBestDealText() {
265
		return bestDealText;
266
	}
267
 
7351 rajveer 268
	public double getAbsoluteMinPrice() {
269
		return absoluteMinPrice;
270
	}
271
 
272
	public void setAbsoluteMinPrice(double absoluteMinPrice) {
273
		this.absoluteMinPrice = absoluteMinPrice;
274
	}
7382 rajveer 275
 
276
	public void setAllcolors(String allcolors) {
277
		if(allcolors.equals("on")){
278
			this.allcolors = true;
279
		}else{
280
			this.allcolors = false;
281
		}
282
	}
283
 
284
	public boolean isAllcolors() {
285
		return allcolors;
286
	}
7351 rajveer 287
 
7285 rajveer 288
}