Subversion Repositories SmartDukaan

Rev

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