| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import java.time.LocalDateTime;
|
3 |
import java.time.LocalDateTime;
|
| 4 |
import java.util.HashMap;
|
4 |
import java.util.HashMap;
|
| 5 |
import java.util.Map;
|
5 |
import java.util.Map;
|
| 6 |
import java.util.Set;
|
6 |
import java.util.Set;
|
| - |
|
7 |
import java.util.function.Predicate;
|
| 7 |
|
8 |
|
| 8 |
import javax.servlet.http.HttpServletRequest;
|
9 |
import javax.servlet.http.HttpServletRequest;
|
| 9 |
|
10 |
|
| 10 |
import org.slf4j.Logger;
|
11 |
import org.slf4j.Logger;
|
| 11 |
import org.slf4j.LoggerFactory;
|
12 |
import org.slf4j.LoggerFactory;
|
| Line 20... |
Line 21... |
| 20 |
import org.springframework.web.bind.annotation.RequestParam;
|
21 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21 |
|
22 |
|
| 22 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
23 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
| 23 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
24 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 24 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
25 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
26 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 25 |
import com.spice.profitmandi.common.util.JWTUtil;
|
27 |
import com.spice.profitmandi.common.util.JWTUtil;
|
| 26 |
import com.spice.profitmandi.dao.entity.Permission;
|
28 |
import com.spice.profitmandi.dao.entity.Permission;
|
| 27 |
import com.spice.profitmandi.dao.entity.Role;
|
29 |
import com.spice.profitmandi.dao.entity.Role;
|
| 28 |
import com.spice.profitmandi.dao.entity.User;
|
30 |
import com.spice.profitmandi.dao.entity.User;
|
| 29 |
import com.spice.profitmandi.dao.entity.UserRole;
|
31 |
import com.spice.profitmandi.dao.entity.UserRole;
|
| - |
|
32 |
import com.spice.profitmandi.dao.enumuration.RoleType;
|
| 30 |
import com.spice.profitmandi.dao.repository.PermissionRepository;
|
33 |
import com.spice.profitmandi.dao.repository.PermissionRepository;
|
| 31 |
import com.spice.profitmandi.dao.repository.RoleRepository;
|
34 |
import com.spice.profitmandi.dao.repository.RoleRepository;
|
| 32 |
import com.spice.profitmandi.dao.repository.UserRepository;
|
35 |
import com.spice.profitmandi.dao.repository.UserRepository;
|
| 33 |
import com.spice.profitmandi.dao.repository.UserRoleRepository;
|
36 |
import com.spice.profitmandi.dao.repository.UserRoleRepository;
|
| - |
|
37 |
import com.spice.profitmandi.web.enumuration.UserStatus;
|
| 34 |
import com.spice.profitmandi.web.model.ProfitMandiResponse;
|
38 |
import com.spice.profitmandi.web.model.ProfitMandiResponse;
|
| 35 |
import com.spice.profitmandi.web.model.Response;
|
- |
|
| 36 |
import com.spice.profitmandi.web.model.ResponseStatus;
|
39 |
import com.spice.profitmandi.web.model.ResponseStatus;
|
| 37 |
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
|
40 |
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
|
| 38 |
import com.spice.profitmandi.web.req.UserAddRoleRequest;
|
41 |
import com.spice.profitmandi.web.req.UserAddRoleRequest;
|
| 39 |
import com.spice.profitmandi.web.req.UserRequest;
|
42 |
import com.spice.profitmandi.web.req.UserRequest;
|
| 40 |
import com.spice.profitmandi.web.util.ResponseSender;
|
43 |
import com.spice.profitmandi.web.util.ResponseSender;
|
| 41 |
|
44 |
|
| - |
|
45 |
import io.swagger.annotations.ApiImplicitParam;
|
| - |
|
46 |
import io.swagger.annotations.ApiImplicitParams;
|
| - |
|
47 |
|
| 42 |
/**
|
48 |
/**
|
| 43 |
* @author ashikali
|
49 |
* @author ashikali
|
| 44 |
*
|
50 |
*
|
| 45 |
*/
|
51 |
*/
|
| 46 |
@Controller
|
52 |
@Controller
|
| 47 |
public class UserController {
|
53 |
public class UserController {
|
| 48 |
|
54 |
|
| 49 |
@Autowired
|
55 |
@Autowired
|
| 50 |
ResponseSender<?> responseSender;
|
56 |
ResponseSender<?> responseSender;
|
| 51 |
|
57 |
|
| 52 |
private static final Logger LOGGER=LoggerFactory.getLogger(UserController.class);
|
58 |
private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
|
| 53 |
|
59 |
|
| 54 |
@Value("${admin.token}")
|
60 |
@Value("${admin.token}")
|
| 55 |
private String validAdminToken;
|
61 |
private String validAdminToken;
|
| 56 |
|
62 |
|
| 57 |
@Autowired
|
63 |
@Autowired
|
| 58 |
UserRepository userRepository;
|
64 |
UserRepository userRepository;
|
| 59 |
|
65 |
|
| 60 |
@Autowired
|
66 |
@Autowired
|
| 61 |
RoleRepository roleRepository;
|
67 |
RoleRepository roleRepository;
|
| 62 |
|
68 |
|
| 63 |
@Autowired
|
69 |
@Autowired
|
| 64 |
UserRoleRepository userRoleRepository;
|
70 |
UserRoleRepository userRoleRepository;
|
| 65 |
|
71 |
|
| 66 |
@Autowired
|
72 |
@Autowired
|
| 67 |
PermissionRepository permissionRepository;
|
73 |
PermissionRepository permissionRepository;
|
| 68 |
|
74 |
|
| 69 |
@Autowired
|
75 |
@Autowired
|
| 70 |
GoogleLoginProcessor googleLoginProcessor;
|
76 |
GoogleLoginProcessor googleLoginProcessor;
|
| 71 |
|
77 |
|
| 72 |
@SuppressWarnings("unchecked")
|
78 |
@SuppressWarnings("unchecked")
|
| 73 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN,method=RequestMethod.POST)
|
79 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, method = RequestMethod.POST)
|
| 74 |
public ResponseEntity<?> googleLogin(HttpServletRequest request){
|
80 |
public ResponseEntity<?> googleLogin(HttpServletRequest request) {
|
| 75 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
81 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 76 |
final Map<String, Object> googleLoginMap = (Map<String, Object>)request.getAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
|
82 |
final Map<String, Object> googleLoginMap = (Map<String, Object>) request
|
| - |
|
83 |
.getAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
|
| 77 |
request.removeAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
|
84 |
request.removeAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
|
| 78 |
try {
|
85 |
try {
|
| 79 |
return responseSender.ok(googleLoginProcessor.process(googleLoginMap));
|
86 |
return responseSender.ok(googleLoginProcessor.process(googleLoginMap));
|
| 80 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
87 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 81 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
88 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 82 |
return responseSender.badRequest(profitMandiBusinessException);
|
89 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 83 |
}
|
90 |
}
|
| 84 |
}
|
91 |
}
|
| 85 |
|
92 |
|
| 86 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method=RequestMethod.GET)
|
93 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method = RequestMethod.GET)
|
| 87 |
public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token){
|
94 |
public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token) {
|
| 88 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
95 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 89 |
try {
|
96 |
try {
|
| 90 |
return responseSender.ok(JWTUtil.isExpired(token));
|
97 |
return responseSender.ok(JWTUtil.isExpired(token));
|
| 91 |
|
98 |
|
| 92 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
99 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 93 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
100 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 94 |
return responseSender.badRequest(profitMandiBusinessException);
|
101 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 95 |
}
|
102 |
}
|
| 96 |
}
|
103 |
}
|
| - |
|
104 |
|
| - |
|
105 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_INFO, method = RequestMethod.GET)
|
| - |
|
106 |
@ApiImplicitParams({
|
| - |
|
107 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| - |
|
108 |
public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
|
| - |
|
109 |
Map<String, Object> responseMap = new HashMap<>();
|
| - |
|
110 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| - |
|
111 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| - |
|
112 |
if (userInfo.getEmail() == null) {
|
| - |
|
113 |
User user = userRepository.selectById(userInfo.getUserId());
|
| - |
|
114 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
| - |
|
115 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
| - |
|
116 |
// if user is retailer
|
| - |
|
117 |
if (user.getRoles().stream().anyMatch(new Predicate<Role>() {
|
| - |
|
118 |
@Override
|
| - |
|
119 |
public boolean test(Role t) {
|
| - |
|
120 |
return t.getType().equals(RoleType.RETAILER);
|
| - |
|
121 |
}
|
| - |
|
122 |
})) {
|
| - |
|
123 |
// TODO: This should be from retailer Table
|
| - |
|
124 |
// if retailer is activated and migrated is 0 then verified
|
| - |
|
125 |
// retailer
|
| - |
|
126 |
// if retailer is not activated and and migrated is 0 then not
|
| - |
|
127 |
// verified retailer
|
| - |
|
128 |
// if retailer is activated and migrated is 1 then retailer is
|
| - |
|
129 |
// retailer.
|
| - |
|
130 |
if (user.isActivated()) {
|
| - |
|
131 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
|
| - |
|
132 |
} else {
|
| - |
|
133 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_VERIFIED_RETAILER.getValue());
|
| - |
|
134 |
}
|
| - |
|
135 |
} else if (user.getRoles().stream().anyMatch(new Predicate<Role>() {
|
| - |
|
136 |
@Override
|
| - |
|
137 |
public boolean test(Role t) {
|
| - |
|
138 |
return t.getType().equals(RoleType.USER);
|
| - |
|
139 |
}
|
| - |
|
140 |
})) {
|
| - |
|
141 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.REGISTERED.getValue());
|
| - |
|
142 |
}
|
| - |
|
143 |
} else {
|
| - |
|
144 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
|
| - |
|
145 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
| - |
|
146 |
}
|
| - |
|
147 |
|
| - |
|
148 |
return responseSender.ok(responseMap);
|
| - |
|
149 |
|
| 97 |
|
150 |
}
|
| 98 |
|
151 |
|
| 99 |
@RequestMapping(value = ProfitMandiConstants.URL_USER, method=RequestMethod.POST)
|
152 |
@RequestMapping(value = ProfitMandiConstants.URL_USER, method = RequestMethod.POST)
|
| 100 |
public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest){
|
153 |
public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest) {
|
| 101 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
154 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 102 |
User user = new User();
|
155 |
User user = new User();
|
| 103 |
user.setFirstName(userRequest.getFirstName());
|
156 |
user.setFirstName(userRequest.getFirstName());
|
| 104 |
user.setLastName(userRequest.getLastName());
|
157 |
user.setLastName(userRequest.getLastName());
|
| 105 |
user.setCity(userRequest.getCity());
|
158 |
user.setCity(userRequest.getCity());
|
| 106 |
user.setPinCode(Integer.valueOf(userRequest.getPinCode()));
|
159 |
user.setPinCode(Integer.valueOf(userRequest.getPinCode()));
|
| Line 116... |
Line 169... |
| 116 |
try {
|
169 |
try {
|
| 117 |
user.setCreateTimestamp(LocalDateTime.now());
|
170 |
user.setCreateTimestamp(LocalDateTime.now());
|
| 118 |
user.setUpdateTimestamp(LocalDateTime.now());
|
171 |
user.setUpdateTimestamp(LocalDateTime.now());
|
| 119 |
userRepository.persist(user);
|
172 |
userRepository.persist(user);
|
| 120 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1000"));
|
173 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1000"));
|
| 121 |
|
174 |
|
| 122 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
175 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 123 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
176 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 124 |
return responseSender.badRequest(profitMandiBusinessException);
|
177 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 125 |
}
|
178 |
}
|
| 126 |
}
|
179 |
}
|
| 127 |
|
180 |
|
| 128 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ALL,method=RequestMethod.GET)
|
181 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ALL, method = RequestMethod.GET)
|
| 129 |
public ResponseEntity<?> getAll(HttpServletRequest request){
|
182 |
public ResponseEntity<?> getAll(HttpServletRequest request) {
|
| 130 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
183 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 131 |
return responseSender.ok(userRepository.selectAll());
|
184 |
return responseSender.ok(userRepository.selectAll());
|
| 132 |
}
|
185 |
}
|
| 133 |
|
186 |
|
| 134 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ID,method=RequestMethod.GET)
|
187 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ID, method = RequestMethod.GET)
|
| 135 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
188 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id) {
|
| 136 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
189 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 137 |
try {
|
190 |
try {
|
| 138 |
return responseSender.ok(userRepository.selectById(id));
|
191 |
return responseSender.ok(userRepository.selectById(id));
|
| 139 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
192 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 140 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
193 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 141 |
return responseSender.badRequest(profitMandiBusinessException);
|
194 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 142 |
}
|
195 |
}
|
| 143 |
}
|
196 |
}
|
| 144 |
|
197 |
|
| 145 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER,method=RequestMethod.GET)
|
198 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER, method = RequestMethod.GET)
|
| 146 |
public ResponseEntity<?> getByMobileNumber(HttpServletRequest request, @RequestParam(name = "mobileNumber") String mobileNumber){
|
199 |
public ResponseEntity<?> getByMobileNumber(HttpServletRequest request,
|
| - |
|
200 |
@RequestParam(name = "mobileNumber") String mobileNumber) {
|
| 147 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
201 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 148 |
try {
|
202 |
try {
|
| 149 |
return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
|
203 |
return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
|
| 150 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
204 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 151 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
205 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 152 |
return responseSender.badRequest(profitMandiBusinessException);
|
206 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 153 |
}
|
207 |
}
|
| 154 |
}
|
208 |
}
|
| 155 |
|
209 |
|
| 156 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_IS_EXIST_MOBILE_NUMBER, method = RequestMethod.GET)
|
210 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_IS_EXIST_MOBILE_NUMBER, method = RequestMethod.GET)
|
| 157 |
public ResponseEntity<?> isMobileNumberExist(HttpServletRequest request, @RequestParam(name = "mobileNumber") String mobileNumber){
|
211 |
public ResponseEntity<?> isMobileNumberExist(HttpServletRequest request,
|
| - |
|
212 |
@RequestParam(name = "mobileNumber") String mobileNumber) {
|
| 158 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
213 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 159 |
return responseSender.ok(userRepository.isExistByMobileNumber(mobileNumber));
|
214 |
return responseSender.ok(userRepository.isExistByMobileNumber(mobileNumber));
|
| 160 |
}
|
215 |
}
|
| 161 |
|
- |
|
| 162 |
|
216 |
|
| 163 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID,method=RequestMethod.GET)
|
217 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID, method = RequestMethod.GET)
|
| 164 |
public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId){
|
218 |
public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId) {
|
| 165 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
219 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 166 |
try {
|
220 |
try {
|
| 167 |
return responseSender.ok(userRepository.selectByEmailId(emailId));
|
221 |
return responseSender.ok(userRepository.selectByEmailId(emailId));
|
| 168 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
222 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 169 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
223 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 170 |
return responseSender.badRequest(profitMandiBusinessException);
|
224 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 171 |
}
|
225 |
}
|
| 172 |
}
|
226 |
}
|
| 173 |
|
227 |
|
| 174 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ADD, method=RequestMethod.POST)
|
228 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ADD, method = RequestMethod.POST)
|
| 175 |
public ResponseEntity<?> addRole(HttpServletRequest request, @RequestBody UserAddRoleRequest userAddRoleRequest){
|
229 |
public ResponseEntity<?> addRole(HttpServletRequest request, @RequestBody UserAddRoleRequest userAddRoleRequest) {
|
| 176 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
230 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 177 |
try {
|
231 |
try {
|
| 178 |
User user = userRepository.selectById(userAddRoleRequest.getUserId());
|
232 |
User user = userRepository.selectById(userAddRoleRequest.getUserId());
|
| 179 |
|
233 |
|
| 180 |
Role role = null;
|
234 |
Role role = null;
|
| 181 |
try{
|
235 |
try {
|
| 182 |
role = roleRepository.selectByNameAndType(userAddRoleRequest.getRole().getName(), userAddRoleRequest.getRole().getType());
|
236 |
role = roleRepository.selectByNameAndType(userAddRoleRequest.getRole().getName(),
|
| - |
|
237 |
userAddRoleRequest.getRole().getType());
|
| 183 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
238 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 184 |
role = new Role();
|
239 |
role = new Role();
|
| 185 |
role.setName(userAddRoleRequest.getRole().getName());
|
240 |
role.setName(userAddRoleRequest.getRole().getName());
|
| 186 |
role.setType(userAddRoleRequest.getRole().getType());
|
241 |
role.setType(userAddRoleRequest.getRole().getType());
|
| 187 |
roleRepository.persist(role);
|
242 |
roleRepository.persist(role);
|
| 188 |
}
|
243 |
}
|
| Line 193... |
Line 248... |
| 193 |
UserRole userRole = new UserRole();
|
248 |
UserRole userRole = new UserRole();
|
| 194 |
userRole.setRoleId(role.getId());
|
249 |
userRole.setRoleId(role.getId());
|
| 195 |
userRole.setUserId(user.getId());
|
250 |
userRole.setUserId(user.getId());
|
| 196 |
userRoleRepository.persist(userRole);
|
251 |
userRoleRepository.persist(userRole);
|
| 197 |
return responseSender.ok("");
|
252 |
return responseSender.ok("");
|
| 198 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
253 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 199 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
254 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 200 |
return responseSender.badRequest(profitMandiBusinessException);
|
255 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 201 |
}
|
256 |
}
|
| 202 |
}
|
257 |
}
|
| 203 |
|
258 |
|
| 204 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_REMOVE,method=RequestMethod.DELETE)
|
259 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_REMOVE, method = RequestMethod.DELETE)
|
| 205 |
public ResponseEntity<?> removeRole(HttpServletRequest request, @RequestParam(name = "roleId") int roleId, @RequestParam(name = "userId") int userId){
|
260 |
public ResponseEntity<?> removeRole(HttpServletRequest request, @RequestParam(name = "roleId") int roleId,
|
| - |
|
261 |
@RequestParam(name = "userId") int userId) {
|
| 206 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
262 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 207 |
try {
|
263 |
try {
|
| 208 |
roleRepository.selectById(roleId);
|
264 |
roleRepository.selectById(roleId);
|
| 209 |
userRepository.selectById(userId);
|
265 |
userRepository.selectById(userId);
|
| 210 |
userRoleRepository.deleteByUserAndRoleId(userId, roleId);
|
266 |
userRoleRepository.deleteByUserAndRoleId(userId, roleId);
|
| 211 |
permissionRepository.deleteByRoleId(roleId);
|
267 |
permissionRepository.deleteByRoleId(roleId);
|
| 212 |
return responseSender.ok("");
|
268 |
return responseSender.ok("");
|
| 213 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
269 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 214 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
270 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 215 |
return responseSender.badRequest(profitMandiBusinessException);
|
271 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 216 |
}
|
272 |
}
|
| 217 |
}
|
273 |
}
|
| 218 |
|
- |
|
| 219 |
|
274 |
|
| 220 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL,method=RequestMethod.GET)
|
275 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL, method = RequestMethod.GET)
|
| 221 |
public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id){
|
276 |
public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id) {
|
| 222 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
277 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 223 |
return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
|
278 |
return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
|
| 224 |
}
|
279 |
}
|
| 225 |
|
280 |
|
| 226 |
@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
|
281 |
@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
|
| - |
|
282 |
public ResponseEntity<?> getAdminToken(HttpServletRequest request,
|
| 227 |
public ResponseEntity<?> getAdminToken(HttpServletRequest request, @RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId){
|
283 |
@RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) {
|
| 228 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
284 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 229 |
if (!adminToken.equals(validAdminToken)){
|
285 |
if (!adminToken.equals(validAdminToken)) {
|
| 230 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.FORBIDDEN.toString(), HttpStatus.FORBIDDEN, ResponseStatus.FAILURE, null);
|
286 |
final ProfitMandiResponse<?> profitMandiResponse = new ProfitMandiResponse<>(LocalDateTime.now(),
|
| - |
|
287 |
request.getRequestURL().toString(), HttpStatus.FORBIDDEN.toString(), HttpStatus.FORBIDDEN,
|
| - |
|
288 |
ResponseStatus.FAILURE, null);
|
| 231 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.FORBIDDEN);
|
289 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.FORBIDDEN);
|
| 232 |
}
|
290 |
}
|
| 233 |
|
- |
|
| 234 |
|
291 |
|
| 235 |
Map<String, Object> responseMap = new HashMap<>(2);
|
292 |
Map<String, Object> responseMap = new HashMap<>(2);
|
| 236 |
try{
|
293 |
try {
|
| 237 |
User user = userRepository.selectByEmailId(emailId);
|
294 |
User user = userRepository.selectByEmailId(emailId);
|
| 238 |
Set<Role> roles = user.getRoles();
|
295 |
Set<Role> roles = user.getRoles();
|
| 239 |
String[] roleTypes = new String[roles.size()];
|
296 |
String[] roleTypes = new String[roles.size()];
|
| 240 |
int index = 0;
|
297 |
int index = 0;
|
| 241 |
for(Role role : roles){
|
298 |
for (Role role : roles) {
|
| 242 |
roleTypes[index++] = role.getType().toString();
|
299 |
roleTypes[index++] = role.getType().toString();
|
| 243 |
}
|
300 |
}
|
| 244 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), roleTypes));
|
301 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), roleTypes));
|
| 245 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
302 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
| 246 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
303 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 247 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create());
|
304 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(emailId));
|
| 248 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
305 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
| 249 |
}
|
306 |
}
|
| 250 |
return responseSender.ok(responseMap);
|
307 |
return responseSender.ok(responseMap);
|
| 251 |
|
308 |
|
| 252 |
}
|
309 |
}
|
| 253 |
}
|
310 |
}
|