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