| Line 11... |
Line 11... |
| 11 |
|
11 |
|
| 12 |
import org.slf4j.Logger;
|
12 |
import org.slf4j.Logger;
|
| 13 |
import org.slf4j.LoggerFactory;
|
13 |
import org.slf4j.LoggerFactory;
|
| 14 |
import org.springframework.beans.factory.annotation.Autowired;
|
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 15 |
import org.springframework.beans.factory.annotation.Value;
|
15 |
import org.springframework.beans.factory.annotation.Value;
|
| - |
|
16 |
import org.springframework.http.HttpHeaders;
|
| 16 |
import org.springframework.http.HttpStatus;
|
17 |
import org.springframework.http.HttpStatus;
|
| - |
|
18 |
import org.springframework.http.MediaType;
|
| 17 |
import org.springframework.http.ResponseEntity;
|
19 |
import org.springframework.http.ResponseEntity;
|
| 18 |
import org.springframework.stereotype.Controller;
|
20 |
import org.springframework.stereotype.Controller;
|
| 19 |
import org.springframework.transaction.annotation.Transactional;
|
21 |
import org.springframework.transaction.annotation.Transactional;
|
| 20 |
import org.springframework.web.bind.annotation.RequestBody;
|
22 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21 |
import org.springframework.web.bind.annotation.RequestMapping;
|
23 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| Line 39... |
Line 41... |
| 39 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
41 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 40 |
import com.spice.profitmandi.dao.entity.dtr.Permission;
|
42 |
import com.spice.profitmandi.dao.entity.dtr.Permission;
|
| 41 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
43 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 42 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
44 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 43 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
45 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| - |
|
46 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 44 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
47 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 45 |
import com.spice.profitmandi.dao.model.UserCart;
|
48 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 46 |
import com.spice.profitmandi.dao.repository.dtr.PermissionRepository;
|
49 |
import com.spice.profitmandi.dao.repository.dtr.PermissionRepository;
|
| 47 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
50 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 48 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
51 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 49 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
52 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 50 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
53 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| - |
|
54 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 51 |
import com.spice.profitmandi.dao.util.UserToRetailerMigrationUtil;
|
55 |
import com.spice.profitmandi.dao.util.MigrationUtil;
|
| 52 |
import com.spice.profitmandi.service.UserService;
|
56 |
import com.spice.profitmandi.service.UserService;
|
| 53 |
import com.spice.profitmandi.web.enumuration.UserStatus;
|
57 |
import com.spice.profitmandi.web.enumuration.UserStatus;
|
| 54 |
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
|
58 |
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
|
| 55 |
import com.spice.profitmandi.web.req.UserAddRoleRequest;
|
59 |
import com.spice.profitmandi.web.req.UserAddRoleRequest;
|
| 56 |
import com.spice.profitmandi.web.req.UserRequest;
|
60 |
import com.spice.profitmandi.web.req.UserRequest;
|
| Line 80... |
Line 84... |
| 80 |
@Value("${admin.token}")
|
84 |
@Value("${admin.token}")
|
| 81 |
private String validAdminToken;
|
85 |
private String validAdminToken;
|
| 82 |
|
86 |
|
| 83 |
@Autowired
|
87 |
@Autowired
|
| 84 |
UserRepository userRepository;
|
88 |
UserRepository userRepository;
|
| - |
|
89 |
|
| - |
|
90 |
@Autowired
|
| - |
|
91 |
com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 85 |
|
92 |
|
| 86 |
@Autowired
|
93 |
@Autowired
|
| 87 |
RetailerRepository retailerRepository;
|
94 |
RetailerRepository retailerRepository;
|
| 88 |
|
95 |
|
| 89 |
@Autowired
|
96 |
@Autowired
|
| Line 92... |
Line 99... |
| 92 |
@Autowired
|
99 |
@Autowired
|
| 93 |
UserAccountRepository userAccountRepository;
|
100 |
UserAccountRepository userAccountRepository;
|
| 94 |
|
101 |
|
| 95 |
@Autowired
|
102 |
@Autowired
|
| 96 |
PermissionRepository permissionRepository;
|
103 |
PermissionRepository permissionRepository;
|
| - |
|
104 |
|
| - |
|
105 |
@Autowired
|
| - |
|
106 |
AddressRepository addressRepository;
|
| 97 |
|
107 |
|
| 98 |
@Autowired
|
108 |
@Autowired
|
| 99 |
GoogleLoginProcessor googleLoginProcessor;
|
109 |
GoogleLoginProcessor googleLoginProcessor;
|
| 100 |
|
110 |
|
| 101 |
@Autowired
|
111 |
@Autowired
|
| 102 |
UserToRetailerMigrationUtil userToRetailerMigrationUtil;
|
112 |
MigrationUtil migrationUtil;
|
| 103 |
|
113 |
|
| 104 |
@Autowired
|
114 |
@Autowired
|
| 105 |
UserService userService;
|
115 |
UserService userService;
|
| 106 |
|
116 |
|
| 107 |
@SuppressWarnings("unchecked")
|
117 |
@SuppressWarnings("unchecked")
|
| Line 129... |
Line 139... |
| 129 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
139 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 130 |
return responseSender.badRequest(profitMandiBusinessException);
|
140 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 131 |
}
|
141 |
}
|
| 132 |
}
|
142 |
}
|
| 133 |
|
143 |
|
| 134 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_INFO, method = RequestMethod.GET)
|
144 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_DETAIL_BY_TOKEN, method = RequestMethod.GET)
|
| 135 |
@ApiImplicitParams({
|
145 |
@ApiImplicitParams({
|
| 136 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
146 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 137 |
public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
|
147 |
public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
|
| 138 |
Map<String, Object> responseMap = new HashMap<>();
|
148 |
Map<String, Object> responseMap = new HashMap<>();
|
| 139 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
149 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| Line 149... |
Line 159... |
| 149 |
}
|
159 |
}
|
| 150 |
if (user != null) {
|
160 |
if (user != null) {
|
| 151 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
161 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
| 152 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
162 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
| 153 |
responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
|
163 |
responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
|
| - |
|
164 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| - |
|
165 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(retailerId);
|
| - |
|
166 |
if(saholicUser.getAddressId() != null){
|
| - |
|
167 |
Address address = addressRepository.selectById(saholicUser.getAddressId());
|
| - |
|
168 |
responseMap.put(ProfitMandiConstants.ADDRESS, address);
|
| 154 |
|
169 |
}
|
| 155 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
170 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
| 156 |
LOGGER.info("userRoles {} ", userRoles);
|
171 |
LOGGER.info("userRoles {} ", userRoles);
|
| 157 |
String[] roleTypes = new String[userRoles.size()];
|
172 |
String[] roleTypes = new String[userRoles.size()];
|
| 158 |
|
173 |
|
| 159 |
// generate new token if roles have been updated
|
174 |
// generate new token if roles have been updated
|
| Line 423... |
Line 438... |
| 423 |
}
|
438 |
}
|
| 424 |
return responseSender.ok(responseMap);
|
439 |
return responseSender.ok(responseMap);
|
| 425 |
|
440 |
|
| 426 |
}
|
441 |
}
|
| 427 |
|
442 |
|
| - |
|
443 |
@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_MIGRATE, method = RequestMethod.GET)
|
| 428 |
@ApiImplicitParams({
|
444 |
@ApiImplicitParams({
|
| 429 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
445 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 430 |
public ResponseEntity<?> migrate(HttpServletRequest request) {
|
446 |
public ResponseEntity<?> migrate(HttpServletRequest request, @RequestParam(name = "userId") int userId) {
|
| 431 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
447 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 432 |
userToRetailerMigrationUtil.migrate();
|
448 |
migrationUtil.migrateUserToRetailer();
|
| 433 |
return responseSender.ok(ResponseCodeHolder.getMessage("OK_1000"));
|
449 |
return responseSender.ok(ResponseCodeHolder.getMessage("OK_1000"));
|
| 434 |
}
|
450 |
}
|
| 435 |
}
|
451 |
}
|