| Line 10... |
Line 10... |
| 10 |
|
10 |
|
| 11 |
import javax.servlet.http.HttpServletRequest;
|
11 |
import javax.servlet.http.HttpServletRequest;
|
| 12 |
|
12 |
|
| 13 |
import org.apache.http.conn.HttpHostConnectException;
|
13 |
import org.apache.http.conn.HttpHostConnectException;
|
| 14 |
import org.apache.logging.log4j.LogManager;
|
14 |
import org.apache.logging.log4j.LogManager;
|
| 15 |
import org.apache.logging.log4j.Logger;
|
15 |
import org.slf4j.Logger;
|
| 16 |
import org.springframework.beans.factory.annotation.Autowired;
|
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 17 |
import org.springframework.beans.factory.annotation.Value;
|
17 |
import org.springframework.beans.factory.annotation.Value;
|
| 18 |
import org.springframework.http.ResponseEntity;
|
18 |
import org.springframework.http.ResponseEntity;
|
| 19 |
import org.springframework.stereotype.Controller;
|
19 |
import org.springframework.stereotype.Controller;
|
| 20 |
import org.springframework.transaction.annotation.Transactional;
|
20 |
import org.springframework.transaction.annotation.Transactional;
|
| Line 36... |
Line 36... |
| 36 |
import com.spice.profitmandi.common.model.RegisteredUserInfo;
|
36 |
import com.spice.profitmandi.common.model.RegisteredUserInfo;
|
| 37 |
import com.spice.profitmandi.common.model.UserInfo;
|
37 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 38 |
import com.spice.profitmandi.common.util.JWTUtil;
|
38 |
import com.spice.profitmandi.common.util.JWTUtil;
|
| 39 |
import com.spice.profitmandi.common.web.client.RestClient;
|
39 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 40 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
40 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 41 |
import com.spice.profitmandi.dao.entity.dtr.Permission;
|
- |
|
| 42 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
41 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| - |
|
42 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| 43 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
43 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 44 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
44 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| 45 |
import com.spice.profitmandi.dao.entity.user.Address;
|
45 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 46 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
46 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 47 |
import com.spice.profitmandi.dao.model.UserCart;
|
47 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 48 |
import com.spice.profitmandi.dao.repository.dtr.PermissionRepository;
|
- |
|
| 49 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
48 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 50 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
49 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 51 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
50 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 52 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
51 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 53 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
52 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 54 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
53 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 55 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
54 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 56 |
import com.spice.profitmandi.service.user.UserService;
|
55 |
import com.spice.profitmandi.service.user.UserService;
|
| 57 |
import com.spice.profitmandi.web.enumuration.UserStatus;
|
56 |
import com.spice.profitmandi.web.enumuration.UserStatus;
|
| 58 |
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
|
57 |
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
|
| 59 |
import com.spice.profitmandi.web.req.UserAddRoleRequest;
|
- |
|
| 60 |
import com.spice.profitmandi.web.req.UserRequest;
|
58 |
import com.spice.profitmandi.web.req.UserRequest;
|
| 61 |
import com.spice.profitmandi.web.res.Notification;
|
59 |
import com.spice.profitmandi.web.res.Notification;
|
| 62 |
|
60 |
|
| 63 |
import io.swagger.annotations.ApiImplicitParam;
|
61 |
import io.swagger.annotations.ApiImplicitParam;
|
| 64 |
import io.swagger.annotations.ApiImplicitParams;
|
62 |
import io.swagger.annotations.ApiImplicitParams;
|
| Line 97... |
Line 95... |
| 97 |
@Autowired
|
95 |
@Autowired
|
| 98 |
private UserRoleRepository userRoleRepository;
|
96 |
private UserRoleRepository userRoleRepository;
|
| 99 |
|
97 |
|
| 100 |
@Autowired
|
98 |
@Autowired
|
| 101 |
private UserAccountRepository userAccountRepository;
|
99 |
private UserAccountRepository userAccountRepository;
|
| 102 |
|
- |
|
| 103 |
@Autowired
|
- |
|
| 104 |
private PermissionRepository permissionRepository;
|
- |
|
| 105 |
|
100 |
|
| 106 |
@Autowired
|
101 |
@Autowired
|
| 107 |
private AddressRepository addressRepository;
|
102 |
private AddressRepository addressRepository;
|
| 108 |
|
103 |
|
| 109 |
@Autowired
|
104 |
@Autowired
|
| Line 111... |
Line 106... |
| 111 |
|
106 |
|
| 112 |
@Autowired
|
107 |
@Autowired
|
| 113 |
private UserService userService;
|
108 |
private UserService userService;
|
| 114 |
|
109 |
|
| 115 |
@Autowired
|
110 |
@Autowired
|
| - |
|
111 |
private RestClient restClient;
|
| - |
|
112 |
|
| - |
|
113 |
@Autowired
|
| 116 |
private RoleManager roleManager;
|
114 |
private RoleManager roleManager;
|
| 117 |
|
115 |
|
| 118 |
@Autowired
|
116 |
@Autowired
|
| 119 |
private RoleRepository roleRepository;
|
117 |
private RoleRepository roleRepository;
|
| 120 |
|
118 |
|
| Line 151... |
Line 149... |
| 151 |
LOGGER.info("Uneregistered user", userInfo.getEmail());
|
149 |
LOGGER.info("Uneregistered user", userInfo.getEmail());
|
| 152 |
}
|
150 |
}
|
| 153 |
}
|
151 |
}
|
| 154 |
}
|
152 |
}
|
| 155 |
if (user != null) {
|
153 |
if (user != null) {
|
| - |
|
154 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| 156 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
155 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
| 157 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
156 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
| 158 |
responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
|
157 |
responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
|
| 159 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
158 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
| 160 |
//LOGGER.info("userRoles {} ", userRoles);
|
159 |
//LOGGER.info("userRoles {} ", userRoles);
|
| 161 |
|
160 |
|
| 162 |
// generate new token if roles have been updated
|
161 |
// generate new token if roles have been updated
|
| 163 |
if (userInfo.getRoleIds() == null || roleIds.size() != userInfo.getRoleIds().size()) {
|
162 |
if (userInfo.getRoleIds() == null || roleIds.size() != userInfo.getRoleIds().size()) {
|
| 164 |
String[] roleIdArray = new String[roleIds.size()];
|
163 |
String[] roleIdStrings = new String[roleIds.size()];
|
| 165 |
int index = 0;
|
164 |
int index = 0;
|
| 166 |
for (int roleId : roleIds) {
|
165 |
for (int roleId : roleIds) {
|
| 167 |
roleIdArray[index++] = String.valueOf(roleId);
|
166 |
roleIdStrings[index++] = String.valueOf(roleId);
|
| 168 |
}
|
167 |
}
|
| 169 |
String newToken = JWTUtil.create(user.getId(), roleIdArray);
|
168 |
String newToken = JWTUtil.create(user.getId(), retailerId, roleIdStrings);
|
| 170 |
responseMap.put("newAuthToken", newToken);
|
169 |
responseMap.put("newAuthToken", newToken);
|
| 171 |
}
|
170 |
}
|
| 172 |
|
- |
|
| - |
|
171 |
// if user is retailer
|
| 173 |
Set<Integer> roleIdsSet = new HashSet<Integer>(roleIds);
|
172 |
Set<Integer> roleIdsSet = new HashSet<Integer>(roleIds);
|
| 174 |
if (roleManager.isRetailer(new HashSet<Integer>(roleIds))) {
|
173 |
if (roleManager.isRetailer(roleIdsSet)) {
|
| 175 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
174 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| 176 |
Retailer retailer = retailerRepository.selectById(uc.getUserId());
|
175 |
Retailer retailer = retailerRepository.selectById(uc.getUserId());
|
| 177 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
|
176 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
|
| 178 |
if(saholicUser.getAddressId() != null){
|
177 |
if(saholicUser.getAddressId() != null){
|
| 179 |
Address address = addressRepository.selectById(saholicUser.getAddressId());
|
178 |
Address address = addressRepository.selectById(saholicUser.getAddressId());
|
| Line 239... |
Line 238... |
| 239 |
user.setStatus(1);
|
238 |
user.setStatus(1);
|
| 240 |
user.setActivated(false);
|
239 |
user.setActivated(false);
|
| 241 |
user.setCreateTimestamp(LocalDateTime.now());
|
240 |
user.setCreateTimestamp(LocalDateTime.now());
|
| 242 |
user.setUpdateTimestamp(LocalDateTime.now());
|
241 |
user.setUpdateTimestamp(LocalDateTime.now());
|
| 243 |
userRepository.persist(user);
|
242 |
userRepository.persist(user);
|
| - |
|
243 |
Role role = roleRepository.selectByName(RoleType.USER.toString());
|
| 244 |
UserRole userRole = new UserRole();
|
244 |
UserRole userRole = new UserRole();
|
| 245 |
userRole.setRoleId(roleRepository.selectByName(RoleType.USER.name()).getId());
|
245 |
userRole.setRoleId(role.getId());
|
| 246 |
userRole.setUserId(user.getId());
|
246 |
userRole.setUserId(user.getId());
|
| 247 |
userRoleRepository.persist(userRole);
|
247 |
userRoleRepository.persist(userRole);
|
| 248 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1000"));
|
248 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1000"));
|
| 249 |
|
249 |
|
| 250 |
}
|
250 |
}
|
| Line 288... |
Line 288... |
| 288 |
String uri = "/getAllNotifications";
|
288 |
String uri = "/getAllNotifications";
|
| 289 |
params.put("user_id", userId + "");
|
289 |
params.put("user_id", userId + "");
|
| 290 |
params.put("android_id", androidId);
|
290 |
params.put("android_id", androidId);
|
| 291 |
params.put("limit", pageSize + "");
|
291 |
params.put("limit", pageSize + "");
|
| 292 |
params.put("offset", "" + ((pageNumber - 1) * pageSize));
|
292 |
params.put("offset", "" + ((pageNumber - 1) * pageSize));
|
| 293 |
RestClient rc = new RestClient();
|
- |
|
| 294 |
try {
|
293 |
try {
|
| 295 |
restResponse = rc.get(SchemeType.HTTP, nodeHost, nodePort, uri, params);
|
294 |
restResponse = restClient.get(SchemeType.HTTP, nodeHost, nodePort, uri, params);
|
| 296 |
} catch(HttpHostConnectException e) {
|
295 |
} catch (HttpHostConnectException e) {
|
| 297 |
throw new ProfitMandiBusinessException("", "", "Could not Connect to host");
|
296 |
throw new ProfitMandiBusinessException("", "", "Could not Connect to host");
|
| 298 |
}
|
297 |
}
|
| 299 |
|
298 |
|
| 300 |
|
299 |
|
| 301 |
JsonArray result_json = Json.parse(restResponse).asArray();
|
300 |
JsonArray result_json = Json.parse(restResponse).asArray();
|
| Line 334... |
Line 333... |
| 334 |
user = userRepository.selectBySecondryEmailId(emailId);
|
333 |
user = userRepository.selectBySecondryEmailId(emailId);
|
| 335 |
}
|
334 |
}
|
| 336 |
return responseSender.ok(user);
|
335 |
return responseSender.ok(user);
|
| 337 |
}
|
336 |
}
|
| 338 |
|
337 |
|
| 339 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ADD, method = RequestMethod.POST)
|
- |
|
| 340 |
public ResponseEntity<?> addRole(HttpServletRequest request, @RequestBody UserAddRoleRequest userAddRoleRequest) throws ProfitMandiBusinessException{
|
- |
|
| 341 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
- |
|
| 342 |
User user = userRepository.selectById(userAddRoleRequest.getUserId());
|
- |
|
| 343 |
|
- |
|
| 344 |
Permission permission = new Permission();
|
- |
|
| 345 |
permission.setType(userAddRoleRequest.getPermissionType());
|
- |
|
| 346 |
permission.setRoleType(RoleType.FOFO);;
|
- |
|
| 347 |
permissionRepository.persist(permission);
|
- |
|
| 348 |
UserRole userRole = new UserRole();
|
- |
|
| 349 |
userRole.setRoleId(userAddRoleRequest.getRoleId());
|
- |
|
| 350 |
userRole.setUserId(user.getId());
|
- |
|
| 351 |
userRoleRepository.persist(userRole);
|
- |
|
| 352 |
return responseSender.ok("");
|
- |
|
| 353 |
}
|
- |
|
| 354 |
|
- |
|
| 355 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_REMOVE, method = RequestMethod.DELETE)
|
- |
|
| 356 |
public ResponseEntity<?> removeRole(HttpServletRequest request, @RequestParam int roleId,
|
- |
|
| 357 |
@RequestParam(name = "userId") int userId) throws ProfitMandiBusinessException{
|
- |
|
| 358 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
- |
|
| 359 |
userRepository.selectById(userId);
|
- |
|
| 360 |
/*userRoleRepository.deleteByUserAndRoleId(userId, roleId);
|
- |
|
| 361 |
permissionRepository.deleteByRoleType(roleRepository.selectById(id));*/
|
- |
|
| 362 |
return responseSender.ok("");
|
- |
|
| 363 |
}
|
- |
|
| 364 |
|
- |
|
| 365 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL, method = RequestMethod.GET)
|
338 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL, method = RequestMethod.GET)
|
| 366 |
public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id) {
|
339 |
public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id) {
|
| 367 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
340 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 368 |
return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
|
341 |
return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
|
| 369 |
}
|
342 |
}
|
| Line 377... |
Line 350... |
| 377 |
return responseSender.ok(userService.getEmailsAndFofoStoreCodeByUserId(userId));
|
350 |
return responseSender.ok(userService.getEmailsAndFofoStoreCodeByUserId(userId));
|
| 378 |
}
|
351 |
}
|
| 379 |
|
352 |
|
| 380 |
@ApiImplicitParams({
|
353 |
@ApiImplicitParams({
|
| 381 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
354 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 382 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID, method = RequestMethod.PUT)
|
355 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID, method = RequestMethod.PUT)
|
| 383 |
public ResponseEntity<?> updateSecondryEmailId(HttpServletRequest request,
|
356 |
public ResponseEntity<?> updateSecondryEmailId(HttpServletRequest request,
|
| 384 |
@RequestParam(name = ProfitMandiConstants.SECONDRY_EMAIL_ID) String secondryEmailId) throws Throwable {
|
357 |
@RequestParam(name = ProfitMandiConstants.SECONDRY_EMAIL_ID) String secondryEmailId) throws Throwable {
|
| 385 |
int userId = (int) request.getAttribute("userId");
|
358 |
int userId = (int) request.getAttribute("userId");
|
| 386 |
User user = userRepository.selectById(userId);
|
359 |
User user = userRepository.selectById(userId);
|
| 387 |
user.setSecondryEmailId(secondryEmailId);
|
360 |
user.setSecondryEmailId(secondryEmailId);
|
| Line 411... |
Line 384... |
| 411 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
384 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 412 |
|
385 |
|
| 413 |
}
|
386 |
}
|
| 414 |
}
|
387 |
}
|
| 415 |
if(user != null){
|
388 |
if(user != null){
|
| - |
|
389 |
int retailerId = 0;
|
| - |
|
390 |
try {
|
| - |
|
391 |
retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| - |
|
392 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
393 |
// TODO Auto-generated catch block
|
| - |
|
394 |
e.printStackTrace();
|
| - |
|
395 |
}
|
| 416 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
396 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
| 417 |
String[] roleIds = new String[userRoles.size()];
|
397 |
String[] roleIdsString = new String[roleIds.size()];
|
| 418 |
int index = 0;
|
398 |
int index = 0;
|
| 419 |
for (UserRole userRole : userRoles) {
|
399 |
for (int roleId : roleIds) {
|
| 420 |
roleIds[index++] = String.valueOf(userRole.getRoleId());
|
400 |
roleIdsString[index++] = String.valueOf(roleId);
|
| 421 |
}
|
401 |
}
|
| 422 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), roleIds));
|
402 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), retailerId, roleIdsString));
|
| 423 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
403 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
| 424 |
}else{
|
404 |
}else{
|
| 425 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(emailId));
|
405 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(emailId));
|
| 426 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
406 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
| 427 |
}
|
407 |
}
|