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