Subversion Repositories SmartDukaan

Rev

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