| Line 42... |
Line 42... |
| 42 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
42 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 43 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
43 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 44 |
import com.spice.profitmandi.dao.model.UserCart;
|
44 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 45 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
45 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 46 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
46 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 47 |
import com.spice.profitmandi.dao.service.inventory.InventoryService;
|
47 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 48 |
import com.spice.profitmandi.service.pricing.PricingService;
|
48 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 49 |
import com.spice.profitmandi.web.res.DealBrands;
|
49 |
import com.spice.profitmandi.web.res.DealBrands;
|
| 50 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
50 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
| 51 |
import com.spice.profitmandi.web.res.DealsResponse;
|
51 |
import com.spice.profitmandi.web.res.DealsResponse;
|
| 52 |
import com.spice.profitmandi.web.res.FofoAvailabilityInfo;
|
52 |
import com.spice.profitmandi.web.res.FofoAvailabilityInfo;
|
| Line 62... |
Line 62... |
| 62 |
|
62 |
|
| 63 |
private static final Logger logger = LoggerFactory.getLogger(DealsController.class);
|
63 |
private static final Logger logger = LoggerFactory.getLogger(DealsController.class);
|
| 64 |
|
64 |
|
| 65 |
@Value("${python.api.host}")
|
65 |
@Value("${python.api.host}")
|
| 66 |
private String host;
|
66 |
private String host;
|
| - |
|
67 |
|
| 67 |
@Value("${python.api.port}")
|
68 |
@Value("${python.api.port}")
|
| 68 |
private int port;
|
69 |
private int port;
|
| 69 |
|
70 |
|
| 70 |
@Value("${fofo.warehouseIds}")
|
71 |
@Value("${fofo.warehouseIds}")
|
| 71 |
private int[] warehouseIds;
|
72 |
private int[] warehouseIds;
|
| Line 78... |
Line 79... |
| 78 |
|
79 |
|
| 79 |
@Autowired
|
80 |
@Autowired
|
| 80 |
private UserAccountRepository userAccountRepository;
|
81 |
private UserAccountRepository userAccountRepository;
|
| 81 |
|
82 |
|
| 82 |
@Autowired
|
83 |
@Autowired
|
| 83 |
ResponseSender<?> responseSender;
|
84 |
private ResponseSender<?> responseSender;
|
| 84 |
|
85 |
|
| 85 |
@Autowired
|
86 |
@Autowired
|
| 86 |
InventoryService inventoryService;
|
87 |
private InventoryService inventoryService;
|
| 87 |
|
88 |
|
| 88 |
|
89 |
|
| 89 |
List<String> filterableParams = Arrays.asList("brand");
|
90 |
List<String> filterableParams = Arrays.asList("brand");
|
| 90 |
|
91 |
|
| 91 |
@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
92 |
@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| Line 94... |
Line 95... |
| 94 |
@ApiOperation(value = "Get deals")
|
95 |
@ApiOperation(value = "Get deals")
|
| 95 |
public ResponseEntity<?> getDeals(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
96 |
public ResponseEntity<?> getDeals(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
| 96 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
97 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
| 97 |
@RequestParam(value = "sort", required = false) String sort,
|
98 |
@RequestParam(value = "sort", required = false) String sort,
|
| 98 |
@RequestParam(value = "direction", required = false) String direction,
|
99 |
@RequestParam(value = "direction", required = false) String direction,
|
| 99 |
@RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
|
100 |
@RequestParam(value = "filterData", required = false) String filterData) throws ProfitMandiBusinessException {
|
| 100 |
logger.info("Request " + request.getParameterMap());
|
101 |
logger.info("Request " + request.getParameterMap());
|
| 101 |
String response = null;
|
102 |
String response = null;
|
| 102 |
int userId = (int) request.getAttribute("userId");
|
103 |
int userId = (int) request.getAttribute("userId");
|
| 103 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
104 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 104 |
// TODO: move to properties
|
105 |
// TODO: move to properties
|
| Line 114... |
Line 115... |
| 114 |
params.put("source", "deals");
|
115 |
params.put("source", "deals");
|
| 115 |
if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
116 |
if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 116 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
117 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
| 117 |
}
|
118 |
}
|
| 118 |
List<Object> responseObject = new ArrayList<>();
|
119 |
List<Object> responseObject = new ArrayList<>();
|
| 119 |
try {
|
- |
|
| 120 |
response = rc.get(uri, params);
|
120 |
response = rc.get(uri, params);
|
| 121 |
} catch (Exception e) {
|
- |
|
| 122 |
logger.error("Unable to get deals", e);
|
- |
|
| 123 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
- |
|
| 124 |
request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(),
|
- |
|
| 125 |
HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, responseObject);
|
- |
|
| 126 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
- |
|
| 127 |
}
|
121 |
|
| 128 |
JsonArray result_json = Json.parse(response).asArray();
|
122 |
JsonArray result_json = Json.parse(response).asArray();
|
| 129 |
for (JsonValue j : result_json) {
|
123 |
for (JsonValue j : result_json) {
|
| 130 |
//logger.info("res " + j.asArray());
|
124 |
//logger.info("res " + j.asArray());
|
| 131 |
List<Object> innerObject = new ArrayList<>();
|
125 |
List<Object> innerObject = new ArrayList<>();
|
| 132 |
for (JsonValue jsonObject : j.asArray()) {
|
126 |
for (JsonValue jsonObject : j.asArray()) {
|
| Line 140... |
Line 134... |
| 140 |
request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,
|
134 |
request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,
|
| 141 |
responseObject);
|
135 |
responseObject);
|
| 142 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
|
136 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
|
| 143 |
}
|
137 |
}
|
| 144 |
|
138 |
|
| 145 |
private String getCommaSeparateTags(int userId) throws Throwable {
|
139 |
private String getCommaSeparateTags(int userId){
|
| 146 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
140 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| 147 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
141 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
| 148 |
List<String> strTagIds = new ArrayList<>();
|
142 |
List<String> strTagIds = new ArrayList<>();
|
| 149 |
for (Integer tagId : tagIds) {
|
143 |
for (Integer tagId : tagIds) {
|
| 150 |
strTagIds.add(String.valueOf(tagId));
|
144 |
strTagIds.add(String.valueOf(tagId));
|
| Line 248... |
Line 242... |
| 248 |
params.put("filterData", filterData);
|
242 |
params.put("filterData", filterData);
|
| 249 |
/*if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
243 |
/*if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 250 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
244 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
| 251 |
}*/
|
245 |
}*/
|
| 252 |
List<Object> responseObject = new ArrayList<>();
|
246 |
List<Object> responseObject = new ArrayList<>();
|
| 253 |
try {
|
- |
|
| 254 |
response = rc.get(uri, params);
|
247 |
response = rc.get(uri, params);
|
| 255 |
} catch (Exception e) {
|
- |
|
| 256 |
logger.error("Unable to get deals", e);
|
- |
|
| 257 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
- |
|
| 258 |
request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(),
|
- |
|
| 259 |
HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, responseObject);
|
- |
|
| 260 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
- |
|
| 261 |
}
|
248 |
|
| 262 |
JsonArray result_json = Json.parse(response).asArray();
|
249 |
JsonArray result_json = Json.parse(response).asArray();
|
| 263 |
for (JsonValue j : result_json) {
|
250 |
for (JsonValue j : result_json) {
|
| 264 |
//logger.info("res " + j.asArray());
|
251 |
//logger.info("res " + j.asArray());
|
| 265 |
List<Object> innerObject = new ArrayList<>();
|
252 |
List<Object> innerObject = new ArrayList<>();
|
| 266 |
for (JsonValue jsonObject : j.asArray()) {
|
253 |
for (JsonValue jsonObject : j.asArray()) {
|
| Line 307... |
Line 294... |
| 307 |
@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
294 |
@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 308 |
@ApiImplicitParams({
|
295 |
@ApiImplicitParams({
|
| 309 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
296 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 310 |
@ApiOperation(value = "Get brand list and count for category")
|
297 |
@ApiOperation(value = "Get brand list and count for category")
|
| 311 |
public ResponseEntity<?> getBrands(HttpServletRequest request,
|
298 |
public ResponseEntity<?> getBrands(HttpServletRequest request,
|
| 312 |
@RequestParam(value = "category_id") String category_id) {
|
299 |
@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException{
|
| 313 |
logger.info("Request " + request.getParameterMap());
|
300 |
logger.info("Request " + request.getParameterMap());
|
| 314 |
String response = null;
|
301 |
String response = null;
|
| 315 |
// TODO: move to properties
|
302 |
// TODO: move to properties
|
| 316 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
303 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
| 317 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
304 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
| 318 |
Map<String, String> params = new HashMap<>();
|
305 |
Map<String, String> params = new HashMap<>();
|
| 319 |
params.put("category_id", category_id);
|
306 |
params.put("category_id", category_id);
|
| 320 |
List<DealBrands> dealBrandsResponse = null;
|
307 |
List<DealBrands> dealBrandsResponse = null;
|
| 321 |
try {
|
- |
|
| 322 |
response = rc.get(uri, params);
|
308 |
response = rc.get(uri, params);
|
| 323 |
} catch (Exception e) {
|
- |
|
| 324 |
logger.error("Unable to get deals", e);
|
- |
|
| 325 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
- |
|
| 326 |
request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(),
|
- |
|
| 327 |
HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, dealBrandsResponse);
|
- |
|
| 328 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
- |
|
| 329 |
}
|
309 |
|
| 330 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
310 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
| 331 |
}.getType());
|
311 |
}.getType());
|
| 332 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
312 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| 333 |
request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,
|
313 |
request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,
|
| 334 |
dealBrandsResponse);
|
314 |
dealBrandsResponse);
|
| Line 337... |
Line 317... |
| 337 |
|
317 |
|
| 338 |
@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
318 |
@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 339 |
@ApiImplicitParams({
|
319 |
@ApiImplicitParams({
|
| 340 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
320 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 341 |
@ApiOperation(value = "Get unit deal object")
|
321 |
@ApiOperation(value = "Get unit deal object")
|
| 342 |
public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id) {
|
322 |
public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
|
| - |
|
323 |
throws ProfitMandiBusinessException{
|
| 343 |
String response = null;
|
324 |
String response = null;
|
| 344 |
// TODO: move to properties
|
325 |
// TODO: move to properties
|
| 345 |
String uri = "getDealById/" + id;
|
326 |
String uri = "getDealById/" + id;
|
| 346 |
System.out.println("Unit deal " + uri);
|
327 |
System.out.println("Unit deal " + uri);
|
| 347 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
328 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
| 348 |
Map<String, String> params = new HashMap<>();
|
329 |
Map<String, String> params = new HashMap<>();
|
| 349 |
DealsResponse dealsResponse = null;
|
330 |
DealsResponse dealsResponse = null;
|
| 350 |
try {
|
- |
|
| 351 |
response = rc.get(uri, params);
|
331 |
response = rc.get(uri, params);
|
| 352 |
} catch (Exception e) {
|
- |
|
| 353 |
logger.error("Unable to get deals", e);
|
- |
|
| 354 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
- |
|
| 355 |
request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(),
|
- |
|
| 356 |
HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, dealsResponse);
|
- |
|
| 357 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
- |
|
| 358 |
}
|
332 |
|
| 359 |
JsonObject result_json = Json.parse(response).asObject();
|
333 |
JsonObject result_json = Json.parse(response).asObject();
|
| 360 |
if (!result_json.isEmpty()) {
|
334 |
if (!result_json.isEmpty()) {
|
| 361 |
dealsResponse = new Gson().fromJson(response, DealsResponse.class);
|
335 |
dealsResponse = new Gson().fromJson(response, DealsResponse.class);
|
| 362 |
}
|
336 |
}
|
| 363 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
337 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| Line 377... |
Line 351... |
| 377 |
}
|
351 |
}
|
| 378 |
|
352 |
|
| 379 |
@ApiImplicitParams({
|
353 |
@ApiImplicitParams({
|
| 380 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
354 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 381 |
@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
355 |
@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 382 |
public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws Throwable {
|
356 |
public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
|
| 383 |
StringBuffer sb = new StringBuffer("/getDealsForNotification/");
|
357 |
StringBuffer sb = new StringBuffer("/getDealsForNotification/");
|
| 384 |
String uri = sb.append(skus).toString();
|
358 |
String uri = sb.append(skus).toString();
|
| 385 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
359 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
| 386 |
String response = rc.get(uri, new HashMap<>());
|
360 |
String response = rc.get(uri, new HashMap<>());
|
| 387 |
JsonArray result_json = Json.parse(response).asArray();
|
361 |
JsonArray result_json = Json.parse(response).asArray();
|