Subversion Repositories SmartDukaan

Rev

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