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