Subversion Repositories SmartDukaan

Rev

Rev 25880 | Rev 25885 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 25880 Rev 25882
Line 56... Line 56...
56
import com.spice.profitmandi.dao.repository.dtr.Mongo;
56
import com.spice.profitmandi.dao.repository.dtr.Mongo;
57
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
57
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
58
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
58
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
59
import com.spice.profitmandi.service.authentication.RoleManager;
59
import com.spice.profitmandi.service.authentication.RoleManager;
60
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
60
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
-
 
61
import com.spice.profitmandi.service.inventory.Bucket;
61
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
62
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
62
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
63
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
63
import com.spice.profitmandi.service.inventory.ItemBucketService;
64
import com.spice.profitmandi.service.inventory.ItemBucketService;
64
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
65
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
65
import com.spice.profitmandi.service.pricing.PricingService;
66
import com.spice.profitmandi.service.pricing.PricingService;
Line 184... Line 185...
184
 
185
 
185
	@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
186
	@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
186
	public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id)
187
	public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id)
187
			throws ProfitMandiBusinessException {
188
			throws ProfitMandiBusinessException {
188
		List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
189
		List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
189
		List<Integer> itemIds = iqPojo.stream().map(x -> x.getItemId()).collect(Collectors.toList());
190
		Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream().collect(Collectors.toMap(x->x.getItemId(), x->x.getQuantity()));
190
 
191
 
191
		RestClient rc = new RestClient();
192
		RestClient rc = new RestClient();
192
		Map<String, String> params = new HashMap<>();
193
		Map<String, String> params = new HashMap<>();
193
		List<String> mandatoryQ = new ArrayList<>();
194
		List<String> mandatoryQ = new ArrayList<>();
194
		mandatoryQ.add(String.format("+{!parent which=\"id:catalog*\"} itemId_i:(%s)", StringUtils.join(itemIds, " ")));
195
		mandatoryQ.add(String.format("+{!parent which=\"id:catalog*\"} itemId_i:(%s)", StringUtils.join(itemIdsQtyMap.keySet(), " ")));
195
 
196
 
196
		params.put("q", StringUtils.join(mandatoryQ, " "));
197
		params.put("q", StringUtils.join(mandatoryQ, " "));
197
		params.put("fl", "*, [child parentFilter=id:catalog*]");
198
		params.put("fl", "*, [child parentFilter=id:catalog*]");
198
 
199
 
199
		params.put("wt", "json");
200
		params.put("wt", "json");
Line 204... Line 205...
204
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
205
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
205
		}
206
		}
206
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
207
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
207
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
208
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
208
		List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, false);
209
		List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, false);
-
 
210
		dealResponse = dealResponse.stream().filter(x->itemIdsQtyMap.keySet().contains((int)x.getItems().get(0).getItem_id()))
-
 
211
				.map(x->{
-
 
212
					FofoAvailabilityInfo fai = x.getItems().get(0);
-
 
213
					fai.setAvailability(itemIdsQtyMap.get((int)fai.getItem_id()));
-
 
214
					return x;
-
 
215
				}).collect(Collectors.toList());
-
 
216
		Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).get(0);
-
 
217
		bucket.setFofoCatalogResponses(dealResponse);
209
		return responseSender.ok(dealResponse);
218
		return responseSender.ok(bucket);
210
	}
219
	}
211
 
220
 
212
	private String getCommaSeparateTags(int userId) {
221
	private String getCommaSeparateTags(int userId) {
213
		UserCart uc = userAccountRepository.getUserCart(userId);
222
		UserCart uc = userAccountRepository.getUserCart(userId);
214
		List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
223
		List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());