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