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