| 21248 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 25300 |
tejbeer |
3 |
import java.io.IOException;
|
| 21248 |
ashik.ali |
4 |
import java.time.LocalDateTime;
|
| 21855 |
amit.gupta |
5 |
import java.util.ArrayList;
|
| 25300 |
tejbeer |
6 |
import java.util.Base64;
|
| 21428 |
amit.gupta |
7 |
import java.util.HashMap;
|
| 23786 |
amit.gupta |
8 |
import java.util.HashSet;
|
| 21855 |
amit.gupta |
9 |
import java.util.List;
|
| 21277 |
ashik.ali |
10 |
import java.util.Map;
|
| 23786 |
amit.gupta |
11 |
import java.util.Set;
|
| 21248 |
ashik.ali |
12 |
|
|
|
13 |
import javax.servlet.http.HttpServletRequest;
|
|
|
14 |
|
| 25300 |
tejbeer |
15 |
import org.apache.http.client.ClientProtocolException;
|
| 23532 |
amit.gupta |
16 |
import org.apache.http.conn.HttpHostConnectException;
|
| 23786 |
amit.gupta |
17 |
import org.apache.logging.log4j.LogManager;
|
| 23859 |
ashik.ali |
18 |
import org.apache.logging.log4j.Logger;
|
| 21278 |
ashik.ali |
19 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21414 |
kshitij.so |
20 |
import org.springframework.beans.factory.annotation.Value;
|
| 21248 |
ashik.ali |
21 |
import org.springframework.http.ResponseEntity;
|
|
|
22 |
import org.springframework.stereotype.Controller;
|
| 21702 |
ashik.ali |
23 |
import org.springframework.transaction.annotation.Transactional;
|
| 21366 |
kshitij.so |
24 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21248 |
ashik.ali |
25 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
26 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
27 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
28 |
|
| 22015 |
ashik.ali |
29 |
import com.eclipsesource.json.Json;
|
| 21855 |
amit.gupta |
30 |
import com.eclipsesource.json.JsonArray;
|
|
|
31 |
import com.eclipsesource.json.JsonObject;
|
|
|
32 |
import com.eclipsesource.json.JsonValue;
|
|
|
33 |
import com.google.gson.Gson;
|
| 21248 |
ashik.ali |
34 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
| 21855 |
amit.gupta |
35 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 21248 |
ashik.ali |
36 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 22930 |
ashik.ali |
37 |
import com.spice.profitmandi.common.model.GoogleLoginRequest;
|
| 21248 |
ashik.ali |
38 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22492 |
amit.gupta |
39 |
import com.spice.profitmandi.common.model.RegisteredUserInfo;
|
| 21469 |
amit.gupta |
40 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 21282 |
ashik.ali |
41 |
import com.spice.profitmandi.common.util.JWTUtil;
|
| 21855 |
amit.gupta |
42 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 21740 |
ashik.ali |
43 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 21735 |
ashik.ali |
44 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 23858 |
ashik.ali |
45 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| 21735 |
ashik.ali |
46 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
47 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| 22355 |
ashik.ali |
48 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 21735 |
ashik.ali |
49 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 21643 |
ashik.ali |
50 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 21735 |
ashik.ali |
51 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 23786 |
amit.gupta |
52 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 21735 |
ashik.ali |
53 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
54 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
55 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 22355 |
ashik.ali |
56 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 24491 |
amit.gupta |
57 |
import com.spice.profitmandi.service.AuthService;
|
| 23798 |
amit.gupta |
58 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23787 |
amit.gupta |
59 |
import com.spice.profitmandi.service.user.UserService;
|
| 21469 |
amit.gupta |
60 |
import com.spice.profitmandi.web.enumuration.UserStatus;
|
| 21277 |
ashik.ali |
61 |
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
|
| 21366 |
kshitij.so |
62 |
import com.spice.profitmandi.web.req.UserRequest;
|
| 21855 |
amit.gupta |
63 |
import com.spice.profitmandi.web.res.Notification;
|
| 21248 |
ashik.ali |
64 |
|
| 21469 |
amit.gupta |
65 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
66 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
67 |
|
| 21248 |
ashik.ali |
68 |
/**
|
|
|
69 |
* @author ashikali
|
|
|
70 |
*
|
|
|
71 |
*/
|
|
|
72 |
@Controller
|
| 22037 |
amit.gupta |
73 |
@Transactional(rollbackFor=Throwable.class)
|
| 21248 |
ashik.ali |
74 |
public class UserController {
|
| 21469 |
amit.gupta |
75 |
|
| 21448 |
ashik.ali |
76 |
@Autowired
|
| 22930 |
ashik.ali |
77 |
private ResponseSender<?> responseSender;
|
| 21469 |
amit.gupta |
78 |
|
| 23568 |
govind |
79 |
private static final Logger LOGGER = LogManager.getLogger(UserController.class);
|
| 21469 |
amit.gupta |
80 |
|
| 21855 |
amit.gupta |
81 |
@Value("${notifications.api.host}")
|
|
|
82 |
private String nodeHost;
|
| 23204 |
ashik.ali |
83 |
|
| 21855 |
amit.gupta |
84 |
@Value("${notifications.api.port}")
|
|
|
85 |
private int nodePort;
|
|
|
86 |
|
| 21414 |
kshitij.so |
87 |
@Value("${admin.token}")
|
|
|
88 |
private String validAdminToken;
|
| 21469 |
amit.gupta |
89 |
|
| 21278 |
ashik.ali |
90 |
@Autowired
|
| 22873 |
ashik.ali |
91 |
private UserRepository userRepository;
|
| 22355 |
ashik.ali |
92 |
|
|
|
93 |
@Autowired
|
| 22873 |
ashik.ali |
94 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 21469 |
amit.gupta |
95 |
|
| 21278 |
ashik.ali |
96 |
@Autowired
|
| 22873 |
ashik.ali |
97 |
private RetailerRepository retailerRepository;
|
| 21485 |
amit.gupta |
98 |
|
|
|
99 |
@Autowired
|
| 22873 |
ashik.ali |
100 |
private UserRoleRepository userRoleRepository;
|
| 21469 |
amit.gupta |
101 |
|
| 21426 |
ashik.ali |
102 |
@Autowired
|
| 22873 |
ashik.ali |
103 |
private UserAccountRepository userAccountRepository;
|
| 22355 |
ashik.ali |
104 |
|
|
|
105 |
@Autowired
|
| 24491 |
amit.gupta |
106 |
private AuthService authService;
|
|
|
107 |
|
|
|
108 |
@Autowired
|
| 22873 |
ashik.ali |
109 |
private AddressRepository addressRepository;
|
| 21469 |
amit.gupta |
110 |
|
| 21426 |
ashik.ali |
111 |
@Autowired
|
| 22873 |
ashik.ali |
112 |
private GoogleLoginProcessor googleLoginProcessor;
|
| 21855 |
amit.gupta |
113 |
|
| 21784 |
amit.gupta |
114 |
@Autowired
|
| 22873 |
ashik.ali |
115 |
private UserService userService;
|
| 23786 |
amit.gupta |
116 |
|
|
|
117 |
@Autowired
|
| 23858 |
ashik.ali |
118 |
private RestClient restClient;
|
|
|
119 |
|
|
|
120 |
@Autowired
|
| 23798 |
amit.gupta |
121 |
private RoleManager roleManager;
|
| 23786 |
amit.gupta |
122 |
|
|
|
123 |
@Autowired
|
|
|
124 |
private RoleRepository roleRepository;
|
| 21469 |
amit.gupta |
125 |
|
|
|
126 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, method = RequestMethod.POST)
|
| 23698 |
amit.gupta |
127 |
public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest googleLoginRequest) throws ProfitMandiBusinessException{
|
|
|
128 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 24494 |
amit.gupta |
129 |
Map<String, Object> resultMap = googleLoginProcessor.process(googleLoginRequest);
|
|
|
130 |
LOGGER.info("Response sent is {}", resultMap);
|
| 23698 |
amit.gupta |
131 |
return responseSender.ok(googleLoginProcessor.process(googleLoginRequest));
|
| 21277 |
ashik.ali |
132 |
}
|
| 21469 |
amit.gupta |
133 |
|
|
|
134 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method = RequestMethod.GET)
|
| 22930 |
ashik.ali |
135 |
public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token) throws ProfitMandiBusinessException{
|
| 21469 |
amit.gupta |
136 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 22930 |
ashik.ali |
137 |
return responseSender.ok(JWTUtil.isExpired(token));
|
| 21282 |
ashik.ali |
138 |
}
|
| 21469 |
amit.gupta |
139 |
|
| 22355 |
ashik.ali |
140 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_DETAIL_BY_TOKEN, method = RequestMethod.GET)
|
| 21469 |
amit.gupta |
141 |
@ApiImplicitParams({
|
|
|
142 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
143 |
public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
|
|
|
144 |
Map<String, Object> responseMap = new HashMap<>();
|
|
|
145 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 21483 |
amit.gupta |
146 |
User user = null;
|
| 21855 |
amit.gupta |
147 |
if (userInfo.getUserId() > -1) {
|
| 21483 |
amit.gupta |
148 |
user = userRepository.selectById(userInfo.getUserId());
|
| 24497 |
amit.gupta |
149 |
if(!(userInfo.getEmail()==null || user.getEmailId().equalsIgnoreCase(userInfo.getEmail()))) {
|
| 24491 |
amit.gupta |
150 |
String userName = null;
|
|
|
151 |
if(user.getSecondryEmailId()!=null && user.getSecondryEmailId().equals(userInfo.getEmail())) {
|
|
|
152 |
userName = user.getFirstName() + " " + user.getLastName();
|
|
|
153 |
} else {
|
|
|
154 |
userName = authService.getNameByEmailId(userInfo.getEmail());
|
|
|
155 |
}
|
|
|
156 |
responseMap.put(ProfitMandiConstants.USER_ID, userInfo.getUserId());
|
|
|
157 |
responseMap.put(ProfitMandiConstants.USER_NAME, userName);
|
|
|
158 |
responseMap.put(ProfitMandiConstants.USER_STATUS, "fofoAssociate");
|
|
|
159 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
|
|
160 |
return responseSender.ok(responseMap);
|
|
|
161 |
}
|
| 21483 |
amit.gupta |
162 |
} else {
|
|
|
163 |
try {
|
|
|
164 |
user = userRepository.selectByEmailId(userInfo.getEmail());
|
|
|
165 |
} catch (ProfitMandiBusinessException e1) {
|
|
|
166 |
}
|
| 23204 |
ashik.ali |
167 |
if(user == null){
|
|
|
168 |
try {
|
|
|
169 |
user = userRepository.selectBySecondryEmailId(userInfo.getEmail());
|
|
|
170 |
} catch (ProfitMandiBusinessException e1) {
|
|
|
171 |
LOGGER.info("Uneregistered user", userInfo.getEmail());
|
|
|
172 |
}
|
|
|
173 |
}
|
| 21483 |
amit.gupta |
174 |
}
|
|
|
175 |
if (user != null) {
|
| 23858 |
ashik.ali |
176 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| 21491 |
amit.gupta |
177 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
| 21526 |
amit.gupta |
178 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
| 22017 |
amit.gupta |
179 |
responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
|
| 23786 |
amit.gupta |
180 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
| 22554 |
amit.gupta |
181 |
//LOGGER.info("userRoles {} ", userRoles);
|
| 22032 |
ashik.ali |
182 |
|
|
|
183 |
// generate new token if roles have been updated
|
| 23786 |
amit.gupta |
184 |
if (userInfo.getRoleIds() == null || roleIds.size() != userInfo.getRoleIds().size()) {
|
| 23858 |
ashik.ali |
185 |
String[] roleIdStrings = new String[roleIds.size()];
|
| 22603 |
amit.gupta |
186 |
int index = 0;
|
| 23786 |
amit.gupta |
187 |
for (int roleId : roleIds) {
|
| 23858 |
ashik.ali |
188 |
roleIdStrings[index++] = String.valueOf(roleId);
|
| 22603 |
amit.gupta |
189 |
}
|
| 23858 |
ashik.ali |
190 |
String newToken = JWTUtil.create(user.getId(), retailerId, roleIdStrings);
|
| 21483 |
amit.gupta |
191 |
responseMap.put("newAuthToken", newToken);
|
|
|
192 |
}
|
| 23858 |
ashik.ali |
193 |
// if user is retailer
|
| 23786 |
amit.gupta |
194 |
Set<Integer> roleIdsSet = new HashSet<Integer>(roleIds);
|
| 23858 |
ashik.ali |
195 |
if (roleManager.isRetailer(roleIdsSet)) {
|
| 22032 |
ashik.ali |
196 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
|
|
197 |
Retailer retailer = retailerRepository.selectById(uc.getUserId());
|
| 22370 |
amit.gupta |
198 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
|
|
|
199 |
if(saholicUser.getAddressId() != null){
|
|
|
200 |
Address address = addressRepository.selectById(saholicUser.getAddressId());
|
|
|
201 |
responseMap.put(ProfitMandiConstants.ADDRESS, address);
|
|
|
202 |
}
|
| 21485 |
amit.gupta |
203 |
// if retailer is activated 1 then verified retailer
|
|
|
204 |
// else if migrated is 1 then old retailer
|
| 22497 |
amit.gupta |
205 |
// also lets incoporte old process i.e is user is activated then also retailer is verified retailer
|
| 21485 |
amit.gupta |
206 |
// else retailer is not verifed
|
| 22497 |
amit.gupta |
207 |
if (retailer.isActive() || user.isActivated()) {
|
| 23798 |
amit.gupta |
208 |
if (roleManager.isPartner(roleIdsSet)) {
|
| 22017 |
amit.gupta |
209 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.FOFO.getValue());
|
|
|
210 |
} else {
|
|
|
211 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
|
|
|
212 |
}
|
| 22032 |
ashik.ali |
213 |
} else if (retailer.isMigrated()) {
|
| 21485 |
amit.gupta |
214 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.RETAILER.getValue());
|
| 21469 |
amit.gupta |
215 |
} else {
|
| 21485 |
amit.gupta |
216 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_VERIFIED_RETAILER.getValue());
|
| 21469 |
amit.gupta |
217 |
}
|
| 23798 |
amit.gupta |
218 |
} else if (roleManager.isUser(roleIdsSet)) {
|
| 22502 |
amit.gupta |
219 |
responseMap.put("userInfo", getRegisteredUserInfo(user));
|
| 21469 |
amit.gupta |
220 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.REGISTERED.getValue());
|
| 22032 |
ashik.ali |
221 |
}
|
| 21491 |
amit.gupta |
222 |
} else {
|
|
|
223 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
|
|
|
224 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
| 21469 |
amit.gupta |
225 |
}
|
| 22032 |
ashik.ali |
226 |
|
| 21469 |
amit.gupta |
227 |
return responseSender.ok(responseMap);
|
|
|
228 |
}
|
| 22492 |
amit.gupta |
229 |
|
| 22502 |
amit.gupta |
230 |
private RegisteredUserInfo getRegisteredUserInfo(User user) throws Throwable {
|
| 22492 |
amit.gupta |
231 |
RegisteredUserInfo ri = new RegisteredUserInfo();
|
|
|
232 |
ri.setCity(user.getCity());
|
|
|
233 |
ri.setFirstName(user.getFirstName());
|
|
|
234 |
ri.setLastName(user.getLastName());
|
| 22493 |
amit.gupta |
235 |
ri.setPhone(user.getMobileNumber());
|
| 22492 |
amit.gupta |
236 |
ri.setPinCode(user.getPinCode());
|
| 22845 |
amit.gupta |
237 |
ri.setState(user.getState());
|
| 22492 |
amit.gupta |
238 |
return ri;
|
|
|
239 |
}
|
| 21469 |
amit.gupta |
240 |
|
|
|
241 |
@RequestMapping(value = ProfitMandiConstants.URL_USER, method = RequestMethod.POST)
|
| 21501 |
amit.gupta |
242 |
@ApiImplicitParams({
|
| 22032 |
ashik.ali |
243 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
244 |
public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest)
|
| 22930 |
ashik.ali |
245 |
throws ProfitMandiBusinessException {
|
| 21469 |
amit.gupta |
246 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21368 |
kshitij.so |
247 |
User user = new User();
|
|
|
248 |
user.setFirstName(userRequest.getFirstName());
|
|
|
249 |
user.setLastName(userRequest.getLastName());
|
|
|
250 |
user.setCity(userRequest.getCity());
|
|
|
251 |
user.setPinCode(Integer.valueOf(userRequest.getPinCode()));
|
| 22845 |
amit.gupta |
252 |
user.setState(userRequest.getState());
|
| 21708 |
amit.gupta |
253 |
user.setMobileNumber(userRequest.getMobieNumber());
|
| 21368 |
kshitij.so |
254 |
user.setEmailId(userRequest.getEmailId());
|
|
|
255 |
user.setUsername("");
|
|
|
256 |
user.setPassword("");
|
|
|
257 |
user.setMobile_verified(false);
|
|
|
258 |
user.setReferral_url("");
|
|
|
259 |
user.setGroup_id(1);
|
| 22504 |
amit.gupta |
260 |
user.setStatus(1);
|
| 21368 |
kshitij.so |
261 |
user.setActivated(false);
|
| 21501 |
amit.gupta |
262 |
user.setCreateTimestamp(LocalDateTime.now());
|
|
|
263 |
user.setUpdateTimestamp(LocalDateTime.now());
|
| 22930 |
ashik.ali |
264 |
userRepository.persist(user);
|
| 23858 |
ashik.ali |
265 |
Role role = roleRepository.selectByName(RoleType.USER.toString());
|
| 22930 |
ashik.ali |
266 |
UserRole userRole = new UserRole();
|
| 23858 |
ashik.ali |
267 |
userRole.setRoleId(role.getId());
|
| 22930 |
ashik.ali |
268 |
userRole.setUserId(user.getId());
|
|
|
269 |
userRoleRepository.persist(userRole);
|
|
|
270 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1000"));
|
|
|
271 |
|
| 21278 |
ashik.ali |
272 |
}
|
| 21469 |
amit.gupta |
273 |
|
|
|
274 |
|
|
|
275 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ID, method = RequestMethod.GET)
|
| 22930 |
ashik.ali |
276 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id) throws ProfitMandiBusinessException{
|
| 21469 |
amit.gupta |
277 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 22930 |
ashik.ali |
278 |
return responseSender.ok(userRepository.selectById(id));
|
| 21248 |
ashik.ali |
279 |
}
|
| 21469 |
amit.gupta |
280 |
|
|
|
281 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER, method = RequestMethod.GET)
|
|
|
282 |
public ResponseEntity<?> getByMobileNumber(HttpServletRequest request,
|
| 22930 |
ashik.ali |
283 |
@RequestParam(name = "mobileNumber") String mobileNumber) throws ProfitMandiBusinessException{
|
| 21469 |
amit.gupta |
284 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 22930 |
ashik.ali |
285 |
return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
|
| 21248 |
ashik.ali |
286 |
}
|
| 23204 |
ashik.ali |
287 |
|
|
|
288 |
|
| 21469 |
amit.gupta |
289 |
|
| 21784 |
amit.gupta |
290 |
@ApiImplicitParams({
|
| 21501 |
amit.gupta |
291 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
292 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ACTIVATE, method = RequestMethod.POST)
|
|
|
293 |
public ResponseEntity<?> activateUser(HttpServletRequest request,
|
| 21784 |
amit.gupta |
294 |
@RequestParam(name = "activationCode") String activationCode) throws Throwable {
|
| 21855 |
amit.gupta |
295 |
int userId = (int) request.getAttribute("userId");
|
| 21784 |
amit.gupta |
296 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
297 |
return responseSender.ok(userService.updateActivation(userId, uc.getUserId(), activationCode));
|
|
|
298 |
}
|
| 21855 |
amit.gupta |
299 |
|
|
|
300 |
@ApiImplicitParams({
|
|
|
301 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
302 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_NOTIFICATIONS, method = RequestMethod.GET)
|
|
|
303 |
public ResponseEntity<?> getNofitications(HttpServletRequest request,
|
|
|
304 |
@RequestParam(name = "androidId") String androidId, @RequestParam(name = "pageNumber") int pageNumber,
|
| 22930 |
ashik.ali |
305 |
@RequestParam(name = "pageSize") int pageSize) throws ProfitMandiBusinessException{
|
| 21855 |
amit.gupta |
306 |
int userId = (int) request.getAttribute("userId");
|
|
|
307 |
String restResponse = null;
|
|
|
308 |
Map<String, String> params = new HashMap<>();
|
|
|
309 |
|
|
|
310 |
String uri = "/getAllNotifications";
|
|
|
311 |
params.put("user_id", userId + "");
|
|
|
312 |
params.put("android_id", androidId);
|
|
|
313 |
params.put("limit", pageSize + "");
|
|
|
314 |
params.put("offset", "" + ((pageNumber - 1) * pageSize));
|
| 23532 |
amit.gupta |
315 |
try {
|
| 23858 |
ashik.ali |
316 |
restResponse = restClient.get(SchemeType.HTTP, nodeHost, nodePort, uri, params);
|
|
|
317 |
} catch (HttpHostConnectException e) {
|
| 23532 |
amit.gupta |
318 |
throw new ProfitMandiBusinessException("", "", "Could not Connect to host");
|
|
|
319 |
}
|
| 22930 |
ashik.ali |
320 |
|
| 21855 |
amit.gupta |
321 |
|
|
|
322 |
JsonArray result_json = Json.parse(restResponse).asArray();
|
|
|
323 |
|
|
|
324 |
List<Notification> notifications = new ArrayList<>();
|
|
|
325 |
|
|
|
326 |
for (JsonValue j : result_json) {
|
|
|
327 |
notifications.add(toNotifiaction(j.asObject()));
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
return responseSender.ok(notifications);
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
private Notification toNotifiaction(JsonObject jsonObject) {
|
|
|
334 |
Notification n = (Notification) (new Gson().fromJson(jsonObject.toString(), Notification.class));
|
| 21995 |
amit.gupta |
335 |
if (n.getStatus().equals("opened") || n.getStatus().equals("referrer") || n.getStatus().equals("seen")) {
|
| 21855 |
amit.gupta |
336 |
n.setSeen(true);
|
|
|
337 |
}
|
|
|
338 |
return n;
|
|
|
339 |
}
|
|
|
340 |
|
| 21426 |
ashik.ali |
341 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_IS_EXIST_MOBILE_NUMBER, method = RequestMethod.GET)
|
| 21469 |
amit.gupta |
342 |
public ResponseEntity<?> isMobileNumberExist(HttpServletRequest request,
|
|
|
343 |
@RequestParam(name = "mobileNumber") String mobileNumber) {
|
|
|
344 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21448 |
ashik.ali |
345 |
return responseSender.ok(userRepository.isExistByMobileNumber(mobileNumber));
|
| 21426 |
ashik.ali |
346 |
}
|
| 21469 |
amit.gupta |
347 |
|
|
|
348 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID, method = RequestMethod.GET)
|
| 22930 |
ashik.ali |
349 |
public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId) throws ProfitMandiBusinessException{
|
| 21469 |
amit.gupta |
350 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 23204 |
ashik.ali |
351 |
User user = null;
|
|
|
352 |
try{
|
|
|
353 |
user = userRepository.selectByEmailId(emailId);
|
|
|
354 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
355 |
user = userRepository.selectBySecondryEmailId(emailId);
|
|
|
356 |
}
|
|
|
357 |
return responseSender.ok(user);
|
| 21248 |
ashik.ali |
358 |
}
|
| 21469 |
amit.gupta |
359 |
|
|
|
360 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL, method = RequestMethod.GET)
|
|
|
361 |
public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id) {
|
|
|
362 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21448 |
ashik.ali |
363 |
return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
|
| 21248 |
ashik.ali |
364 |
}
|
| 23204 |
ashik.ali |
365 |
|
|
|
366 |
@ApiImplicitParams({
|
|
|
367 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
368 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID_AND_FOFO_STORE_CODE, method = RequestMethod.GET)
|
|
|
369 |
public ResponseEntity<?> getSecondryEmailAndStoreCode(HttpServletRequest request) throws ProfitMandiBusinessException{
|
|
|
370 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
371 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
372 |
return responseSender.ok(userService.getEmailsAndFofoStoreCodeByUserId(userId));
|
|
|
373 |
}
|
|
|
374 |
|
|
|
375 |
@ApiImplicitParams({
|
| 24491 |
amit.gupta |
376 |
@ApiImplicitParam(name = "Auth-Token", value = "-Token", required = true, dataType = "string", paramType = "header") })
|
| 23858 |
ashik.ali |
377 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID, method = RequestMethod.PUT)
|
| 23204 |
ashik.ali |
378 |
public ResponseEntity<?> updateSecondryEmailId(HttpServletRequest request,
|
|
|
379 |
@RequestParam(name = ProfitMandiConstants.SECONDRY_EMAIL_ID) String secondryEmailId) throws Throwable {
|
|
|
380 |
int userId = (int) request.getAttribute("userId");
|
|
|
381 |
User user = userRepository.selectById(userId);
|
|
|
382 |
user.setSecondryEmailId(secondryEmailId);
|
|
|
383 |
userRepository.persist(user);
|
|
|
384 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1001"));
|
|
|
385 |
}
|
| 21414 |
kshitij.so |
386 |
|
|
|
387 |
@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
|
| 21469 |
amit.gupta |
388 |
public ResponseEntity<?> getAdminToken(HttpServletRequest request,
|
|
|
389 |
@RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) {
|
|
|
390 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
391 |
if (!adminToken.equals(validAdminToken)) {
|
| 22930 |
ashik.ali |
392 |
return responseSender.forbidden(null);
|
| 21414 |
kshitij.so |
393 |
}
|
| 21469 |
amit.gupta |
394 |
|
| 21414 |
kshitij.so |
395 |
Map<String, Object> responseMap = new HashMap<>(2);
|
| 23204 |
ashik.ali |
396 |
User user = null;
|
| 21469 |
amit.gupta |
397 |
try {
|
| 23204 |
ashik.ali |
398 |
user = userRepository.selectByEmailId(emailId);
|
|
|
399 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
400 |
|
|
|
401 |
}
|
|
|
402 |
|
|
|
403 |
if(user == null){
|
|
|
404 |
try{
|
|
|
405 |
user = userRepository.selectBySecondryEmailId(emailId);
|
|
|
406 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
407 |
|
|
|
408 |
}
|
|
|
409 |
}
|
|
|
410 |
if(user != null){
|
| 23858 |
ashik.ali |
411 |
int retailerId = 0;
|
|
|
412 |
try {
|
|
|
413 |
retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
|
|
414 |
} catch (ProfitMandiBusinessException e) {
|
|
|
415 |
// TODO Auto-generated catch block
|
|
|
416 |
e.printStackTrace();
|
|
|
417 |
}
|
|
|
418 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
|
|
419 |
String[] roleIdsString = new String[roleIds.size()];
|
| 21414 |
kshitij.so |
420 |
int index = 0;
|
| 23858 |
ashik.ali |
421 |
for (int roleId : roleIds) {
|
|
|
422 |
roleIdsString[index++] = String.valueOf(roleId);
|
| 21414 |
kshitij.so |
423 |
}
|
| 23858 |
ashik.ali |
424 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), retailerId, roleIdsString));
|
| 21414 |
kshitij.so |
425 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
| 23204 |
ashik.ali |
426 |
}else{
|
| 21469 |
amit.gupta |
427 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(emailId));
|
| 21414 |
kshitij.so |
428 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
|
|
429 |
}
|
| 21448 |
ashik.ali |
430 |
return responseSender.ok(responseMap);
|
| 21469 |
amit.gupta |
431 |
|
| 21414 |
kshitij.so |
432 |
}
|
| 25300 |
tejbeer |
433 |
|
|
|
434 |
@RequestMapping(value = "/mobileappsettings", method = RequestMethod.POST)
|
|
|
435 |
public ResponseEntity<?> mobileAppSettings(HttpServletRequest request,@RequestParam(name = "t") int timestamp,@RequestParam(name = "imeinumber") String imeinumber) throws ProfitMandiBusinessException, ClientProtocolException, IOException{
|
|
|
436 |
|
|
|
437 |
final String uri = "http://api.profittill.com/mobileappsettings?t="+timestamp+"&imeinumber="+imeinumber;
|
|
|
438 |
final String BASIC_AUTH = "Basic " + Base64.getEncoder().encodeToString("dtr:dtr18Feb2015".getBytes());
|
|
|
439 |
Map<String, String> headers = new HashMap<>();
|
|
|
440 |
Map<String, String> params = new HashMap<>();
|
|
|
441 |
headers.put("Authorization", BASIC_AUTH);
|
|
|
442 |
return responseSender.ok(restClient.post(uri, params, headers));
|
|
|
443 |
}
|
| 22032 |
ashik.ali |
444 |
|
| 21248 |
ashik.ali |
445 |
}
|