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