| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| 4 |
import java.net.URISyntaxException;
|
4 |
import java.net.URISyntaxException;
|
| 5 |
import java.time.LocalDateTime;
|
- |
|
| 6 |
import java.util.ArrayList;
|
- |
|
| 7 |
import java.util.List;
|
5 |
import java.util.List;
|
| 8 |
|
6 |
|
| 9 |
import org.slf4j.Logger;
|
7 |
import org.slf4j.Logger;
|
| 10 |
import org.slf4j.LoggerFactory;
|
8 |
import org.slf4j.LoggerFactory;
|
| 11 |
import org.springframework.beans.factory.annotation.Autowired;
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 12 |
import org.springframework.http.HttpStatus;
|
- |
|
| 13 |
import org.springframework.http.MediaType;
|
10 |
import org.springframework.http.MediaType;
|
| 14 |
import org.springframework.http.ResponseEntity;
|
11 |
import org.springframework.http.ResponseEntity;
|
| 15 |
import org.springframework.stereotype.Controller;
|
12 |
import org.springframework.stereotype.Controller;
|
| 16 |
import org.springframework.web.bind.annotation.RequestMapping;
|
13 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 17 |
import org.springframework.web.bind.annotation.RequestMethod;
|
14 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| Line 22... |
Line 19... |
| 22 |
import com.eclipsesource.json.JsonObject;
|
19 |
import com.eclipsesource.json.JsonObject;
|
| 23 |
import com.eclipsesource.json.JsonValue;
|
20 |
import com.eclipsesource.json.JsonValue;
|
| 24 |
import com.google.gson.Gson;
|
21 |
import com.google.gson.Gson;
|
| 25 |
import com.google.gson.reflect.TypeToken;
|
22 |
import com.google.gson.reflect.TypeToken;
|
| 26 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
23 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 27 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
- |
|
| 28 |
import com.spice.profitmandi.common.model.ResponseStatus;
|
- |
|
| 29 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
24 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 30 |
import com.spice.profitmandi.web.res.SolrSearchResultResponse;
|
25 |
import com.spice.profitmandi.web.res.SolrSearchResultResponse;
|
| 31 |
import com.spice.profitmandi.web.res.SolrSuggestionResponse;
|
26 |
import com.spice.profitmandi.web.res.SolrSuggestionResponse;
|
| 32 |
import com.spice.profitmandi.web.services.SolrService;
|
27 |
import com.spice.profitmandi.web.services.SolrService;
|
| 33 |
|
28 |
|
| Line 64... |
Line 59... |
| 64 |
try {
|
59 |
try {
|
| 65 |
jsonString = solrService.getSearchResults(search_text.trim(), offset);
|
60 |
jsonString = solrService.getSearchResults(search_text.trim(), offset);
|
| 66 |
logger.info("Response from solr "+jsonString);
|
61 |
logger.info("Response from solr "+jsonString);
|
| 67 |
} catch (URISyntaxException | IOException e) {
|
62 |
} catch (URISyntaxException | IOException e) {
|
| 68 |
logger.error("Error while gettting search results from solr",e);
|
63 |
logger.error("Error while gettting search results from solr",e);
|
| 69 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SEARCH , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, new ArrayList<SolrSearchResultResponse>());
|
64 |
responseSender.internalServerError(e);
|
| 70 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
- |
|
| 71 |
}
|
65 |
}
|
| 72 |
JsonArray result_json = Json.parse(jsonString).asObject().get("response").asObject().get("docs").asArray();
|
66 |
JsonArray result_json = Json.parse(jsonString).asObject().get("response").asObject().get("docs").asArray();
|
| 73 |
for (JsonValue j : result_json ){
|
67 |
for (JsonValue j : result_json ){
|
| 74 |
j.asObject().add("productUrl", j.asObject().get("ids").asArray().get(0)+"/"+j.asObject().get("id").asString());
|
68 |
j.asObject().add("productUrl", j.asObject().get("ids").asArray().get(0)+"/"+j.asObject().get("id").asString());
|
| 75 |
}
|
69 |
}
|
| Line 90... |
Line 84... |
| 90 |
String jsonString;
|
84 |
String jsonString;
|
| 91 |
try {
|
85 |
try {
|
| 92 |
jsonString = solrService.getSuggestions(search_text.trim());
|
86 |
jsonString = solrService.getSuggestions(search_text.trim());
|
| 93 |
} catch (URISyntaxException | IOException e) {
|
87 |
} catch (URISyntaxException | IOException e) {
|
| 94 |
logger.error("Error while getting suggestions from solr",e);
|
88 |
logger.error("Error while getting suggestions from solr",e);
|
| 95 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SUGGESTION , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, new ArrayList<SolrSuggestionResponse>());
|
89 |
return responseSender.internalServerError(e);
|
| 96 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
- |
|
| 97 |
}
|
90 |
}
|
| 98 |
result_json = Json.parse(jsonString).asObject().get("grouped").asObject();
|
91 |
result_json = Json.parse(jsonString).asObject().get("grouped").asObject();
|
| 99 |
Gson gson = new Gson();
|
92 |
Gson gson = new Gson();
|
| 100 |
List<SolrSuggestionResponse> solrSearchResultResponse = gson.fromJson(sanatizedResults().toString(), new TypeToken<List<SolrSuggestionResponse>>(){}.getType());
|
93 |
List<SolrSuggestionResponse> solrSearchResultResponse = gson.fromJson(sanatizedResults().toString(), new TypeToken<List<SolrSuggestionResponse>>(){}.getType());
|
| 101 |
return responseSender.ok(solrSearchResultResponse);
|
94 |
return responseSender.ok(solrSearchResultResponse);
|