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