Subversion Repositories SmartDukaan

Rev

Rev 7306 | Rev 7351 | 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;
7308 rajveer 47
	private long freebieItemId;
48
	private String bestDealText;
7285 rajveer 49
	private boolean activeonstore;
50
 
51
	public String index()	{
52
		return "index";
53
	}
54
 
55
	public String show()	{
56
		return "index";
57
	}
58
 
59
	public String create() {
7308 rajveer 60
		StorePricing sp = new StorePricing(itemId, recommendedPrice, minPrice, maxPrice, minAdvancePrice, freebieItemId, bestDealText);
7285 rajveer 61
		try	{
62
			CatalogClient csc = new CatalogClient();
63
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
64
			catalogClient.updateStorePricing(sp);
65
			Item item = getItem(itemId);
66
			if(item.isActiveOnStore() != isActiveonstore()){
67
				item.setActiveOnStore(isActiveonstore());
68
				catalogClient.updateItem(item);
69
			}
70
		} catch (TException e) {
71
			logger.error("", e);
72
		} catch (CatalogServiceException e) {
73
			// TODO Auto-generated catch block
74
			e.printStackTrace();
75
		}
76
		return "index";
77
	}
78
 
79
	public List<Item> searchItem(){
80
		List<Item> items = null;
81
		if(itemString != null){
82
			try{
83
				CatalogClient csc = new CatalogClient();
84
				in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
85
				List<String> searchTerms = Arrays.asList(itemString.split(" "));
86
				items = catalogClient.searchItemsInRange(searchTerms, 0, 50);
87
			}catch (Exception e) {
88
				logger.error("", e);
89
			}
90
		}
91
		return items;
92
	}
93
 
94
 
95
	public StorePricing getStorePricing(){
96
		StorePricing sp = null;
97
		if(id != null){
98
			try{
99
				long itemId = Long.parseLong(id);
100
				CatalogClient csc = new CatalogClient();
101
				in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
102
				sp = catalogClient.getStorePricing(itemId);
103
			}catch (Exception e) {
104
				logger.error("", e);
105
			}
106
		}
107
		return sp;
108
	}
109
 
7306 rajveer 110
	public List<StorePricing> getStorePricings(List<Item> items){
111
		List<Long> itemIds = new ArrayList<Long>();
112
		List<StorePricing> sps = null;
113
		try{
114
			for(Item item: items){
115
				itemIds.add(item.getId());
116
			}
117
			CatalogClient csc = new CatalogClient();
118
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
119
			sps = catalogClient.getStorePricings(itemIds);
120
		}catch (Exception e) {
121
			logger.error("", e);
122
		}
123
		return sps;
124
	}
125
 
7285 rajveer 126
	public Item getItem(long itemId){
127
		Item item = null;
128
		try{
129
			CatalogClient csc = new CatalogClient();
130
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
131
			item = catalogClient.getItem(itemId);
132
		}catch (Exception e) {
133
			logger.error("", e);
134
		}
135
		return item;
136
	}
137
 
138
 
139
    public String getServletContextPath() {
140
        return request.getContextPath();
141
    }
142
 
143
	@Override
144
	public void setServletRequest(HttpServletRequest request) {
145
		this.request = request;
146
	}
147
 
148
	@Override
149
	public void setServletResponse(HttpServletResponse response) {
150
		this.response = response;
151
	}
152
 
153
	public String getProductNameFromItem(Item item)	{
154
		return ModelUtils.extractProductNameFromItem(item);
155
	}
156
 
157
	public void setItemString(String itemString){
158
		this.itemString = itemString;
159
	}
160
 
161
	public void setId(String id){
162
 		this.id = id;
163
	}
164
 
165
	public void setItemId(long itemId) {
166
		this.itemId = itemId;
167
	}
168
 
169
	public long getItemId() {
170
		return itemId;
171
	}
172
 
173
	public void setRecommendedPrice(double recommendedPrice) {
174
		this.recommendedPrice = recommendedPrice;
175
	}
176
 
177
	public double getRecommendedPrice() {
178
		return recommendedPrice;
179
	}
180
 
181
	public void setMinPrice(double minPrice) {
182
		this.minPrice = minPrice;
183
	}
184
 
185
	public double getMinPrice() {
186
		return minPrice;
187
	}
188
 
189
	public void setMaxPrice(double maxPrice) {
190
		this.maxPrice = maxPrice;
191
	}
192
 
193
	public double getMaxPrice() {
194
		return maxPrice;
195
	}
196
 
197
	public void setMinAdvancePrice(double minAdvancePrice) {
198
		this.minAdvancePrice = minAdvancePrice;
199
	}
200
 
201
	public double getMinAdvancePrice() {
202
		return minAdvancePrice;
203
	}
204
 
205
	public void setActiveonstore(String activeonstore) {
206
		if(activeonstore.equals("on")){
207
			this.activeonstore = true;
208
		}else{
209
			this.activeonstore = false;
210
		}
211
	}
212
 
213
	public boolean isActiveonstore() {
214
		return activeonstore;
215
	}
216
 
7308 rajveer 217
	public void setFreebieItemId(long freebieItemId) {
218
		this.freebieItemId = freebieItemId;
219
	}
220
 
221
	public long getFreebieItemId() {
222
		return freebieItemId;
223
	}
224
 
225
	public void setBestDealText(String bestDealText) {
226
		this.bestDealText = bestDealText;
227
	}
228
 
229
	public String getBestDealText() {
230
		return bestDealText;
231
	}
232
 
7285 rajveer 233
}