| Line 8... |
Line 8... |
| 8 |
import java.util.Map;
|
8 |
import java.util.Map;
|
| 9 |
|
9 |
|
| 10 |
import javax.servlet.http.HttpServletRequest;
|
10 |
import javax.servlet.http.HttpServletRequest;
|
| 11 |
|
11 |
|
| 12 |
import org.apache.commons.lang3.StringUtils;
|
12 |
import org.apache.commons.lang3.StringUtils;
|
| - |
|
13 |
import org.apache.http.conn.HttpHostConnectException;
|
| 13 |
import org.json.JSONArray;
|
14 |
import org.json.JSONArray;
|
| 14 |
import org.json.JSONObject;
|
15 |
import org.json.JSONObject;
|
| 15 |
import org.slf4j.Logger;
|
16 |
import org.slf4j.Logger;
|
| 16 |
import org.slf4j.LoggerFactory;
|
17 |
import org.slf4j.LoggerFactory;
|
| 17 |
import org.springframework.beans.factory.annotation.Autowired;
|
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
| Line 116... |
Line 117... |
| 116 |
//show only skus belonging to that specific
|
117 |
//show only skus belonging to that specific
|
| 117 |
//else use normal flow
|
118 |
//else use normal flow
|
| 118 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
119 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 119 |
// TODO: move to properties
|
120 |
// TODO: move to properties
|
| 120 |
String uri = "/deals/" + userId;
|
121 |
String uri = "/deals/" + userId;
|
| 121 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
122 |
RestClient rc = new RestClient();
|
| 122 |
Map<String, String> params = new HashMap<>();
|
123 |
Map<String, String> params = new HashMap<>();
|
| 123 |
params.put("offset", offset);
|
124 |
params.put("offset", offset);
|
| 124 |
params.put("limit", limit);
|
125 |
params.put("limit", limit);
|
| 125 |
params.put("categoryId", categoryId);
|
126 |
params.put("categoryId", categoryId);
|
| 126 |
params.put("direction", direction);
|
127 |
params.put("direction", direction);
|
| Line 129... |
Line 130... |
| 129 |
params.put("source", "deals");
|
130 |
params.put("source", "deals");
|
| 130 |
if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
131 |
if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 131 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
132 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
| 132 |
}
|
133 |
}
|
| 133 |
List<Object> responseObject = new ArrayList<>();
|
134 |
List<Object> responseObject = new ArrayList<>();
|
| - |
|
135 |
try {
|
| 134 |
response = rc.get(uri, params);
|
136 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
| - |
|
137 |
} catch (HttpHostConnectException e) {
|
| - |
|
138 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| - |
|
139 |
}
|
| 135 |
|
140 |
|
| 136 |
JsonArray result_json = Json.parse(response).asArray();
|
141 |
JsonArray result_json = Json.parse(response).asArray();
|
| 137 |
for (JsonValue j : result_json) {
|
142 |
for (JsonValue j : result_json) {
|
| 138 |
//logger.info("res " + j.asArray());
|
143 |
//logger.info("res " + j.asArray());
|
| 139 |
List<Object> innerObject = new ArrayList<>();
|
144 |
List<Object> innerObject = new ArrayList<>();
|
| Line 166... |
Line 171... |
| 166 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
171 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 167 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
172 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 168 |
if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
173 |
if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 169 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
174 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| 170 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
175 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
| 171 |
RestClient rc = new RestClient(SchemeType.HTTP, "dtr", 8984);
|
176 |
RestClient rc = new RestClient();
|
| 172 |
Map<String, String> params = new HashMap<>();
|
177 |
Map<String, String> params = new HashMap<>();
|
| 173 |
List<String> mandatoryQ = new ArrayList<>();
|
178 |
List<String> mandatoryQ = new ArrayList<>();
|
| 174 |
if(brand != null) {
|
179 |
if(brand != null) {
|
| 175 |
|
180 |
|
| 176 |
mandatoryQ.add(String.format("+{!parent which=\"brand_s=%s\"} tagId_i:(%s)", brand, StringUtils.join(tagIds, " ")));
|
181 |
mandatoryQ.add(String.format("+{!parent which=\"brand_s=%s\"} tagId_i:(%s)", brand, StringUtils.join(tagIds, " ")));
|
| Line 181... |
Line 186... |
| 181 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
186 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| 182 |
params.put("sort", "rank_i asc");
|
187 |
params.put("sort", "rank_i asc");
|
| 183 |
params.put("start", String.valueOf(offset));
|
188 |
params.put("start", String.valueOf(offset));
|
| 184 |
params.put("rows", String.valueOf(limit));
|
189 |
params.put("rows", String.valueOf(limit));
|
| 185 |
params.put("wt", "json");
|
190 |
params.put("wt", "json");
|
| 186 |
logger.info(rc.getUrl());
|
191 |
String response = null;
|
| - |
|
192 |
try {
|
| 187 |
String response =rc.get("solr/demo/select", params);
|
193 |
response =rc.get(SchemeType.HTTP, "dtr", 8984, "solr/demo/select", params);
|
| - |
|
194 |
} catch (HttpHostConnectException e) {
|
| - |
|
195 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| - |
|
196 |
}
|
| 188 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
197 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 189 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
198 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| 190 |
for(int i=0; i < docs.length(); i++) {
|
199 |
for(int i=0; i < docs.length(); i++) {
|
| 191 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
200 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
| 192 |
JSONObject doc = docs.getJSONObject(i);
|
201 |
JSONObject doc = docs.getJSONObject(i);
|
| Line 257... |
Line 266... |
| 257 |
logger.info("Request " + request.getParameterMap());
|
266 |
logger.info("Request " + request.getParameterMap());
|
| 258 |
String response = null;
|
267 |
String response = null;
|
| 259 |
int userId = (int) request.getAttribute("userId");
|
268 |
int userId = (int) request.getAttribute("userId");
|
| 260 |
|
269 |
|
| 261 |
String uri = "/deals/" + userId;
|
270 |
String uri = "/deals/" + userId;
|
| 262 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
271 |
RestClient rc = new RestClient();
|
| 263 |
Map<String, String> params = new HashMap<>();
|
272 |
Map<String, String> params = new HashMap<>();
|
| 264 |
params.put("offset", offset);
|
273 |
params.put("offset", offset);
|
| 265 |
params.put("limit", limit);
|
274 |
params.put("limit", limit);
|
| 266 |
params.put("categoryId", categoryId);
|
275 |
params.put("categoryId", categoryId);
|
| 267 |
params.put("direction", direction);
|
276 |
params.put("direction", direction);
|
| Line 270... |
Line 279... |
| 270 |
params.put("filterData", filterData);
|
279 |
params.put("filterData", filterData);
|
| 271 |
/*if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
280 |
/*if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 272 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
281 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
| 273 |
}*/
|
282 |
}*/
|
| 274 |
List<Object> responseObject = new ArrayList<>();
|
283 |
List<Object> responseObject = new ArrayList<>();
|
| - |
|
284 |
try {
|
| 275 |
response = rc.get(uri, params);
|
285 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
| - |
|
286 |
} catch (HttpHostConnectException e) {
|
| - |
|
287 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| - |
|
288 |
}
|
| 276 |
|
289 |
|
| 277 |
JsonArray result_json = Json.parse(response).asArray();
|
290 |
JsonArray result_json = Json.parse(response).asArray();
|
| 278 |
for (JsonValue j : result_json) {
|
291 |
for (JsonValue j : result_json) {
|
| 279 |
//logger.info("res " + j.asArray());
|
292 |
//logger.info("res " + j.asArray());
|
| 280 |
List<Object> innerObject = new ArrayList<>();
|
293 |
List<Object> innerObject = new ArrayList<>();
|
| Line 324... |
Line 337... |
| 324 |
@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException{
|
337 |
@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException{
|
| 325 |
logger.info("Request " + request.getParameterMap());
|
338 |
logger.info("Request " + request.getParameterMap());
|
| 326 |
String response = null;
|
339 |
String response = null;
|
| 327 |
// TODO: move to properties
|
340 |
// TODO: move to properties
|
| 328 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
341 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
| 329 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
342 |
RestClient rc = new RestClient();
|
| 330 |
Map<String, String> params = new HashMap<>();
|
343 |
Map<String, String> params = new HashMap<>();
|
| 331 |
params.put("category_id", category_id);
|
344 |
params.put("category_id", category_id);
|
| 332 |
List<DealBrands> dealBrandsResponse = null;
|
345 |
List<DealBrands> dealBrandsResponse = null;
|
| - |
|
346 |
try {
|
| 333 |
response = rc.get(uri, params);
|
347 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
| - |
|
348 |
} catch (HttpHostConnectException e) {
|
| - |
|
349 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| - |
|
350 |
}
|
| 334 |
|
351 |
|
| 335 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
352 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
| 336 |
}.getType());
|
353 |
}.getType());
|
| 337 |
|
354 |
|
| 338 |
return responseSender.ok(dealBrandsResponse);
|
355 |
return responseSender.ok(dealBrandsResponse);
|
| Line 346... |
Line 363... |
| 346 |
throws ProfitMandiBusinessException{
|
363 |
throws ProfitMandiBusinessException{
|
| 347 |
String response = null;
|
364 |
String response = null;
|
| 348 |
// TODO: move to properties
|
365 |
// TODO: move to properties
|
| 349 |
String uri = "getDealById/" + id;
|
366 |
String uri = "getDealById/" + id;
|
| 350 |
System.out.println("Unit deal " + uri);
|
367 |
System.out.println("Unit deal " + uri);
|
| 351 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
368 |
RestClient rc = new RestClient();
|
| 352 |
Map<String, String> params = new HashMap<>();
|
369 |
Map<String, String> params = new HashMap<>();
|
| 353 |
DealsResponse dealsResponse = null;
|
370 |
DealsResponse dealsResponse = null;
|
| - |
|
371 |
try {
|
| 354 |
response = rc.get(uri, params);
|
372 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
| - |
|
373 |
} catch (HttpHostConnectException e) {
|
| - |
|
374 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| - |
|
375 |
}
|
| 355 |
|
376 |
|
| 356 |
JsonObject result_json = Json.parse(response).asObject();
|
377 |
JsonObject result_json = Json.parse(response).asObject();
|
| 357 |
if (!result_json.isEmpty()) {
|
378 |
if (!result_json.isEmpty()) {
|
| 358 |
dealsResponse = new Gson().fromJson(response, DealsResponse.class);
|
379 |
dealsResponse = new Gson().fromJson(response, DealsResponse.class);
|
| 359 |
Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
|
380 |
Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
|
| Line 383... |
Line 404... |
| 383 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
404 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 384 |
@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
405 |
@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 385 |
public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
|
406 |
public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
|
| 386 |
StringBuffer sb = new StringBuffer("/getDealsForNotification/");
|
407 |
StringBuffer sb = new StringBuffer("/getDealsForNotification/");
|
| 387 |
String uri = sb.append(skus).toString();
|
408 |
String uri = sb.append(skus).toString();
|
| 388 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
409 |
RestClient rc = new RestClient();
|
| - |
|
410 |
String response;
|
| - |
|
411 |
try {
|
| 389 |
String response = rc.get(uri, new HashMap<>());
|
412 |
response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
|
| - |
|
413 |
}catch (HttpHostConnectException e) {
|
| - |
|
414 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| - |
|
415 |
}
|
| 390 |
JsonArray result_json = Json.parse(response).asArray();
|
416 |
JsonArray result_json = Json.parse(response).asArray();
|
| 391 |
List<Object> responseObject = new ArrayList<>();
|
417 |
List<Object> responseObject = new ArrayList<>();
|
| 392 |
for (JsonValue j : result_json) {
|
418 |
for (JsonValue j : result_json) {
|
| 393 |
//logger.info("res " + j.asArray());
|
419 |
//logger.info("res " + j.asArray());
|
| 394 |
List<Object> innerObject = new ArrayList<>();
|
420 |
List<Object> innerObject = new ArrayList<>();
|