| 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();
|
|
|
70 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
|
| 7382 |
rajveer |
71 |
catalogClient.updateStorePricing(sp, allcolors);
|
| 7285 |
rajveer |
72 |
Item item = getItem(itemId);
|
|
|
73 |
if(item.isActiveOnStore() != isActiveonstore()){
|
|
|
74 |
item.setActiveOnStore(isActiveonstore());
|
|
|
75 |
catalogClient.updateItem(item);
|
|
|
76 |
}
|
| 7382 |
rajveer |
77 |
addActionError("Pricing successfully updated");
|
| 7285 |
rajveer |
78 |
} catch (TException e) {
|
|
|
79 |
logger.error("", e);
|
|
|
80 |
} catch (CatalogServiceException e) {
|
|
|
81 |
e.printStackTrace();
|
| 7382 |
rajveer |
82 |
addActionError("Unable to update pricing because: " + e.getMessage());
|
| 7285 |
rajveer |
83 |
}
|
| 7382 |
rajveer |
84 |
setId(Long.toString(itemId));
|
| 7285 |
rajveer |
85 |
return "index";
|
|
|
86 |
}
|
|
|
87 |
|
| 7382 |
rajveer |
88 |
public Collection<String> getMessages(){
|
|
|
89 |
return getActionErrors();
|
|
|
90 |
}
|
|
|
91 |
|
| 7285 |
rajveer |
92 |
public List<Item> searchItem(){
|
|
|
93 |
List<Item> items = null;
|
|
|
94 |
if(itemString != null){
|
|
|
95 |
try{
|
|
|
96 |
CatalogClient csc = new CatalogClient();
|
|
|
97 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
|
|
|
98 |
List<String> searchTerms = Arrays.asList(itemString.split(" "));
|
|
|
99 |
items = catalogClient.searchItemsInRange(searchTerms, 0, 50);
|
|
|
100 |
}catch (Exception e) {
|
|
|
101 |
logger.error("", e);
|
|
|
102 |
}
|
| 7382 |
rajveer |
103 |
}else if(id == null)
|
|
|
104 |
{
|
|
|
105 |
try{
|
|
|
106 |
CatalogClient csc = new CatalogClient();
|
|
|
107 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
|
|
|
108 |
items = catalogClient.getLatestArrivals();
|
|
|
109 |
}catch (Exception e) {
|
|
|
110 |
logger.error("", e);
|
|
|
111 |
}
|
|
|
112 |
}
|
| 7285 |
rajveer |
113 |
return items;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
public StorePricing getStorePricing(){
|
|
|
118 |
StorePricing sp = null;
|
|
|
119 |
if(id != null){
|
|
|
120 |
try{
|
|
|
121 |
long itemId = Long.parseLong(id);
|
|
|
122 |
CatalogClient csc = new CatalogClient();
|
|
|
123 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
|
|
|
124 |
sp = catalogClient.getStorePricing(itemId);
|
|
|
125 |
}catch (Exception e) {
|
|
|
126 |
logger.error("", e);
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
return sp;
|
|
|
130 |
}
|
|
|
131 |
|
| 7306 |
rajveer |
132 |
public List<StorePricing> getStorePricings(List<Item> items){
|
|
|
133 |
List<Long> itemIds = new ArrayList<Long>();
|
|
|
134 |
List<StorePricing> sps = null;
|
|
|
135 |
try{
|
|
|
136 |
for(Item item: items){
|
|
|
137 |
itemIds.add(item.getId());
|
|
|
138 |
}
|
|
|
139 |
CatalogClient csc = new CatalogClient();
|
|
|
140 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
|
|
|
141 |
sps = catalogClient.getStorePricings(itemIds);
|
|
|
142 |
}catch (Exception e) {
|
|
|
143 |
logger.error("", e);
|
|
|
144 |
}
|
|
|
145 |
return sps;
|
|
|
146 |
}
|
|
|
147 |
|
| 7285 |
rajveer |
148 |
public Item getItem(long itemId){
|
|
|
149 |
Item item = null;
|
|
|
150 |
try{
|
|
|
151 |
CatalogClient csc = new CatalogClient();
|
|
|
152 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
|
|
|
153 |
item = catalogClient.getItem(itemId);
|
|
|
154 |
}catch (Exception e) {
|
|
|
155 |
logger.error("", e);
|
|
|
156 |
}
|
|
|
157 |
return item;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
public String getServletContextPath() {
|
|
|
162 |
return request.getContextPath();
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
@Override
|
|
|
166 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
167 |
this.request = request;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
@Override
|
|
|
171 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
172 |
this.response = response;
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
public String getProductNameFromItem(Item item) {
|
|
|
176 |
return ModelUtils.extractProductNameFromItem(item);
|
|
|
177 |
}
|
|
|
178 |
|
| 7382 |
rajveer |
179 |
public String getItemString(){
|
|
|
180 |
return this.itemString;
|
|
|
181 |
}
|
|
|
182 |
|
| 7285 |
rajveer |
183 |
public void setItemString(String itemString){
|
|
|
184 |
this.itemString = itemString;
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
public void setId(String id){
|
|
|
188 |
this.id = id;
|
|
|
189 |
}
|
|
|
190 |
|
| 7382 |
rajveer |
191 |
public String getId(){
|
|
|
192 |
return this.id;
|
|
|
193 |
}
|
|
|
194 |
|
| 7285 |
rajveer |
195 |
public void setItemId(long itemId) {
|
|
|
196 |
this.itemId = itemId;
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
public long getItemId() {
|
|
|
200 |
return itemId;
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
public void setRecommendedPrice(double recommendedPrice) {
|
|
|
204 |
this.recommendedPrice = recommendedPrice;
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
public double getRecommendedPrice() {
|
|
|
208 |
return recommendedPrice;
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
public void setMinPrice(double minPrice) {
|
|
|
212 |
this.minPrice = minPrice;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
public double getMinPrice() {
|
|
|
216 |
return minPrice;
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
public void setMaxPrice(double maxPrice) {
|
|
|
220 |
this.maxPrice = maxPrice;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
public double getMaxPrice() {
|
|
|
224 |
return maxPrice;
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
public void setMinAdvancePrice(double minAdvancePrice) {
|
|
|
228 |
this.minAdvancePrice = minAdvancePrice;
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
public double getMinAdvancePrice() {
|
|
|
232 |
return minAdvancePrice;
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
public void setActiveonstore(String activeonstore) {
|
|
|
236 |
if(activeonstore.equals("on")){
|
|
|
237 |
this.activeonstore = true;
|
|
|
238 |
}else{
|
|
|
239 |
this.activeonstore = false;
|
|
|
240 |
}
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
public boolean isActiveonstore() {
|
|
|
244 |
return activeonstore;
|
|
|
245 |
}
|
|
|
246 |
|
| 7308 |
rajveer |
247 |
public void setFreebieItemId(long freebieItemId) {
|
|
|
248 |
this.freebieItemId = freebieItemId;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
public long getFreebieItemId() {
|
|
|
252 |
return freebieItemId;
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
public void setBestDealText(String bestDealText) {
|
|
|
256 |
this.bestDealText = bestDealText;
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
public String getBestDealText() {
|
|
|
260 |
return bestDealText;
|
|
|
261 |
}
|
|
|
262 |
|
| 7351 |
rajveer |
263 |
public double getAbsoluteMinPrice() {
|
|
|
264 |
return absoluteMinPrice;
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
public void setAbsoluteMinPrice(double absoluteMinPrice) {
|
|
|
268 |
this.absoluteMinPrice = absoluteMinPrice;
|
|
|
269 |
}
|
| 7382 |
rajveer |
270 |
|
|
|
271 |
public void setAllcolors(String allcolors) {
|
|
|
272 |
if(allcolors.equals("on")){
|
|
|
273 |
this.allcolors = true;
|
|
|
274 |
}else{
|
|
|
275 |
this.allcolors = false;
|
|
|
276 |
}
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
public boolean isAllcolors() {
|
|
|
280 |
return allcolors;
|
|
|
281 |
}
|
| 7351 |
rajveer |
282 |
|
| 7285 |
rajveer |
283 |
}
|