Subversion Repositories SmartDukaan

Rev

Rev 36932 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36932 Rev 37144
Line 259... Line 259...
259
    AffiliateService affiliateService;
259
    AffiliateService affiliateService;
260
 
260
 
261
    @Autowired
261
    @Autowired
262
    FofoUser fofoUser;
262
    FofoUser fofoUser;
263
 
263
 
-
 
264
    @Autowired
-
 
265
    private com.spice.profitmandi.web.services.PartnerSolrClient partnerSolrClient;
-
 
266
 
-
 
267
    @Autowired
-
 
268
    private com.spice.profitmandi.service.catalog.BrandsService brandsService;
-
 
269
 
264
    List<String> filterableParams = Arrays.asList("brand");
270
    List<String> filterableParams = Arrays.asList("brand");
265
 
271
 
266
    @RequestMapping(value = "/store/entity/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
272
    @RequestMapping(value = "/store/entity/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
267
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
273
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
268
    @ApiOperation(value = "Get unit deal object")
274
    @ApiOperation(value = "Get unit deal object")
Line 272... Line 278...
272
        FofoCatalogResponse fofoCatalogResponse = null;
278
        FofoCatalogResponse fofoCatalogResponse = null;
273
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
279
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
274
        if (roleManagerService.isPartner(userInfo.getRoleIds())) {
280
        if (roleManagerService.isPartner(userInfo.getRoleIds())) {
275
            String categoryId = "(3 OR 6)";
281
            String categoryId = "(3 OR 6)";
276
 
282
 
277
            RestClient rc = new RestClient();
-
 
278
            Map<String, String> params = new HashMap<>();
283
            Map<String, String> params = new HashMap<>();
279
            List<String> mandatoryQ = new ArrayList<>();
284
            List<String> mandatoryQ = new ArrayList<>();
280
            String catalogString = "catalog" + id;
285
            String catalogString = "catalog" + id;
281
 
286
 
282
            mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)", categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
287
            mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)", categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
283
 
288
 
284
            params.put("q", StringUtils.join(mandatoryQ, " "));
289
            params.put("q", StringUtils.join(mandatoryQ, " "));
285
            params.put("fl", "*, [child parentFilter=id:catalog*]");
290
            params.put("fl", "*, [child parentFilter=id:catalog*]");
286
            params.put("sort", "rank_i asc, create_s desc");
291
            params.put("sort", "rank_i asc, create_s desc");
287
            params.put("wt", "json");
292
            params.put("wt", "json");
288
            String response = null;
-
 
289
            try {
-
 
290
                response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
-
 
291
            } catch (HttpHostConnectException e) {
-
 
292
                throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
293
            }
-
 
294
            JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
295
            JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
293
            JSONArray docs = partnerSolrClient.selectDocs(params, userInfo.getRetailerId());
296
            dealResponses = getCatalogResponse(docs, false, userInfo.getRetailerId());
294
            dealResponses = getCatalogResponse(docs, false, userInfo.getRetailerId());
297
            fofoCatalogResponse = dealResponses.get(0);
295
            fofoCatalogResponse = dealResponses.get(0);
298
            fofoCatalogResponse.setWebOffers(webOfferRepository.selectAllActiveOffers().get(fofoCatalogResponse.getCatalogId()));
296
            fofoCatalogResponse.setWebOffers(webOfferRepository.selectAllActiveOffers().get(fofoCatalogResponse.getCatalogId()));
299
 
297
 
300
        } else {
298
        } else {
Line 330... Line 328...
330
        }
328
        }
331
 
329
 
332
        dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
330
        dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
333
        }.getType());
331
        }.getType());
334
 
332
 
-
 
333
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
-
 
334
        List<String> restrictedBrands = brandsService.restrictedBrands(userInfo.getRetailerId());
-
 
335
        dealBrandsResponse = dealBrandsResponse.stream().filter(x -> !restrictedBrands.contains(x.getBrand()))
-
 
336
                .collect(Collectors.toList());
-
 
337
 
335
        return responseSender.ok(dealBrandsResponse);
338
        return responseSender.ok(dealBrandsResponse);
336
    }
339
    }
337
 
340
 
338
    @RequestMapping(value = "/store/listing/{listingUrl}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
341
    @RequestMapping(value = "/store/listing/{listingUrl}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
339
    public ResponseEntity<?> bestSellers(HttpServletRequest request, @PathVariable String listingUrl) throws Exception {
342
    public ResponseEntity<?> bestSellers(HttpServletRequest request, @PathVariable String listingUrl) throws Exception {
Line 897... Line 900...
897
    private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing) throws ProfitMandiBusinessException {
900
    private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing) throws ProfitMandiBusinessException {
898
        List<Integer> webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId()).stream().filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
901
        List<Integer> webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId()).stream().filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
899
        if (webProducts.size() == 0) {
902
        if (webProducts.size() == 0) {
900
            return new ArrayList<>();
903
            return new ArrayList<>();
901
        }
904
        }
902
        RestClient rc = new RestClient();
-
 
903
        Map<String, String> params = new HashMap<>();
905
        Map<String, String> params = new HashMap<>();
904
        List<String> mandatoryQ = new ArrayList<>();
906
        List<String> mandatoryQ = new ArrayList<>();
905
        mandatoryQ.add(String.format(
907
        mandatoryQ.add(String.format(
906
                "+{!parent which=\"catalogId_i:(" + StringUtils.join(webProducts, " ") + ")\"} tagId_i:(%s)", StringUtils.join(TAG_IDS, " ")));
908
                "+{!parent which=\"catalogId_i:(" + StringUtils.join(webProducts, " ") + ")\"} tagId_i:(%s)", StringUtils.join(TAG_IDS, " ")));
907
        params.put("q", StringUtils.join(mandatoryQ, " "));
909
        params.put("q", StringUtils.join(mandatoryQ, " "));
908
        params.put("fl", "*, [child parentFilter=id:catalog*]");
910
        params.put("fl", "*, [child parentFilter=id:catalog*]");
909
        // params.put("sort", "create_s desc");
911
        // params.put("sort", "create_s desc");
910
        params.put("start", String.valueOf(0));
912
        params.put("start", String.valueOf(0));
911
        params.put("rows", String.valueOf(100));
913
        params.put("rows", String.valueOf(100));
912
        params.put("wt", "json");
914
        params.put("wt", "json");
913
        String response = null;
-
 
914
        try {
-
 
915
            response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
-
 
916
        } catch (HttpHostConnectException e) {
-
 
917
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
918
        }
-
 
919
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
920
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
915
        JSONArray docs = partnerSolrClient.selectDocs(params, userInfo.getRetailerId());
921
        List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
916
        List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
922
        return dealResponse;
917
        return dealResponse;
923
    }
918
    }
924
 
919
 
925
    @RequestMapping(value = "/store/cart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
920
    @RequestMapping(value = "/store/cart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)