| Line 6... |
Line 6... |
| 6 |
import java.util.List;
|
6 |
import java.util.List;
|
| 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.commons.lang3.StringUtils;
|
| - |
|
12 |
import org.json.JSONArray;
|
| - |
|
13 |
import org.json.JSONObject;
|
| 11 |
import org.slf4j.Logger;
|
14 |
import org.slf4j.Logger;
|
| 12 |
import org.slf4j.LoggerFactory;
|
15 |
import org.slf4j.LoggerFactory;
|
| 13 |
import org.springframework.beans.factory.annotation.Autowired;
|
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 14 |
import org.springframework.beans.factory.annotation.Value;
|
17 |
import org.springframework.beans.factory.annotation.Value;
|
| 15 |
import org.springframework.http.HttpStatus;
|
18 |
import org.springframework.http.HttpStatus;
|
| Line 32... |
Line 35... |
| 32 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
35 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 33 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
36 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 34 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
37 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
| 35 |
import com.spice.profitmandi.common.model.ResponseStatus;
|
38 |
import com.spice.profitmandi.common.model.ResponseStatus;
|
| 36 |
import com.spice.profitmandi.common.model.UserInfo;
|
39 |
import com.spice.profitmandi.common.model.UserInfo;
|
| - |
|
40 |
import com.spice.profitmandi.common.solr.model.FofoDealItem;
|
| - |
|
41 |
import com.spice.profitmandi.common.solr.model.FofoDealResponse;
|
| 37 |
import com.spice.profitmandi.common.web.client.RestClient;
|
42 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| - |
|
43 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 38 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
44 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 39 |
import com.spice.profitmandi.service.pricing.PricingService;
|
45 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 40 |
import com.spice.profitmandi.web.res.DealBrands;
|
46 |
import com.spice.profitmandi.web.res.DealBrands;
|
| 41 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
47 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
| 42 |
import com.spice.profitmandi.web.res.DealsResponse;
|
48 |
import com.spice.profitmandi.web.res.DealsResponse;
|
| Line 44... |
Line 50... |
| 44 |
import io.swagger.annotations.ApiImplicitParam;
|
50 |
import io.swagger.annotations.ApiImplicitParam;
|
| 45 |
import io.swagger.annotations.ApiImplicitParams;
|
51 |
import io.swagger.annotations.ApiImplicitParams;
|
| 46 |
import io.swagger.annotations.ApiOperation;
|
52 |
import io.swagger.annotations.ApiOperation;
|
| 47 |
|
53 |
|
| 48 |
@Controller
|
54 |
@Controller
|
| 49 |
@Transactional(rollbackFor=Throwable.class)
|
55 |
@Transactional(rollbackFor = Throwable.class)
|
| 50 |
public class DealsController {
|
56 |
public class DealsController {
|
| 51 |
|
57 |
|
| 52 |
private static final Logger logger=LoggerFactory.getLogger(DealsController.class);
|
58 |
private static final Logger logger = LoggerFactory.getLogger(DealsController.class);
|
| 53 |
|
59 |
|
| 54 |
@Value("${python.api.host}")
|
60 |
@Value("${python.api.host}")
|
| 55 |
private String host;
|
61 |
private String host;
|
| 56 |
@Value("${python.api.port}")
|
62 |
@Value("${python.api.port}")
|
| 57 |
private int port;
|
63 |
private int port;
|
| 58 |
|
64 |
|
| 59 |
@Autowired
|
65 |
@Autowired
|
| 60 |
private PricingService pricingService;
|
66 |
private PricingService pricingService;
|
| - |
|
67 |
|
| - |
|
68 |
@Autowired
|
| - |
|
69 |
ResponseSender<?> responseSender;
|
| 61 |
|
70 |
|
| 62 |
@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
71 |
@RequestMapping(value = ProfitMandiConstants.URL_DEALS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 63 |
@ApiImplicitParams({
|
72 |
@ApiImplicitParams({
|
| 64 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
73 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 65 |
required = true, dataType = "string", paramType = "header")
|
- |
|
| 66 |
})
|
- |
|
| 67 |
@ApiOperation(value = "Get deals")
|
74 |
@ApiOperation(value = "Get deals")
|
| 68 |
public ResponseEntity<?> getDeals(HttpServletRequest request, @RequestParam(value="categoryId") String categoryId,
|
75 |
public ResponseEntity<?> getDeals(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
| 69 |
@RequestParam(value="offset") String offset, @RequestParam(value="limit") String limit, @RequestParam(value="sort", required=false) String sort,
|
76 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
| - |
|
77 |
@RequestParam(value = "sort", required = false) String sort,
|
| - |
|
78 |
@RequestParam(value = "direction", required = false) String direction,
|
| 70 |
@RequestParam(value="direction", required=false) String direction, @RequestParam(value="filterData", required=false) String filterData ) throws Throwable {
|
79 |
@RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
|
| 71 |
logger.info("Request "+request.getParameterMap());
|
80 |
logger.info("Request " + request.getParameterMap());
|
| 72 |
String response = null;
|
81 |
String response = null;
|
| 73 |
int userId = (int)request.getAttribute("userId");
|
82 |
int userId = (int) request.getAttribute("userId");
|
| 74 |
UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
|
83 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 75 |
//TODO: move to properties
|
84 |
// TODO: move to properties
|
| 76 |
String uri = "/deals/"+userId;
|
85 |
String uri = "/deals/" + userId;
|
| 77 |
RestClient rc = new RestClient(SchemeType.HTTP, host , port);
|
86 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
| 78 |
Map<String, String> params = new HashMap<>();
|
87 |
Map<String, String> params = new HashMap<>();
|
| 79 |
params.put("offset", offset);
|
88 |
params.put("offset", offset);
|
| 80 |
params.put("limit", limit);
|
89 |
params.put("limit", limit);
|
| 81 |
params.put("categoryId", categoryId);
|
90 |
params.put("categoryId", categoryId);
|
| 82 |
params.put("direction", direction);
|
91 |
params.put("direction", direction);
|
| 83 |
params.put("sort", sort);
|
92 |
params.put("sort", sort);
|
| 84 |
params.put("filterData", filterData);
|
93 |
params.put("filterData", filterData);
|
| 85 |
params.put("source", "deals");
|
94 |
params.put("source", "deals");
|
| 86 |
if(userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
95 |
if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 87 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
96 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
| 88 |
}
|
97 |
}
|
| 89 |
List<Object> responseObject = new ArrayList<>();
|
98 |
List<Object> responseObject = new ArrayList<>();
|
| 90 |
try {
|
99 |
try {
|
| 91 |
response = rc.get(uri, params);
|
100 |
response = rc.get(uri, params);
|
| 92 |
} catch (Exception | ProfitMandiBusinessException e) {
|
101 |
} catch (Exception | ProfitMandiBusinessException e) {
|
| 93 |
logger.error("Unable to get deals",e);
|
102 |
logger.error("Unable to get deals", e);
|
| - |
|
103 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| - |
|
104 |
request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(),
|
| 94 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, responseObject);
|
105 |
HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, responseObject);
|
| 95 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
106 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
| 96 |
}
|
107 |
}
|
| 97 |
JsonArray result_json = Json.parse(response).asArray();
|
108 |
JsonArray result_json = Json.parse(response).asArray();
|
| 98 |
for (JsonValue j : result_json ){
|
109 |
for (JsonValue j : result_json) {
|
| 99 |
logger.info("res "+j.asArray());
|
110 |
logger.info("res " + j.asArray());
|
| 100 |
List<Object> innerObject = new ArrayList<>();
|
111 |
List<Object> innerObject = new ArrayList<>();
|
| 101 |
for (JsonValue jsonObject : j.asArray()){
|
112 |
for (JsonValue jsonObject : j.asArray()) {
|
| 102 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
113 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
| 103 |
}
|
114 |
}
|
| 104 |
if (innerObject.size() > 0){
|
115 |
if (innerObject.size() > 0) {
|
| 105 |
responseObject.add(innerObject);
|
116 |
responseObject.add(innerObject);
|
| 106 |
}
|
117 |
}
|
| 107 |
}
|
118 |
}
|
| - |
|
119 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| 108 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, responseObject);
|
120 |
request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,
|
| - |
|
121 |
responseObject);
|
| 109 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
122 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
|
| 110 |
}
|
123 |
}
|
| 111 |
|
124 |
|
| 112 |
|
- |
|
| 113 |
private String getCommaSeparateTags(int userId) throws Throwable{
|
125 |
private String getCommaSeparateTags(int userId) throws Throwable {
|
| 114 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userId);
|
126 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userId);
|
| 115 |
List<String> strTagIds = new ArrayList<>();
|
127 |
List<String> strTagIds = new ArrayList<>();
|
| 116 |
for (Integer tagId : tagIds) {
|
128 |
for (Integer tagId : tagIds) {
|
| 117 |
strTagIds.add(String.valueOf(tagId));
|
129 |
strTagIds.add(String.valueOf(tagId));
|
| 118 |
}
|
130 |
}
|
| 119 |
return String.join(",", strTagIds);
|
131 |
return String.join(",", strTagIds);
|
| 120 |
}
|
132 |
}
|
| 121 |
|
133 |
|
| - |
|
134 |
@ApiImplicitParams({
|
| - |
|
135 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| - |
|
136 |
@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
137 |
public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId,
|
| - |
|
138 |
@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
|
| - |
|
139 |
@RequestParam(value = "sort", required = false) String sort) throws Throwable {
|
| - |
|
140 |
List<FofoDealResponse> dealResponse = new ArrayList<>();
|
| - |
|
141 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| - |
|
142 |
if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| - |
|
143 |
List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(userInfo.getUserId());
|
| - |
|
144 |
RestClient rc = new RestClient(SchemeType.HTTP, "dtr", 8984);
|
| - |
|
145 |
Map<String, String> params = new HashMap<>();
|
| - |
|
146 |
params.put("q", String.format("{!parent which=\"id:catalog*\"}tagId_i:(%s)", StringUtils.join(tagIds, " OR ")));
|
| - |
|
147 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
| - |
|
148 |
params.put("sort", "rank_i asc");
|
| - |
|
149 |
params.put("start", String.valueOf(offset));
|
| - |
|
150 |
params.put("rows", String.valueOf(limit));
|
| - |
|
151 |
params.put("wt", "json");
|
| - |
|
152 |
String response =rc.get("solr/demo/select", params);
|
| - |
|
153 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| - |
|
154 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| - |
|
155 |
for(int i=0; i < docs.length(); i++) {
|
| - |
|
156 |
Map<Integer, FofoDealItem> itemPricing = new HashMap<>();
|
| - |
|
157 |
JSONObject doc = docs.getJSONObject(i);
|
| - |
|
158 |
FofoDealResponse ffdr = new FofoDealResponse();
|
| - |
|
159 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
| - |
|
160 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
| - |
|
161 |
ffdr.setTitle(doc.getString("title_s"));
|
| - |
|
162 |
for(int j=0; j< doc.getJSONArray("_childItems_").length(); j++) {
|
| - |
|
163 |
JSONObject childItem = doc.getJSONArray("_childItems_").getJSONObject(j);
|
| - |
|
164 |
int itemId = childItem.getInt("itemId_i");
|
| - |
|
165 |
float sellingPrice = (float)childItem.getDouble("sellingPrice_f");
|
| - |
|
166 |
if(itemPricing.containsKey(itemId)) {
|
| - |
|
167 |
if(itemPricing.get(itemId).getSellingPrice() > sellingPrice) {
|
| - |
|
168 |
itemPricing.get(itemId).setSellingPrice(sellingPrice);
|
| - |
|
169 |
itemPricing.get(itemId).setMop((float)childItem.getDouble("mop_f"));
|
| - |
|
170 |
}
|
| - |
|
171 |
} else {
|
| - |
|
172 |
FofoDealItem fdi = new FofoDealItem();
|
| - |
|
173 |
fdi.setSellingPrice((float)childItem.getDouble("sellingPrice_f"));
|
| - |
|
174 |
fdi.setMop((float)childItem.getDouble("mop_f"));
|
| - |
|
175 |
fdi.setColor(childItem.getString("color_s"));
|
| - |
|
176 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
| - |
|
177 |
fdi.setTagId(itemId);
|
| - |
|
178 |
itemPricing.put(itemId, fdi);
|
| - |
|
179 |
}
|
| - |
|
180 |
}
|
| - |
|
181 |
ffdr.setItems(new ArrayList<FofoDealItem>(itemPricing.values()));
|
| - |
|
182 |
dealResponse.add(ffdr);
|
| - |
|
183 |
}
|
| - |
|
184 |
|
| - |
|
185 |
} else {
|
| - |
|
186 |
return responseSender.badRequest(new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
| - |
|
187 |
}
|
| - |
|
188 |
return responseSender.ok(dealResponse);
|
| - |
|
189 |
}
|
| 122 |
|
190 |
|
| 123 |
@RequestMapping(value = "/online-deals", method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
191 |
@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 124 |
@ApiImplicitParams({
|
192 |
@ApiImplicitParams({
|
| 125 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
193 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 126 |
required = true, dataType = "string", paramType = "header")
|
- |
|
| 127 |
})
|
- |
|
| 128 |
@ApiOperation(value = "Get online deals")
|
194 |
@ApiOperation(value = "Get online deals")
|
| 129 |
public ResponseEntity<?> getOnlineDeals(HttpServletRequest request, @RequestParam(value="categoryId") String categoryId,
|
195 |
public ResponseEntity<?> getOnlineDeals(HttpServletRequest request,
|
| - |
|
196 |
@RequestParam(value = "categoryId") String categoryId, @RequestParam(value = "offset") String offset,
|
| 130 |
@RequestParam(value="offset") String offset, @RequestParam(value="limit") String limit, @RequestParam(value="sort", required=false) String sort,
|
197 |
@RequestParam(value = "limit") String limit, @RequestParam(value = "sort", required = false) String sort,
|
| - |
|
198 |
@RequestParam(value = "direction", required = false) String direction,
|
| 131 |
@RequestParam(value="direction", required=false) String direction, @RequestParam(value="filterData", required=false) String filterData ) throws Throwable{
|
199 |
@RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
|
| 132 |
logger.info("Request "+request.getParameterMap());
|
200 |
logger.info("Request " + request.getParameterMap());
|
| 133 |
String response = null;
|
201 |
String response = null;
|
| 134 |
int userId = (int)request.getAttribute("userId");
|
202 |
int userId = (int) request.getAttribute("userId");
|
| 135 |
UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
|
203 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 136 |
|
204 |
|
| 137 |
String uri = "/deals/"+userId;
|
205 |
String uri = "/deals/" + userId;
|
| 138 |
RestClient rc = new RestClient(SchemeType.HTTP, host , port);
|
206 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
| 139 |
Map<String, String> params = new HashMap<>();
|
207 |
Map<String, String> params = new HashMap<>();
|
| 140 |
params.put("offset", offset);
|
208 |
params.put("offset", offset);
|
| 141 |
params.put("limit", limit);
|
209 |
params.put("limit", limit);
|
| 142 |
params.put("categoryId", categoryId);
|
210 |
params.put("categoryId", categoryId);
|
| 143 |
params.put("direction", direction);
|
211 |
params.put("direction", direction);
|
| 144 |
params.put("sort", sort);
|
212 |
params.put("sort", sort);
|
| 145 |
params.put("source", "online");
|
213 |
params.put("source", "online");
|
| 146 |
params.put("filterData", filterData);
|
214 |
params.put("filterData", filterData);
|
| 147 |
if(userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
215 |
if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
|
| 148 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
216 |
params.put("tag_ids", getCommaSeparateTags(userId));
|
| 149 |
}
|
217 |
}
|
| 150 |
List<Object> responseObject = new ArrayList<>();
|
218 |
List<Object> responseObject = new ArrayList<>();
|
| 151 |
try {
|
219 |
try {
|
| 152 |
response = rc.get(uri, params);
|
220 |
response = rc.get(uri, params);
|
| 153 |
} catch (Exception | ProfitMandiBusinessException e) {
|
221 |
} catch (Exception | ProfitMandiBusinessException e) {
|
| 154 |
logger.error("Unable to get deals",e);
|
222 |
logger.error("Unable to get deals", e);
|
| - |
|
223 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| - |
|
224 |
request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(),
|
| 155 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, responseObject);
|
225 |
HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, responseObject);
|
| 156 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
226 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
| 157 |
}
|
227 |
}
|
| 158 |
JsonArray result_json = Json.parse(response).asArray();
|
228 |
JsonArray result_json = Json.parse(response).asArray();
|
| 159 |
for (JsonValue j : result_json ){
|
229 |
for (JsonValue j : result_json) {
|
| 160 |
logger.info("res "+j.asArray());
|
230 |
logger.info("res " + j.asArray());
|
| 161 |
List<Object> innerObject = new ArrayList<>();
|
231 |
List<Object> innerObject = new ArrayList<>();
|
| 162 |
for (JsonValue jsonObject : j.asArray()){
|
232 |
for (JsonValue jsonObject : j.asArray()) {
|
| 163 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
233 |
innerObject.add(toDealObject(jsonObject.asObject()));
|
| 164 |
}
|
234 |
}
|
| 165 |
if (innerObject.size() > 0){
|
235 |
if (innerObject.size() > 0) {
|
| 166 |
responseObject.add(innerObject);
|
236 |
responseObject.add(innerObject);
|
| 167 |
}
|
237 |
}
|
| 168 |
}
|
238 |
}
|
| - |
|
239 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| 169 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, responseObject);
|
240 |
request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,
|
| - |
|
241 |
responseObject);
|
| 170 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
242 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
|
| 171 |
}
|
243 |
}
|
| 172 |
|
- |
|
| 173 |
|
- |
|
| 174 |
/* @RequestMapping(value = "/direct-deals", method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
- |
|
| 175 |
@ApiImplicitParams({
|
- |
|
| 176 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
- |
|
| 177 |
required = true, dataType = "string", paramType = "header")
|
- |
|
| 178 |
})
|
- |
|
| 179 |
public ResponseEntity<?> getDirectDeals(HttpServletRequest request, @RequestParam(value="categoryId") String categoryId,@RequestParam(value="offset") String offset,
|
- |
|
| 180 |
@RequestParam(value="limit") String limit, @RequestParam(value="sort", required=false) String sort, @RequestParam(value="direction", required=false) String direction,
|
- |
|
| 181 |
@RequestParam(value="filterData", required=false) String filterData ){
|
- |
|
| 182 |
|
- |
|
| 183 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
- |
|
| 184 |
}*/
|
- |
|
| 185 |
|
244 |
|
| - |
|
245 |
/*
|
| - |
|
246 |
* @RequestMapping(value = "/direct-deals",
|
| - |
|
247 |
* method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
248 |
*
|
| - |
|
249 |
* @ApiImplicitParams({
|
| - |
|
250 |
*
|
| - |
|
251 |
* @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required =
|
| - |
|
252 |
* true, dataType = "string", paramType = "header") }) public
|
| - |
|
253 |
* ResponseEntity<?> getDirectDeals(HttpServletRequest
|
| - |
|
254 |
* request, @RequestParam(value="categoryId") String
|
| - |
|
255 |
* categoryId,@RequestParam(value="offset") String offset,
|
| - |
|
256 |
*
|
| - |
|
257 |
* @RequestParam(value="limit") String limit, @RequestParam(value="sort",
|
| - |
|
258 |
* required=false) String sort, @RequestParam(value="direction",
|
| - |
|
259 |
* required=false) String direction,
|
| - |
|
260 |
*
|
| - |
|
261 |
* @RequestParam(value="filterData", required=false) String filterData ){
|
| - |
|
262 |
*
|
| - |
|
263 |
* return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK); }
|
| - |
|
264 |
*/
|
| - |
|
265 |
|
| 186 |
private Object toDealObject(JsonObject jsonObject){
|
266 |
private Object toDealObject(JsonObject jsonObject) {
|
| 187 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1){
|
267 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
|
| 188 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
268 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
| 189 |
}
|
269 |
}
|
| 190 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|
270 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|
| 191 |
}
|
271 |
}
|
| 192 |
|
- |
|
| 193 |
|
272 |
|
| 194 |
@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
273 |
@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 195 |
@ApiImplicitParams({
|
274 |
@ApiImplicitParams({
|
| 196 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
275 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 197 |
required = true, dataType = "string", paramType = "header")
|
- |
|
| 198 |
})
|
- |
|
| 199 |
@ApiOperation(value = "Get brand list and count for category")
|
276 |
@ApiOperation(value = "Get brand list and count for category")
|
| 200 |
public ResponseEntity<?> getBrands(HttpServletRequest request, @RequestParam(value="category_id") String category_id){
|
277 |
public ResponseEntity<?> getBrands(HttpServletRequest request,
|
| - |
|
278 |
@RequestParam(value = "category_id") String category_id) {
|
| 201 |
logger.info("Request "+request.getParameterMap());
|
279 |
logger.info("Request " + request.getParameterMap());
|
| 202 |
String response = null;
|
280 |
String response = null;
|
| 203 |
//TODO: move to properties
|
281 |
// TODO: move to properties
|
| 204 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
282 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
| 205 |
RestClient rc = new RestClient(SchemeType.HTTP, host , port);
|
283 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
| 206 |
Map<String, String> params = new HashMap<>();
|
284 |
Map<String, String> params = new HashMap<>();
|
| 207 |
params.put("category_id", category_id);
|
285 |
params.put("category_id", category_id);
|
| 208 |
List<DealBrands> dealBrandsResponse = null;
|
286 |
List<DealBrands> dealBrandsResponse = null;
|
| 209 |
try {
|
287 |
try {
|
| 210 |
response = rc.get(uri, params);
|
288 |
response = rc.get(uri, params);
|
| 211 |
} catch (Exception | ProfitMandiBusinessException e) {
|
289 |
} catch (Exception | ProfitMandiBusinessException e) {
|
| 212 |
logger.error("Unable to get deals",e);
|
290 |
logger.error("Unable to get deals", e);
|
| - |
|
291 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| - |
|
292 |
request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(),
|
| 213 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, dealBrandsResponse);
|
293 |
HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, dealBrandsResponse);
|
| 214 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
294 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
| 215 |
}
|
295 |
}
|
| 216 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>(){}.getType());
|
296 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
| - |
|
297 |
}.getType());
|
| - |
|
298 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| 217 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, dealBrandsResponse);
|
299 |
request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,
|
| - |
|
300 |
dealBrandsResponse);
|
| 218 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
301 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
|
| 219 |
}
|
302 |
}
|
| 220 |
|
303 |
|
| 221 |
@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
304 |
@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 222 |
@ApiImplicitParams({
|
305 |
@ApiImplicitParams({
|
| 223 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
306 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 224 |
required = true, dataType = "string", paramType = "header")
|
- |
|
| 225 |
})
|
- |
|
| 226 |
@ApiOperation(value = "Get unit deal object")
|
307 |
@ApiOperation(value = "Get unit deal object")
|
| 227 |
public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value="id") long id){
|
308 |
public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id) {
|
| 228 |
String response = null;
|
309 |
String response = null;
|
| 229 |
//TODO: move to properties
|
310 |
// TODO: move to properties
|
| 230 |
String uri = "getDealById/"+id;
|
311 |
String uri = "getDealById/" + id;
|
| 231 |
System.out.println("Unit deal "+uri);
|
312 |
System.out.println("Unit deal " + uri);
|
| 232 |
RestClient rc = new RestClient(SchemeType.HTTP, host , port);
|
313 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
| 233 |
Map<String, String> params = new HashMap<>();
|
314 |
Map<String, String> params = new HashMap<>();
|
| 234 |
DealsResponse dealsResponse = null;
|
315 |
DealsResponse dealsResponse = null;
|
| 235 |
try {
|
316 |
try {
|
| 236 |
response = rc.get(uri, params);
|
317 |
response = rc.get(uri, params);
|
| 237 |
} catch (Exception | ProfitMandiBusinessException e) {
|
318 |
} catch (Exception | ProfitMandiBusinessException e) {
|
| 238 |
logger.error("Unable to get deals",e);
|
319 |
logger.error("Unable to get deals", e);
|
| 239 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, dealsResponse);
|
320 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| - |
|
321 |
request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(),
|
| - |
|
322 |
HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, dealsResponse);
|
| 240 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
323 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
| 241 |
}
|
324 |
}
|
| 242 |
JsonObject result_json = Json.parse(response).asObject();
|
325 |
JsonObject result_json = Json.parse(response).asObject();
|
| 243 |
if (!result_json.isEmpty()){
|
326 |
if (!result_json.isEmpty()) {
|
| 244 |
dealsResponse = new Gson().fromJson(response, DealsResponse.class);
|
327 |
dealsResponse = new Gson().fromJson(response, DealsResponse.class);
|
| 245 |
}
|
328 |
}
|
| - |
|
329 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| 246 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, dealsResponse);
|
330 |
request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,
|
| - |
|
331 |
dealsResponse);
|
| 247 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
332 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
|
| 248 |
}
|
333 |
}
|
| 249 |
|
334 |
|
| 250 |
}
|
335 |
}
|