Subversion Repositories SmartDukaan

Rev

Rev 37144 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
37144 amit 1
package com.spice.profitmandi.web.services;
2
 
3
import java.util.Map;
4
 
5
import org.apache.http.conn.HttpHostConnectException;
6
import org.json.JSONArray;
7
import org.json.JSONObject;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.beans.factory.annotation.Value;
10
import org.springframework.stereotype.Component;
11
 
12
import com.spice.profitmandi.common.enumuration.SchemeType;
13
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
14
import com.spice.profitmandi.common.web.client.RestClient;
15
import com.spice.profitmandi.service.catalog.BrandsService;
16
 
17
/**
18
 * Executes partner-facing queries against the solr demo core, always applying
19
 * the partner's restricted-brand (blocked + LOI-ineligible) exclusion at query time.
20
 */
21
@Component
22
public class PartnerSolrClient {
23
 
24
    @Value("${new.solr.url}")
25
    private String solrUrl;
26
 
27
    @Autowired
28
    private BrandsService brandsService;
29
 
30
    @Autowired
31
    private RestClient restClient;
32
 
33
    public JSONArray selectDocs(Map<String, String> params, int fofoId) throws ProfitMandiBusinessException {
34
        brandsService.applyRestrictedSolrExclusion(params, fofoId);
37250 amit 35
        return selectDocsRaw(params);
36
    }
37
 
38
    /**
39
     * Pure HTTP query with no DB access — safe to call off the request thread. The caller
40
     * is responsible for having applied the partner's brand exclusion to params already.
41
     */
42
    public JSONArray selectDocsRaw(Map<String, String> params) throws ProfitMandiBusinessException {
37144 amit 43
        String response;
44
        try {
45
            response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
46
        } catch (HttpHostConnectException e) {
47
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
48
        }
49
        return new JSONObject(response).getJSONObject("response").getJSONArray("docs");
50
    }
51
 
52
}