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