| 21248 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
| 21428 |
amit.gupta |
4 |
import java.util.HashMap;
|
| 21277 |
ashik.ali |
5 |
import java.util.Map;
|
| 21428 |
amit.gupta |
6 |
import java.util.Set;
|
| 21469 |
amit.gupta |
7 |
import java.util.function.Predicate;
|
| 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.HttpStatus;
|
|
|
16 |
import org.springframework.http.ResponseEntity;
|
|
|
17 |
import org.springframework.stereotype.Controller;
|
| 21702 |
ashik.ali |
18 |
import org.springframework.transaction.annotation.Transactional;
|
| 21366 |
kshitij.so |
19 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21248 |
ashik.ali |
20 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
21 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
22 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
23 |
|
|
|
24 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
|
|
25 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
26 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21740 |
ashik.ali |
27 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
|
|
28 |
import com.spice.profitmandi.common.model.ResponseStatus;
|
| 21469 |
amit.gupta |
29 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 21282 |
ashik.ali |
30 |
import com.spice.profitmandi.common.util.JWTUtil;
|
| 21740 |
ashik.ali |
31 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 21735 |
ashik.ali |
32 |
import com.spice.profitmandi.dao.entity.dtr.Permission;
|
|
|
33 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
|
|
34 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
|
|
35 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
36 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
|
|
37 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 21643 |
ashik.ali |
38 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 21735 |
ashik.ali |
39 |
import com.spice.profitmandi.dao.repository.dtr.PermissionRepository;
|
|
|
40 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
|
|
41 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
|
|
42 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
43 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
44 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 21487 |
ashik.ali |
45 |
import com.spice.profitmandi.dao.util.UserToRetailerMigrationUtil;
|
| 21784 |
amit.gupta |
46 |
import com.spice.profitmandi.service.UserService;
|
| 21469 |
amit.gupta |
47 |
import com.spice.profitmandi.web.enumuration.UserStatus;
|
| 21277 |
ashik.ali |
48 |
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
|
| 21426 |
ashik.ali |
49 |
import com.spice.profitmandi.web.req.UserAddRoleRequest;
|
| 21366 |
kshitij.so |
50 |
import com.spice.profitmandi.web.req.UserRequest;
|
| 21248 |
ashik.ali |
51 |
|
| 21469 |
amit.gupta |
52 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
53 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
54 |
|
| 21248 |
ashik.ali |
55 |
/**
|
|
|
56 |
* @author ashikali
|
|
|
57 |
*
|
|
|
58 |
*/
|
|
|
59 |
@Controller
|
| 21702 |
ashik.ali |
60 |
@Transactional
|
| 21248 |
ashik.ali |
61 |
public class UserController {
|
| 21469 |
amit.gupta |
62 |
|
| 21448 |
ashik.ali |
63 |
@Autowired
|
|
|
64 |
ResponseSender<?> responseSender;
|
| 21469 |
amit.gupta |
65 |
|
|
|
66 |
private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
|
|
|
67 |
|
| 21414 |
kshitij.so |
68 |
@Value("${admin.token}")
|
|
|
69 |
private String validAdminToken;
|
| 21469 |
amit.gupta |
70 |
|
| 21278 |
ashik.ali |
71 |
@Autowired
|
|
|
72 |
UserRepository userRepository;
|
| 21469 |
amit.gupta |
73 |
|
| 21278 |
ashik.ali |
74 |
@Autowired
|
| 21485 |
amit.gupta |
75 |
RetailerRepository retailerRepository;
|
|
|
76 |
|
|
|
77 |
@Autowired
|
| 21426 |
ashik.ali |
78 |
RoleRepository roleRepository;
|
| 21469 |
amit.gupta |
79 |
|
| 21426 |
ashik.ali |
80 |
@Autowired
|
|
|
81 |
UserRoleRepository userRoleRepository;
|
| 21469 |
amit.gupta |
82 |
|
| 21426 |
ashik.ali |
83 |
@Autowired
|
| 21485 |
amit.gupta |
84 |
UserAccountRepository userAccountRepository;
|
|
|
85 |
|
|
|
86 |
@Autowired
|
| 21426 |
ashik.ali |
87 |
PermissionRepository permissionRepository;
|
| 21469 |
amit.gupta |
88 |
|
| 21426 |
ashik.ali |
89 |
@Autowired
|
| 21278 |
ashik.ali |
90 |
GoogleLoginProcessor googleLoginProcessor;
|
| 21487 |
ashik.ali |
91 |
|
|
|
92 |
@Autowired
|
|
|
93 |
UserToRetailerMigrationUtil userToRetailerMigrationUtil;
|
| 21784 |
amit.gupta |
94 |
|
|
|
95 |
@Autowired
|
|
|
96 |
UserService userService;
|
| 21469 |
amit.gupta |
97 |
|
| 21277 |
ashik.ali |
98 |
@SuppressWarnings("unchecked")
|
| 21469 |
amit.gupta |
99 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, method = RequestMethod.POST)
|
|
|
100 |
public ResponseEntity<?> googleLogin(HttpServletRequest request) {
|
|
|
101 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
102 |
final Map<String, Object> googleLoginMap = (Map<String, Object>) request
|
|
|
103 |
.getAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
|
| 21277 |
ashik.ali |
104 |
request.removeAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
|
|
|
105 |
try {
|
| 21448 |
ashik.ali |
106 |
return responseSender.ok(googleLoginProcessor.process(googleLoginMap));
|
| 21469 |
amit.gupta |
107 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
108 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
109 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21277 |
ashik.ali |
110 |
}
|
|
|
111 |
}
|
| 21469 |
amit.gupta |
112 |
|
|
|
113 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method = RequestMethod.GET)
|
|
|
114 |
public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token) {
|
|
|
115 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21282 |
ashik.ali |
116 |
try {
|
| 21448 |
ashik.ali |
117 |
return responseSender.ok(JWTUtil.isExpired(token));
|
| 21469 |
amit.gupta |
118 |
|
|
|
119 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
120 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
121 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21282 |
ashik.ali |
122 |
}
|
|
|
123 |
}
|
| 21469 |
amit.gupta |
124 |
|
|
|
125 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_INFO, method = RequestMethod.GET)
|
|
|
126 |
@ApiImplicitParams({
|
|
|
127 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
128 |
public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
|
|
|
129 |
Map<String, Object> responseMap = new HashMap<>();
|
|
|
130 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 21483 |
amit.gupta |
131 |
User user = null;
|
|
|
132 |
if(userInfo.getUserId()>-1){
|
|
|
133 |
user = userRepository.selectById(userInfo.getUserId());
|
|
|
134 |
} else {
|
|
|
135 |
try {
|
|
|
136 |
user = userRepository.selectByEmailId(userInfo.getEmail());
|
|
|
137 |
} catch (ProfitMandiBusinessException e1) {
|
| 21526 |
amit.gupta |
138 |
LOGGER.info("Uneregistered user", userInfo.getEmail());
|
| 21483 |
amit.gupta |
139 |
}
|
|
|
140 |
}
|
|
|
141 |
if (user != null) {
|
| 21491 |
amit.gupta |
142 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
| 21526 |
amit.gupta |
143 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
| 21483 |
amit.gupta |
144 |
|
|
|
145 |
Set<Role> roles = user.getRoles();
|
|
|
146 |
//generate new token if roles size is different
|
|
|
147 |
if(userInfo.getRoleNames() == null || roles.size() != userInfo.getRoleNames().size()) {
|
|
|
148 |
String[] roleTypes = new String[roles.size()];
|
|
|
149 |
int index = 0;
|
|
|
150 |
for (Role role : roles) {
|
|
|
151 |
roleTypes[index++] = role.getType().toString();
|
|
|
152 |
}
|
|
|
153 |
String newToken = JWTUtil.create(user.getId(), roleTypes);
|
|
|
154 |
responseMap.put("newAuthToken", newToken);
|
|
|
155 |
}
|
|
|
156 |
|
| 21469 |
amit.gupta |
157 |
// if user is retailer
|
|
|
158 |
if (user.getRoles().stream().anyMatch(new Predicate<Role>() {
|
|
|
159 |
@Override
|
|
|
160 |
public boolean test(Role t) {
|
|
|
161 |
return t.getType().equals(RoleType.RETAILER);
|
|
|
162 |
}
|
|
|
163 |
})) {
|
| 21485 |
amit.gupta |
164 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
|
|
165 |
Retailer retailer = retailerRepository.selectById(uc.getUserId());
|
|
|
166 |
// if retailer is activated 1 then verified retailer
|
|
|
167 |
// else if migrated is 1 then old retailer
|
|
|
168 |
// else retailer is not verifed
|
|
|
169 |
if (retailer.isActive()) {
|
| 21469 |
amit.gupta |
170 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
|
| 21485 |
amit.gupta |
171 |
} else if (retailer.isMigrated()){
|
|
|
172 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.RETAILER.getValue());
|
| 21469 |
amit.gupta |
173 |
} else {
|
| 21485 |
amit.gupta |
174 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_VERIFIED_RETAILER.getValue());
|
| 21469 |
amit.gupta |
175 |
}
|
|
|
176 |
} else if (user.getRoles().stream().anyMatch(new Predicate<Role>() {
|
|
|
177 |
@Override
|
|
|
178 |
public boolean test(Role t) {
|
|
|
179 |
return t.getType().equals(RoleType.USER);
|
|
|
180 |
}
|
|
|
181 |
})) {
|
|
|
182 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.REGISTERED.getValue());
|
|
|
183 |
}
|
| 21491 |
amit.gupta |
184 |
} else {
|
|
|
185 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
|
|
|
186 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
| 21469 |
amit.gupta |
187 |
}
|
| 21526 |
amit.gupta |
188 |
|
| 21469 |
amit.gupta |
189 |
return responseSender.ok(responseMap);
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
@RequestMapping(value = ProfitMandiConstants.URL_USER, method = RequestMethod.POST)
|
| 21501 |
amit.gupta |
193 |
@ApiImplicitParams({
|
|
|
194 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
195 |
public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest) throws Throwable{
|
| 21469 |
amit.gupta |
196 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21368 |
kshitij.so |
197 |
User user = new User();
|
|
|
198 |
user.setFirstName(userRequest.getFirstName());
|
|
|
199 |
user.setLastName(userRequest.getLastName());
|
|
|
200 |
user.setCity(userRequest.getCity());
|
|
|
201 |
user.setPinCode(Integer.valueOf(userRequest.getPinCode()));
|
| 21708 |
amit.gupta |
202 |
user.setMobileNumber(userRequest.getMobieNumber());
|
| 21368 |
kshitij.so |
203 |
user.setEmailId(userRequest.getEmailId());
|
|
|
204 |
user.setUsername("");
|
|
|
205 |
user.setPassword("");
|
|
|
206 |
user.setMobile_verified(false);
|
|
|
207 |
user.setReferral_url("");
|
|
|
208 |
user.setGroup_id(1);
|
|
|
209 |
user.setStatus(0);
|
|
|
210 |
user.setActivated(false);
|
| 21501 |
amit.gupta |
211 |
user.setCreateTimestamp(LocalDateTime.now());
|
|
|
212 |
user.setUpdateTimestamp(LocalDateTime.now());
|
| 21503 |
ashik.ali |
213 |
try{
|
|
|
214 |
userRepository.persist(user);
|
| 21414 |
kshitij.so |
215 |
|
| 21503 |
ashik.ali |
216 |
UserRole userRole = new UserRole();
|
|
|
217 |
userRole.setRoleId(RoleType.USER.getValue());
|
|
|
218 |
userRole.setUserId(user.getId());
|
|
|
219 |
userRoleRepository.persist(userRole);
|
|
|
220 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1000"));
|
|
|
221 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
222 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
223 |
return responseSender.badRequest(profitMandiBusinessException);
|
|
|
224 |
}
|
| 21278 |
ashik.ali |
225 |
}
|
| 21469 |
amit.gupta |
226 |
|
|
|
227 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ALL, method = RequestMethod.GET)
|
| 21497 |
ashik.ali |
228 |
public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize) {
|
| 21469 |
amit.gupta |
229 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21497 |
ashik.ali |
230 |
return responseSender.ok(userRepository.selectAll(pageNumber, pageSize));
|
| 21248 |
ashik.ali |
231 |
}
|
| 21469 |
amit.gupta |
232 |
|
|
|
233 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ID, method = RequestMethod.GET)
|
|
|
234 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id) {
|
|
|
235 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21248 |
ashik.ali |
236 |
try {
|
| 21448 |
ashik.ali |
237 |
return responseSender.ok(userRepository.selectById(id));
|
| 21469 |
amit.gupta |
238 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
239 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
240 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21248 |
ashik.ali |
241 |
}
|
|
|
242 |
}
|
| 21469 |
amit.gupta |
243 |
|
|
|
244 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER, method = RequestMethod.GET)
|
|
|
245 |
public ResponseEntity<?> getByMobileNumber(HttpServletRequest request,
|
|
|
246 |
@RequestParam(name = "mobileNumber") String mobileNumber) {
|
|
|
247 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21248 |
ashik.ali |
248 |
try {
|
| 21448 |
ashik.ali |
249 |
return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
|
| 21469 |
amit.gupta |
250 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
251 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
252 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21248 |
ashik.ali |
253 |
}
|
|
|
254 |
}
|
| 21784 |
amit.gupta |
255 |
|
|
|
256 |
|
| 21469 |
amit.gupta |
257 |
|
| 21784 |
amit.gupta |
258 |
@ApiImplicitParams({
|
| 21501 |
amit.gupta |
259 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
260 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ACTIVATE, method = RequestMethod.POST)
|
|
|
261 |
public ResponseEntity<?> activateUser(HttpServletRequest request,
|
| 21784 |
amit.gupta |
262 |
@RequestParam(name = "activationCode") String activationCode) throws Throwable {
|
| 21511 |
ashik.ali |
263 |
int userId = (int)request.getAttribute("userId");
|
| 21784 |
amit.gupta |
264 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
265 |
return responseSender.ok(userService.updateActivation(userId, uc.getUserId(), activationCode));
|
|
|
266 |
}
|
| 21501 |
amit.gupta |
267 |
|
| 21426 |
ashik.ali |
268 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_IS_EXIST_MOBILE_NUMBER, method = RequestMethod.GET)
|
| 21469 |
amit.gupta |
269 |
public ResponseEntity<?> isMobileNumberExist(HttpServletRequest request,
|
|
|
270 |
@RequestParam(name = "mobileNumber") String mobileNumber) {
|
|
|
271 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21448 |
ashik.ali |
272 |
return responseSender.ok(userRepository.isExistByMobileNumber(mobileNumber));
|
| 21426 |
ashik.ali |
273 |
}
|
| 21469 |
amit.gupta |
274 |
|
|
|
275 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID, method = RequestMethod.GET)
|
|
|
276 |
public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId) {
|
|
|
277 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21248 |
ashik.ali |
278 |
try {
|
| 21448 |
ashik.ali |
279 |
return responseSender.ok(userRepository.selectByEmailId(emailId));
|
| 21469 |
amit.gupta |
280 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
281 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
282 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21248 |
ashik.ali |
283 |
}
|
|
|
284 |
}
|
| 21469 |
amit.gupta |
285 |
|
|
|
286 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ADD, method = RequestMethod.POST)
|
|
|
287 |
public ResponseEntity<?> addRole(HttpServletRequest request, @RequestBody UserAddRoleRequest userAddRoleRequest) {
|
|
|
288 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21248 |
ashik.ali |
289 |
try {
|
| 21426 |
ashik.ali |
290 |
User user = userRepository.selectById(userAddRoleRequest.getUserId());
|
| 21469 |
amit.gupta |
291 |
|
| 21426 |
ashik.ali |
292 |
Role role = null;
|
| 21469 |
amit.gupta |
293 |
try {
|
|
|
294 |
role = roleRepository.selectByNameAndType(userAddRoleRequest.getRole().getName(),
|
|
|
295 |
userAddRoleRequest.getRole().getType());
|
|
|
296 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 21426 |
ashik.ali |
297 |
role = new Role();
|
|
|
298 |
role.setName(userAddRoleRequest.getRole().getName());
|
|
|
299 |
role.setType(userAddRoleRequest.getRole().getType());
|
|
|
300 |
roleRepository.persist(role);
|
|
|
301 |
}
|
|
|
302 |
Permission permission = new Permission();
|
|
|
303 |
permission.setType(userAddRoleRequest.getRole().getPermissionType());
|
|
|
304 |
permission.setRoleId(role.getId());
|
|
|
305 |
permissionRepository.persist(permission);
|
|
|
306 |
UserRole userRole = new UserRole();
|
|
|
307 |
userRole.setRoleId(role.getId());
|
|
|
308 |
userRole.setUserId(user.getId());
|
|
|
309 |
userRoleRepository.persist(userRole);
|
| 21448 |
ashik.ali |
310 |
return responseSender.ok("");
|
| 21469 |
amit.gupta |
311 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
312 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
313 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21248 |
ashik.ali |
314 |
}
|
|
|
315 |
}
|
| 21469 |
amit.gupta |
316 |
|
|
|
317 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_REMOVE, method = RequestMethod.DELETE)
|
|
|
318 |
public ResponseEntity<?> removeRole(HttpServletRequest request, @RequestParam(name = "roleId") int roleId,
|
|
|
319 |
@RequestParam(name = "userId") int userId) {
|
|
|
320 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21248 |
ashik.ali |
321 |
try {
|
| 21426 |
ashik.ali |
322 |
roleRepository.selectById(roleId);
|
|
|
323 |
userRepository.selectById(userId);
|
|
|
324 |
userRoleRepository.deleteByUserAndRoleId(userId, roleId);
|
|
|
325 |
permissionRepository.deleteByRoleId(roleId);
|
| 21448 |
ashik.ali |
326 |
return responseSender.ok("");
|
| 21469 |
amit.gupta |
327 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
328 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
329 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21248 |
ashik.ali |
330 |
}
|
|
|
331 |
}
|
| 21469 |
amit.gupta |
332 |
|
|
|
333 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL, method = RequestMethod.GET)
|
|
|
334 |
public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id) {
|
|
|
335 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21448 |
ashik.ali |
336 |
return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
|
| 21248 |
ashik.ali |
337 |
}
|
| 21414 |
kshitij.so |
338 |
|
|
|
339 |
@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
|
| 21469 |
amit.gupta |
340 |
public ResponseEntity<?> getAdminToken(HttpServletRequest request,
|
|
|
341 |
@RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) {
|
|
|
342 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
343 |
if (!adminToken.equals(validAdminToken)) {
|
|
|
344 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
|
|
345 |
request.getRequestURL().toString(), HttpStatus.FORBIDDEN.toString(), HttpStatus.FORBIDDEN,
|
|
|
346 |
ResponseStatus.FAILURE, null);
|
| 21414 |
kshitij.so |
347 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.FORBIDDEN);
|
|
|
348 |
}
|
| 21469 |
amit.gupta |
349 |
|
| 21414 |
kshitij.so |
350 |
Map<String, Object> responseMap = new HashMap<>(2);
|
| 21469 |
amit.gupta |
351 |
try {
|
| 21414 |
kshitij.so |
352 |
User user = userRepository.selectByEmailId(emailId);
|
|
|
353 |
Set<Role> roles = user.getRoles();
|
|
|
354 |
String[] roleTypes = new String[roles.size()];
|
|
|
355 |
int index = 0;
|
| 21469 |
amit.gupta |
356 |
for (Role role : roles) {
|
| 21414 |
kshitij.so |
357 |
roleTypes[index++] = role.getType().toString();
|
|
|
358 |
}
|
|
|
359 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), roleTypes));
|
|
|
360 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
| 21469 |
amit.gupta |
361 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
362 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(emailId));
|
| 21414 |
kshitij.so |
363 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
|
|
364 |
}
|
| 21448 |
ashik.ali |
365 |
return responseSender.ok(responseMap);
|
| 21469 |
amit.gupta |
366 |
|
| 21414 |
kshitij.so |
367 |
}
|
| 21503 |
ashik.ali |
368 |
|
|
|
369 |
@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_MIGRATE, method = RequestMethod.GET)
|
|
|
370 |
public ResponseEntity<?> migrate(HttpServletRequest request) {
|
|
|
371 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
372 |
userToRetailerMigrationUtil.migrate();
|
|
|
373 |
return responseSender.ok(ResponseCodeHolder.getMessage("OK_1000"));
|
|
|
374 |
}
|
| 21248 |
ashik.ali |
375 |
}
|