| Line 7... |
Line 7... |
| 7 |
import java.util.Map;
|
7 |
import java.util.Map;
|
| 8 |
|
8 |
|
| 9 |
import javax.servlet.http.HttpServletRequest;
|
9 |
import javax.servlet.http.HttpServletRequest;
|
| 10 |
|
10 |
|
| 11 |
import org.apache.thrift.TException;
|
11 |
import org.apache.thrift.TException;
|
| - |
|
12 |
import org.apache.thrift.transport.TTransportException;
|
| 12 |
import org.slf4j.Logger;
|
13 |
import org.slf4j.Logger;
|
| 13 |
import org.slf4j.LoggerFactory;
|
14 |
import org.slf4j.LoggerFactory;
|
| 14 |
import org.springframework.beans.factory.annotation.Value;
|
15 |
import org.springframework.beans.factory.annotation.Value;
|
| 15 |
import org.springframework.http.HttpStatus;
|
16 |
import org.springframework.http.HttpStatus;
|
| 16 |
import org.springframework.http.MediaType;
|
17 |
import org.springframework.http.MediaType;
|
| Line 24... |
Line 25... |
| 24 |
import com.eclipsesource.json.Json;
|
25 |
import com.eclipsesource.json.Json;
|
| 25 |
import com.eclipsesource.json.JsonArray;
|
26 |
import com.eclipsesource.json.JsonArray;
|
| 26 |
import com.eclipsesource.json.JsonObject;
|
27 |
import com.eclipsesource.json.JsonObject;
|
| 27 |
import com.eclipsesource.json.JsonValue;
|
28 |
import com.eclipsesource.json.JsonValue;
|
| 28 |
import com.google.gson.Gson;
|
29 |
import com.google.gson.Gson;
|
| - |
|
30 |
import com.google.gson.reflect.TypeToken;
|
| 29 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
32 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 31 |
import com.spice.profitmandi.thrift.clients.CatalogClient;
|
- |
|
| 32 |
import com.spice.profitmandi.web.client.RestClient;
|
33 |
import com.spice.profitmandi.web.client.RestClient;
|
| 33 |
import com.spice.profitmandi.web.enumuration.SchemeType;
|
34 |
import com.spice.profitmandi.web.enumuration.SchemeType;
|
| 34 |
import com.spice.profitmandi.web.model.ProfitMandiResponse;
|
35 |
import com.spice.profitmandi.web.model.ProfitMandiResponse;
|
| 35 |
import com.spice.profitmandi.web.model.ResponseStatus;
|
36 |
import com.spice.profitmandi.web.model.ResponseStatus;
|
| - |
|
37 |
import com.spice.profitmandi.web.res.DealBrands;
|
| 36 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
38 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
| 37 |
import com.spice.profitmandi.web.res.DealsResponse;
|
39 |
import com.spice.profitmandi.web.res.DealsResponse;
|
| 38 |
|
40 |
|
| 39 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
41 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
| 40 |
import in.shop2020.model.v1.catalog.Item;
|
42 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 41 |
import io.swagger.annotations.ApiImplicitParam;
|
43 |
import io.swagger.annotations.ApiImplicitParam;
|
| 42 |
import io.swagger.annotations.ApiImplicitParams;
|
44 |
import io.swagger.annotations.ApiImplicitParams;
|
| 43 |
import io.swagger.annotations.ApiOperation;
|
45 |
import io.swagger.annotations.ApiOperation;
|
| 44 |
|
46 |
|
| 45 |
@Controller
|
47 |
@Controller
|
| Line 68... |
Line 70... |
| 68 |
params.put("limit", limit);
|
70 |
params.put("limit", limit);
|
| 69 |
params.put("categoryId", categoryId);
|
71 |
params.put("categoryId", categoryId);
|
| 70 |
params.put("direction", direction);
|
72 |
params.put("direction", direction);
|
| 71 |
params.put("sort", sort);
|
73 |
params.put("sort", sort);
|
| 72 |
params.put("filterData", filterData);
|
74 |
params.put("filterData", filterData);
|
| 73 |
|
- |
|
| - |
|
75 |
List<Object> responseObject = new ArrayList<>();
|
| 74 |
try {
|
76 |
try {
|
| 75 |
response = rc.get(uri, params);
|
77 |
response = rc.get(uri, params);
|
| 76 |
} catch (Exception | ProfitMandiBusinessException e) {
|
78 |
} catch (Exception | ProfitMandiBusinessException e) {
|
| 77 |
logger.error("Unable to get deals",e);
|
79 |
logger.error("Unable to get deals",e);
|
| 78 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, new DealsResponse());
|
80 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, responseObject);
|
| 79 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
81 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
| 80 |
}
|
82 |
}
|
| 81 |
JsonArray result_json = Json.parse(response).asArray();
|
83 |
JsonArray result_json = Json.parse(response).asArray();
|
| 82 |
List<Object> responseObject = new ArrayList<>();
|
- |
|
| 83 |
for (JsonValue j : result_json ){
|
84 |
for (JsonValue j : result_json ){
|
| 84 |
logger.info("res "+j.asArray());
|
85 |
logger.info("res "+j.asArray());
|
| 85 |
List<Object> innerObject = new ArrayList<>();
|
86 |
List<Object> innerObject = new ArrayList<>();
|
| 86 |
for (JsonValue jsonObject : j.asArray()){
|
87 |
for (JsonValue jsonObject : j.asArray()){
|
| 87 |
innerObject.add(toObject(jsonObject.asObject()));
|
88 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
| 88 |
}
|
89 |
}
|
| 89 |
if (innerObject.size() > 0){
|
90 |
if (innerObject.size() > 0){
|
| 90 |
responseObject.add(innerObject);
|
91 |
responseObject.add(innerObject);
|
| 91 |
}
|
92 |
}
|
| 92 |
}
|
93 |
}
|
| 93 |
try {
|
- |
|
| 94 |
CatalogClient cc = new CatalogClient();
|
- |
|
| 95 |
Item item = cc.getClient().getItem(26328);
|
- |
|
| 96 |
logger.info("Thrift item "+item.toString());
|
- |
|
| 97 |
} catch (CatalogServiceException | TException e) {
|
- |
|
| 98 |
// TODO Auto-generated catch block
|
- |
|
| 99 |
e.printStackTrace();
|
- |
|
| 100 |
}
|
- |
|
| 101 |
|
- |
|
| 102 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, responseObject);
|
94 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, responseObject);
|
| 103 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
95 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
| 104 |
}
|
96 |
}
|
| 105 |
|
97 |
|
| 106 |
private Object toObject(JsonObject jsonObject){
|
98 |
private Object toDealObject(JsonObject jsonObject){
|
| 107 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1){
|
99 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1){
|
| 108 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
100 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
| 109 |
}
|
101 |
}
|
| 110 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|
102 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|
| 111 |
}
|
103 |
}
|
| - |
|
104 |
|
| - |
|
105 |
|
| - |
|
106 |
@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
107 |
@ApiImplicitParams({
|
| - |
|
108 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
| - |
|
109 |
required = true, dataType = "string", paramType = "header")
|
| - |
|
110 |
})
|
| - |
|
111 |
@ApiOperation(value = "Get brand list and count for category")
|
| - |
|
112 |
public ResponseEntity<?> getBrands(HttpServletRequest request, @RequestParam(value="category_id") String category_id){
|
| - |
|
113 |
logger.info("Request "+request.getParameterMap());
|
| - |
|
114 |
String response = null;
|
| - |
|
115 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
| - |
|
116 |
RestClient rc = new RestClient(SchemeType.HTTP, host , port);
|
| - |
|
117 |
Map<String, String> params = new HashMap<>();
|
| - |
|
118 |
params.put("category_id", category_id);
|
| - |
|
119 |
try {
|
| - |
|
120 |
response = rc.get(uri, params);
|
| - |
|
121 |
} catch (Exception | ProfitMandiBusinessException e) {
|
| - |
|
122 |
logger.error("Unable to get deals",e);
|
| 112 |
|
123 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, new DealBrands());
|
| - |
|
124 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
| - |
|
125 |
}
|
| - |
|
126 |
List<DealBrands> dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>(){}.getType());
|
| - |
|
127 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, dealBrandsResponse);
|
| - |
|
128 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
| - |
|
129 |
}
|
| - |
|
130 |
|
| 113 |
|
131 |
|
| 114 |
}
|
132 |
}
|