| Line 69... |
Line 69... |
| 69 |
|
69 |
|
| 70 |
private static final Logger logger = LogManager.getLogger(DealsController.class);
|
70 |
private static final Logger logger = LogManager.getLogger(DealsController.class);
|
| 71 |
|
71 |
|
| 72 |
@Value("${python.api.host}")
|
72 |
@Value("${python.api.host}")
|
| 73 |
private String host;
|
73 |
private String host;
|
| 74 |
|
74 |
|
| 75 |
@Value("${python.api.port}")
|
75 |
@Value("${python.api.port}")
|
| 76 |
private int port;
|
76 |
private int port;
|
| 77 |
|
77 |
|
| 78 |
//This is now unused as we are not supporting multiple companies.
|
78 |
// This is now unused as we are not supporting multiple companies.
|
| 79 |
@Value("${gadgetCops.invoice.cc}")
|
79 |
@Value("${gadgetCops.invoice.cc}")
|
| 80 |
private String[] ccGadgetCopInvoiceTo;
|
80 |
private String[] ccGadgetCopInvoiceTo;
|
| 81 |
|
81 |
|
| 82 |
@Autowired
|
82 |
@Autowired
|
| 83 |
private PricingService pricingService;
|
83 |
private PricingService pricingService;
|
| 84 |
|
84 |
|
| 85 |
@Autowired
|
85 |
@Autowired
|
| 86 |
private Mongo mongoClient;
|
86 |
private Mongo mongoClient;
|
| 87 |
|
87 |
|
| 88 |
@Autowired
|
88 |
@Autowired
|
| 89 |
private UserAccountRepository userAccountRepository;
|
89 |
private UserAccountRepository userAccountRepository;
|
| 90 |
|
- |
|
| 91 |
|
90 |
|
| 92 |
@Autowired
|
91 |
@Autowired
|
| 93 |
private ResponseSender<?> responseSender;
|
92 |
private ResponseSender<?> responseSender;
|
| 94 |
|
93 |
|
| 95 |
@Autowired
|
94 |
@Autowired
|
| 96 |
private TagListingRepository tagListingRepository;
|
95 |
private TagListingRepository tagListingRepository;
|
| 97 |
|
96 |
|
| 98 |
@Autowired
|
97 |
@Autowired
|
| 99 |
private ItemRepository itemRepository;
|
98 |
private ItemRepository itemRepository;
|
| 100 |
|
99 |
|
| 101 |
@Autowired
|
100 |
@Autowired
|
| 102 |
private RoleManager roleManagerService;
|
101 |
private RoleManager roleManagerService;
|
| 103 |
|
- |
|
| 104 |
|
102 |
|
| 105 |
List<String> filterableParams = Arrays.asList("brand");
|
103 |
List<String> filterableParams = Arrays.asList("brand");
|
| 106 |
|
104 |
|
| 107 |
@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
105 |
@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 108 |
@ApiImplicitParams({
|
106 |
@ApiImplicitParams({
|
| 109 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
107 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 110 |
@ApiOperation(value = "Get deals")
|
108 |
@ApiOperation(value = "Get deals")
|
| 111 |
public ResponseEntity<?> getDeals(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
109 |
public ResponseEntity<?> getDeals(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
| 112 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
110 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
| 113 |
@RequestParam(value = "sort", required = false) String sort,
|
111 |
@RequestParam(value = "sort", required = false) String sort,
|
| 114 |
@RequestParam(value = "direction", required = false) String direction,
|
112 |
@RequestParam(value = "direction", required = false) String direction,
|
| 115 |
@RequestParam(value = "filterData", required = false) String filterData) throws ProfitMandiBusinessException {
|
113 |
@RequestParam(value = "filterData", required = false) String filterData)
|
| - |
|
114 |
throws ProfitMandiBusinessException {
|
| 116 |
logger.info("Request " + request.getParameterMap());
|
115 |
logger.info("Request " + request.getParameterMap());
|
| 117 |
String response = null;
|
116 |
String response = null;
|
| 118 |
int userId = (int) request.getAttribute("userId");
|
117 |
int userId = (int) request.getAttribute("userId");
|
| 119 |
|
118 |
|
| 120 |
//If pincode belongs to Specific warehouse marked
|
119 |
// If pincode belongs to Specific warehouse marked
|
| 121 |
//availability should be fetched for that warehouse only
|
120 |
// availability should be fetched for that warehouse only
|
| 122 |
//show only skus belonging to that specific
|
121 |
// show only skus belonging to that specific
|
| 123 |
//else use normal flow
|
122 |
// else use normal flow
|
| 124 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
123 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 125 |
// TODO: move to properties
|
124 |
// TODO: move to properties
|
| 126 |
String uri = "/deals/" + userId;
|
125 |
String uri = "/deals/" + userId;
|
| 127 |
RestClient rc = new RestClient();
|
126 |
RestClient rc = new RestClient();
|
| 128 |
Map<String, String> params = new HashMap<>();
|
127 |
Map<String, String> params = new HashMap<>();
|
| Line 136... |
Line 135... |
| 136 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
135 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
| 137 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
136 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
| 138 |
}
|
137 |
}
|
| 139 |
List<Object> responseObject = new ArrayList<>();
|
138 |
List<Object> responseObject = new ArrayList<>();
|
| 140 |
try {
|
139 |
try {
|
| 141 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
140 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
| 142 |
} catch (HttpHostConnectException e) {
|
141 |
} catch (HttpHostConnectException e) {
|
| 143 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
142 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 144 |
}
|
143 |
}
|
| 145 |
|
144 |
|
| 146 |
JsonArray result_json = Json.parse(response).asArray();
|
145 |
JsonArray result_json = Json.parse(response).asArray();
|
| 147 |
for (JsonValue j : result_json) {
|
146 |
for (JsonValue j : result_json) {
|
| 148 |
//logger.info("res " + j.asArray());
|
147 |
// logger.info("res " + j.asArray());
|
| 149 |
List<Object> innerObject = new ArrayList<>();
|
148 |
List<Object> innerObject = new ArrayList<>();
|
| 150 |
for (JsonValue jsonObject : j.asArray()) {
|
149 |
for (JsonValue jsonObject : j.asArray()) {
|
| 151 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
150 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
| 152 |
}
|
151 |
}
|
| 153 |
if (innerObject.size() > 0) {
|
152 |
if (innerObject.size() > 0) {
|
| Line 155... |
Line 154... |
| 155 |
}
|
154 |
}
|
| 156 |
}
|
155 |
}
|
| 157 |
return responseSender.ok(responseObject);
|
156 |
return responseSender.ok(responseObject);
|
| 158 |
}
|
157 |
}
|
| 159 |
|
158 |
|
| 160 |
private String getCommaSeparateTags(int userId){
|
159 |
private String getCommaSeparateTags(int userId) {
|
| 161 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
160 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| 162 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
161 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
| 163 |
List<String> strTagIds = new ArrayList<>();
|
162 |
List<String> strTagIds = new ArrayList<>();
|
| 164 |
for (Integer tagId : tagIds) {
|
163 |
for (Integer tagId : tagIds) {
|
| 165 |
strTagIds.add(String.valueOf(tagId));
|
164 |
strTagIds.add(String.valueOf(tagId));
|
| Line 170... |
Line 169... |
| 170 |
@ApiImplicitParams({
|
169 |
@ApiImplicitParams({
|
| 171 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
170 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 172 |
@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
171 |
@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 173 |
public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
172 |
public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
| 174 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
173 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
| - |
|
174 |
@RequestParam(value = "sort", required = false) String sort,
|
| 175 |
@RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "brand", required = false) String brand,
|
175 |
@RequestParam(value = "brand", required = false) String brand,
|
| 176 |
@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
|
176 |
@RequestParam(value = "hotDeal", required = false) boolean hotDeal) throws Throwable {
|
| 177 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
177 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
| 178 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
178 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 179 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
179 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
| 180 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
180 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| 181 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
181 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
|
| 182 |
RestClient rc = new RestClient();
|
182 |
RestClient rc = new RestClient();
|
| 183 |
Map<String, String> params = new HashMap<>();
|
183 |
Map<String, String> params = new HashMap<>();
|
| 184 |
List<String> mandatoryQ = new ArrayList<>();
|
184 |
List<String> mandatoryQ = new ArrayList<>();
|
| 185 |
if(brand != null) {
|
185 |
if (brand != null) {
|
| 186 |
|
186 |
|
| 187 |
mandatoryQ.add(String.format("+{!parent which=\"brand_s=%s\"} tagId_i:(%s)", brand, StringUtils.join(tagIds, " ")));
|
187 |
mandatoryQ.add(String.format("+{!parent which=\"brand_s=%s\"} tagId_i:(%s)", brand,
|
| - |
|
188 |
StringUtils.join(tagIds, " ")));
|
| 188 |
} else if (hotDeal) {
|
189 |
} else if (hotDeal) {
|
| 189 |
mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
|
190 |
mandatoryQ.add(String.format("+{!parent which=\"hot_deals_b=true\"} tagId_i:(%s)",
|
| - |
|
191 |
StringUtils.join(tagIds, " ")));
|
| 190 |
} else {
|
192 |
} else {
|
| - |
|
193 |
mandatoryQ.add(
|
| 191 |
mandatoryQ.add(String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
|
194 |
String.format("+{!parent which=\"id:catalog*\"} tagId_i:(%s)", StringUtils.join(tagIds, " ")));
|
| 192 |
}
|
195 |
}
|
| 193 |
params.put("q", StringUtils.join(mandatoryQ," "));
|
196 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
| 194 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
197 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| 195 |
params.put("sort", "rank_i asc");
|
198 |
params.put("sort", "rank_i asc");
|
| 196 |
params.put("start", String.valueOf(offset));
|
199 |
params.put("start", String.valueOf(offset));
|
| 197 |
params.put("rows", String.valueOf(limit));
|
200 |
params.put("rows", String.valueOf(limit));
|
| 198 |
params.put("wt", "json");
|
201 |
params.put("wt", "json");
|
| 199 |
String response = null;
|
202 |
String response = null;
|
| 200 |
try {
|
203 |
try {
|
| 201 |
response =rc.get(SchemeType.HTTP, "dtr", 8984, "solr/demo/select", params);
|
204 |
response = rc.get(SchemeType.HTTP, "dtr", 8984, "solr/demo/select", params);
|
| 202 |
} catch (HttpHostConnectException e) {
|
205 |
} catch (HttpHostConnectException e) {
|
| 203 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
206 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 204 |
}
|
207 |
}
|
| 205 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
208 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 206 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
209 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| 207 |
Map<Integer, TagListing> itemTagListingMap = null;
|
210 |
Map<Integer, TagListing> itemTagListingMap = null;
|
| 208 |
if(hotDeal) {
|
211 |
if (hotDeal) {
|
| 209 |
HashSet<Integer> itemsSet = new HashSet<>();
|
212 |
HashSet<Integer> itemsSet = new HashSet<>();
|
| 210 |
for(int i=0; i < docs.length(); i++) {
|
213 |
for (int i = 0; i < docs.length(); i++) {
|
| 211 |
JSONObject doc = docs.getJSONObject(i);
|
214 |
JSONObject doc = docs.getJSONObject(i);
|
| 212 |
for(int j=0; j< doc.getJSONArray("_childDocuments_").length(); j++) {
|
215 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
| 213 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
216 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| 214 |
int itemId = childItem.getInt("itemId_i");
|
217 |
int itemId = childItem.getInt("itemId_i");
|
| 215 |
itemsSet.add(itemId);
|
218 |
itemsSet.add(itemId);
|
| - |
|
219 |
}
|
| 216 |
}
|
220 |
}
|
| - |
|
221 |
itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds))
|
| - |
|
222 |
.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 217 |
}
|
223 |
}
|
| 218 |
itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemsSet, new HashSet<>(tagIds)).stream()
|
- |
|
| 219 |
.collect(Collectors.toMap(x->x.getItemId(), x->x));
|
- |
|
| 220 |
}
|
- |
|
| 221 |
|
224 |
|
| 222 |
for(int i=0; i < docs.length(); i++) {
|
225 |
for (int i = 0; i < docs.length(); i++) {
|
| 223 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
226 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
| 224 |
JSONObject doc = docs.getJSONObject(i);
|
227 |
JSONObject doc = docs.getJSONObject(i);
|
| 225 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
228 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
| 226 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
229 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
| 227 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
230 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
| 228 |
ffdr.setTitle(doc.getString("title_s"));
|
231 |
ffdr.setTitle(doc.getString("title_s"));
|
| 229 |
ffdr.setBrand(doc.getString("brand_s"));
|
232 |
ffdr.setBrand(doc.getString("brand_s"));
|
| 230 |
|
233 |
|
| 231 |
for(int j=0; j< doc.getJSONArray("_childDocuments_").length(); j++) {
|
234 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
| 232 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
235 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
| 233 |
int itemId = childItem.getInt("itemId_i");
|
236 |
int itemId = childItem.getInt("itemId_i");
|
| - |
|
237 |
if (hotDeal) {
|
| 234 |
TagListing tl = itemTagListingMap.get(itemId);
|
238 |
TagListing tl = itemTagListingMap.get(itemId);
|
| 235 |
if(hotDeal && !tl.isHotDeals()) {
|
239 |
if(!tl.isHotDeals()) {
|
| 236 |
continue;
|
240 |
continue;
|
| - |
|
241 |
}
|
| 237 |
}
|
242 |
}
|
| 238 |
float sellingPrice = (float)childItem.getDouble("sellingPrice_f");
|
243 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
| 239 |
if(fofoAvailabilityInfoMap.containsKey(itemId)) {
|
244 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
| 240 |
if(fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
245 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
| 241 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
246 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
| 242 |
fofoAvailabilityInfoMap.get(itemId).setMop((float)childItem.getDouble("mop_f"));
|
247 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
| 243 |
}
|
248 |
}
|
| 244 |
} else {
|
249 |
} else {
|
| 245 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
250 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
| 246 |
fdi.setSellingPrice((float)childItem.getDouble("sellingPrice_f"));
|
251 |
fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
|
| 247 |
fdi.setMop((float)childItem.getDouble("mop_f"));
|
252 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
| 248 |
fdi.setColor(childItem.has("color_s")?childItem.getString("color_s"): "");
|
253 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
| 249 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
254 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
| 250 |
fdi.setItem_id(itemId);
|
255 |
fdi.setItem_id(itemId);
|
| 251 |
/*int totalAvailability = 0;
|
- |
|
| 252 |
//Using item availability cache for now but can be changed to use caching later.
|
- |
|
| 253 |
try {
|
256 |
/*
|
| 254 |
ItemAvailabilityCache iac = itemAvailabilityCacheRepository.selectByItemId(itemId);
|
257 |
* int totalAvailability = 0; //Using item availability cache for now but can be
|
| 255 |
totalAvailability = iac.getTotalAvailability();
|
258 |
* changed to use caching later. try { ItemAvailabilityCache iac =
|
| 256 |
} catch (Exception e) {}
|
259 |
* itemAvailabilityCacheRepository.selectByItemId(itemId); totalAvailability =
|
| 257 |
if(totalAvailability <= 0){
|
260 |
* iac.getTotalAvailability(); } catch (Exception e) {} if(totalAvailability <=
|
| 258 |
continue;
|
261 |
* 0){ continue; }
|
| 259 |
}*/
|
262 |
*/
|
| 260 |
Item item = itemRepository.selectById(itemId);
|
263 |
Item item = itemRepository.selectById(itemId);
|
| 261 |
//In case its tampered glass moq should be 5
|
264 |
// In case its tampered glass moq should be 5
|
| 262 |
if(item.getCategoryId()==10020) {
|
265 |
if (item.getCategoryId() == 10020) {
|
| 263 |
fdi.setMinBuyQuantity(5);
|
266 |
fdi.setMinBuyQuantity(5);
|
| 264 |
} else {
|
267 |
} else {
|
| 265 |
fdi.setMinBuyQuantity(1);
|
268 |
fdi.setMinBuyQuantity(1);
|
| 266 |
}
|
269 |
}
|
| 267 |
fdi.setAvailability(10);
|
270 |
fdi.setAvailability(10);
|
| 268 |
fdi.setQuantityStep(1);
|
271 |
fdi.setQuantityStep(1);
|
| 269 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
|
272 |
fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
|
| 270 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
273 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
| 271 |
}
|
274 |
}
|
| 272 |
}
|
275 |
}
|
| 273 |
if(fofoAvailabilityInfoMap.values().size() > 0) {
|
276 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
| 274 |
ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
|
277 |
ffdr.setItems(new ArrayList<FofoAvailabilityInfo>(fofoAvailabilityInfoMap.values()));
|
| 275 |
dealResponse.add(ffdr);
|
278 |
dealResponse.add(ffdr);
|
| 276 |
}
|
279 |
}
|
| 277 |
}
|
280 |
}
|
| 278 |
|
281 |
|
| 279 |
} else {
|
282 |
} else {
|
| - |
|
283 |
return responseSender.badRequest(
|
| 280 |
return responseSender.badRequest(new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
284 |
new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
| 281 |
}
|
285 |
}
|
| 282 |
return responseSender.ok(dealResponse);
|
286 |
return responseSender.ok(dealResponse);
|
| 283 |
}
|
287 |
}
|
| 284 |
|
288 |
|
| 285 |
@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
289 |
@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| Line 303... |
Line 307... |
| 303 |
params.put("categoryId", categoryId);
|
307 |
params.put("categoryId", categoryId);
|
| 304 |
params.put("direction", direction);
|
308 |
params.put("direction", direction);
|
| 305 |
params.put("sort", sort);
|
309 |
params.put("sort", sort);
|
| 306 |
params.put("source", "online");
|
310 |
params.put("source", "online");
|
| 307 |
params.put("filterData", filterData);
|
311 |
params.put("filterData", filterData);
|
| - |
|
312 |
/*
|
| 308 |
/*if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
313 |
* if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 309 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
314 |
* params.put("tag_ids", getCommaSeparateTags(userId)); }
|
| 310 |
}*/
|
315 |
*/
|
| 311 |
List<Object> responseObject = new ArrayList<>();
|
316 |
List<Object> responseObject = new ArrayList<>();
|
| 312 |
try {
|
317 |
try {
|
| 313 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
318 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
| 314 |
} catch (HttpHostConnectException e) {
|
319 |
} catch (HttpHostConnectException e) {
|
| 315 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
320 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 316 |
}
|
321 |
}
|
| 317 |
|
322 |
|
| 318 |
JsonArray result_json = Json.parse(response).asArray();
|
323 |
JsonArray result_json = Json.parse(response).asArray();
|
| 319 |
for (JsonValue j : result_json) {
|
324 |
for (JsonValue j : result_json) {
|
| 320 |
//logger.info("res " + j.asArray());
|
325 |
// logger.info("res " + j.asArray());
|
| 321 |
List<Object> innerObject = new ArrayList<>();
|
326 |
List<Object> innerObject = new ArrayList<>();
|
| 322 |
for (JsonValue jsonObject : j.asArray()) {
|
327 |
for (JsonValue jsonObject : j.asArray()) {
|
| 323 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
328 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
| 324 |
}
|
329 |
}
|
| 325 |
if (innerObject.size() > 0) {
|
330 |
if (innerObject.size() > 0) {
|
| Line 328... |
Line 333... |
| 328 |
}
|
333 |
}
|
| 329 |
return responseSender.ok(responseObject);
|
334 |
return responseSender.ok(responseObject);
|
| 330 |
}
|
335 |
}
|
| 331 |
|
336 |
|
| 332 |
/*
|
337 |
/*
|
| 333 |
* @RequestMapping(value = "/direct-deals",
|
338 |
* @RequestMapping(value = "/direct-deals", method=RequestMethod.GET,produces =
|
| 334 |
* method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
339 |
* MediaType.APPLICATION_JSON_VALUE)
|
| 335 |
*
|
340 |
*
|
| 336 |
* @ApiImplicitParams({
|
341 |
* @ApiImplicitParams({
|
| 337 |
*
|
342 |
*
|
| 338 |
* @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required =
|
343 |
* @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true,
|
| 339 |
* true, dataType = "string", paramType = "header") }) public
|
344 |
* dataType = "string", paramType = "header") }) public ResponseEntity<?>
|
| 340 |
* ResponseEntity<?> getDirectDeals(HttpServletRequest
|
- |
|
| 341 |
* request, @RequestParam(value="categoryId") String
|
345 |
* getDirectDeals(HttpServletRequest request, @RequestParam(value="categoryId")
|
| 342 |
* categoryId,@RequestParam(value="offset") String offset,
|
346 |
* String categoryId,@RequestParam(value="offset") String offset,
|
| 343 |
*
|
347 |
*
|
| 344 |
* @RequestParam(value="limit") String limit, @RequestParam(value="sort",
|
348 |
* @RequestParam(value="limit") String limit, @RequestParam(value="sort",
|
| 345 |
* required=false) String sort, @RequestParam(value="direction",
|
349 |
* required=false) String sort, @RequestParam(value="direction", required=false)
|
| 346 |
* required=false) String direction,
|
350 |
* String direction,
|
| 347 |
*
|
351 |
*
|
| 348 |
* @RequestParam(value="filterData", required=false) String filterData ){
|
352 |
* @RequestParam(value="filterData", required=false) String filterData ){
|
| 349 |
*
|
353 |
*
|
| 350 |
* return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK); }
|
354 |
* return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK); }
|
| 351 |
*/
|
355 |
*/
|
| Line 360... |
Line 364... |
| 360 |
@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
364 |
@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 361 |
@ApiImplicitParams({
|
365 |
@ApiImplicitParams({
|
| 362 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
366 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 363 |
@ApiOperation(value = "Get brand list and count for category")
|
367 |
@ApiOperation(value = "Get brand list and count for category")
|
| 364 |
public ResponseEntity<?> getBrands(HttpServletRequest request,
|
368 |
public ResponseEntity<?> getBrands(HttpServletRequest request,
|
| 365 |
@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException{
|
369 |
@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
|
| 366 |
logger.info("Request " + request.getParameterMap());
|
370 |
logger.info("Request " + request.getParameterMap());
|
| 367 |
String response = null;
|
371 |
String response = null;
|
| 368 |
// TODO: move to properties
|
372 |
// TODO: move to properties
|
| 369 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
373 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
| 370 |
RestClient rc = new RestClient();
|
374 |
RestClient rc = new RestClient();
|
| Line 374... |
Line 378... |
| 374 |
try {
|
378 |
try {
|
| 375 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
379 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
| 376 |
} catch (HttpHostConnectException e) {
|
380 |
} catch (HttpHostConnectException e) {
|
| 377 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
381 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 378 |
}
|
382 |
}
|
| 379 |
|
383 |
|
| 380 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
384 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
| 381 |
}.getType());
|
385 |
}.getType());
|
| 382 |
|
386 |
|
| 383 |
return responseSender.ok(dealBrandsResponse);
|
387 |
return responseSender.ok(dealBrandsResponse);
|
| 384 |
}
|
388 |
}
|
| 385 |
|
389 |
|
| 386 |
@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
390 |
@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 387 |
@ApiImplicitParams({
|
391 |
@ApiImplicitParams({
|
| 388 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
392 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 389 |
@ApiOperation(value = "Get unit deal object")
|
393 |
@ApiOperation(value = "Get unit deal object")
|
| 390 |
public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
|
394 |
public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
|
| 391 |
throws ProfitMandiBusinessException{
|
395 |
throws ProfitMandiBusinessException {
|
| 392 |
String response = null;
|
396 |
String response = null;
|
| 393 |
// TODO: move to properties
|
397 |
// TODO: move to properties
|
| 394 |
String uri = "getDealById/" + id;
|
398 |
String uri = "getDealById/" + id;
|
| 395 |
System.out.println("Unit deal " + uri);
|
399 |
System.out.println("Unit deal " + uri);
|
| 396 |
RestClient rc = new RestClient();
|
400 |
RestClient rc = new RestClient();
|
| Line 399... |
Line 403... |
| 399 |
try {
|
403 |
try {
|
| 400 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
404 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
| 401 |
} catch (HttpHostConnectException e) {
|
405 |
} catch (HttpHostConnectException e) {
|
| 402 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
406 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 403 |
}
|
407 |
}
|
| 404 |
|
408 |
|
| 405 |
JsonObject result_json = Json.parse(response).asObject();
|
409 |
JsonObject result_json = Json.parse(response).asObject();
|
| 406 |
if (!result_json.isEmpty()) {
|
410 |
if (!result_json.isEmpty()) {
|
| 407 |
dealsResponse = new Gson().fromJson(response, DealsResponse.class);
|
411 |
dealsResponse = new Gson().fromJson(response, DealsResponse.class);
|
| 408 |
Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
|
412 |
Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
|
| 409 |
while (iter.hasNext()){
|
413 |
while (iter.hasNext()) {
|
| 410 |
AvailabilityInfo ai = iter.next();
|
414 |
AvailabilityInfo ai = iter.next();
|
| 411 |
if(ai.getAvailability() <= 0)
|
415 |
if (ai.getAvailability() <= 0)
|
| 412 |
iter.remove();
|
416 |
iter.remove();
|
| 413 |
}
|
417 |
}
|
| 414 |
}
|
418 |
}
|
| - |
|
419 |
/*
|
| 415 |
/*final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
420 |
* final ProfitMandiResponse<?> profitMandiResponse = new
|
| - |
|
421 |
* ProfitMandiResponse<>(LocalDateTime.now(),
|
| 416 |
request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,
|
422 |
* request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK,
|
| 417 |
dealsResponse);*/
|
423 |
* ResponseStatus.SUCCESS, dealsResponse);
|
| - |
|
424 |
*/
|
| 418 |
return responseSender.ok(dealsResponse);
|
425 |
return responseSender.ok(dealsResponse);
|
| 419 |
}
|
426 |
}
|
| 420 |
|
427 |
|
| 421 |
@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
428 |
@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 422 |
public ResponseEntity<?> getBrandsToDisplay() {
|
429 |
public ResponseEntity<?> getBrandsToDisplay() {
|
| 423 |
return new ResponseEntity<>(mongoClient.getBrandsToDisplay(), HttpStatus.OK);
|
430 |
return new ResponseEntity<>(mongoClient.getBrandsToDisplay(), HttpStatus.OK);
|
| 424 |
}
|
431 |
}
|
| 425 |
|
432 |
|
| 426 |
@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
433 |
@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 427 |
public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
|
434 |
public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
|
| 428 |
return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
|
435 |
return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
|
| 429 |
}
|
436 |
}
|
| - |
|
437 |
|
| 430 |
@RequestMapping(value = "/deals/subCategories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
438 |
@RequestMapping(value = "/deals/subCategories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 431 |
public ResponseEntity<?> getSubcategoriesToDisplay() {
|
439 |
public ResponseEntity<?> getSubcategoriesToDisplay() {
|
| 432 |
return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
|
440 |
return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
|
| 433 |
}
|
441 |
}
|
| - |
|
442 |
|
| 434 |
@ApiImplicitParams({
|
443 |
@ApiImplicitParams({
|
| 435 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
444 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 436 |
@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
445 |
@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 437 |
public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
|
446 |
public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
|
| 438 |
StringBuffer sb = new StringBuffer("/getDealsForNotification/");
|
447 |
StringBuffer sb = new StringBuffer("/getDealsForNotification/");
|
| 439 |
String uri = sb.append(skus).toString();
|
448 |
String uri = sb.append(skus).toString();
|
| 440 |
RestClient rc = new RestClient();
|
449 |
RestClient rc = new RestClient();
|
| 441 |
String response;
|
450 |
String response;
|
| 442 |
try {
|
451 |
try {
|
| 443 |
response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
|
452 |
response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
|
| 444 |
}catch (HttpHostConnectException e) {
|
453 |
} catch (HttpHostConnectException e) {
|
| 445 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
454 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 446 |
}
|
455 |
}
|
| 447 |
JsonArray result_json = Json.parse(response).asArray();
|
456 |
JsonArray result_json = Json.parse(response).asArray();
|
| 448 |
List<Object> responseObject = new ArrayList<>();
|
457 |
List<Object> responseObject = new ArrayList<>();
|
| 449 |
for (JsonValue j : result_json) {
|
458 |
for (JsonValue j : result_json) {
|
| 450 |
//logger.info("res " + j.asArray());
|
459 |
// logger.info("res " + j.asArray());
|
| 451 |
List<Object> innerObject = new ArrayList<>();
|
460 |
List<Object> innerObject = new ArrayList<>();
|
| 452 |
for (JsonValue jsonObject : j.asArray()) {
|
461 |
for (JsonValue jsonObject : j.asArray()) {
|
| 453 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
462 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
| 454 |
}
|
463 |
}
|
| 455 |
if (innerObject.size() > 0) {
|
464 |
if (innerObject.size() > 0) {
|