Subversion Repositories SmartDukaan

Rev

Rev 21368 | Rev 21414 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21248 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
3
import java.time.LocalDateTime;
21277 ashik.ali 4
import java.util.Map;
21248 ashik.ali 5
 
6
import javax.servlet.http.HttpServletRequest;
7
 
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
21278 ashik.ali 10
import org.springframework.beans.factory.annotation.Autowired;
21248 ashik.ali 11
import org.springframework.http.HttpStatus;
12
import org.springframework.http.ResponseEntity;
13
import org.springframework.stereotype.Controller;
21366 kshitij.so 14
import org.springframework.web.bind.annotation.RequestBody;
21248 ashik.ali 15
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestMethod;
17
import org.springframework.web.bind.annotation.RequestParam;
18
 
19
import com.spice.profitmandi.common.ResponseCodeHolder;
20
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
21
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21282 ashik.ali 22
import com.spice.profitmandi.common.util.JWTUtil;
21278 ashik.ali 23
import com.spice.profitmandi.dao.entity.User;
21248 ashik.ali 24
import com.spice.profitmandi.dao.repository.UserRepository;
25
import com.spice.profitmandi.web.model.ProfitMandiResponse;
26
import com.spice.profitmandi.web.model.Response;
27
import com.spice.profitmandi.web.model.ResponseStatus;
21277 ashik.ali 28
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
21366 kshitij.so 29
import com.spice.profitmandi.web.req.UserRequest;
21248 ashik.ali 30
 
31
/**
32
 * @author ashikali
33
 *
34
 */
35
@Controller
36
public class UserController {
37
 
38
	private static final Logger LOGGER=LoggerFactory.getLogger(UserController.class);
39
 
21278 ashik.ali 40
	@Autowired
41
	UserRepository userRepository;
21248 ashik.ali 42
 
21278 ashik.ali 43
	@Autowired
44
	GoogleLoginProcessor googleLoginProcessor;
45
 
21277 ashik.ali 46
	@SuppressWarnings("unchecked")
47
	@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN,method=RequestMethod.POST)
48
	public ResponseEntity<?> googleLogin(HttpServletRequest request){
49
		LOGGER.info("requested url : "+request.getRequestURL().toString());
50
		final Map<String, Object> googleLoginMap = (Map<String, Object>)request.getAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
51
		request.removeAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
52
		try {
53
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, googleLoginProcessor.process(googleLoginMap));
54
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
55
		}catch (ProfitMandiBusinessException pmbe) {
56
			LOGGER.error("ProfitMandi error: ", pmbe);
57
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
58
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
59
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
60
		}catch (Exception e) {
61
			LOGGER.error("Internal Server Error : ",e);
62
			final Response response=new Response("","","", e.getMessage());
63
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
64
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
65
		}
66
	}
67
 
21282 ashik.ali 68
	@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method=RequestMethod.GET)
69
	public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token){
70
		LOGGER.info("requested url : "+request.getRequestURL().toString());
71
		try {
72
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, JWTUtil.isExpired(token));
73
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
74
		}catch (ProfitMandiBusinessException pmbe) {
75
			LOGGER.error("ProfitMandi error: ", pmbe);
76
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
77
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
78
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
79
		}catch (Exception e) {
80
			LOGGER.error("Internal Server Error: ", e);
81
			final Response response=new Response("","","", e.getMessage());
82
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
83
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
84
		}
85
	}
86
 
21278 ashik.ali 87
	@RequestMapping(value = ProfitMandiConstants.URL_USER, method=RequestMethod.POST)
21366 kshitij.so 88
	public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest){
21278 ashik.ali 89
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21368 kshitij.so 90
		User user = new User();
91
		user.setFirstName(userRequest.getFirstName());
92
		user.setLastName(userRequest.getLastName());
93
		user.setCity(userRequest.getCity());
94
		user.setPinCode(Integer.valueOf(userRequest.getPinCode()));
95
		user.setEmailId(userRequest.getEmailId());
96
		user.setUsername("");
97
		user.setPassword("");
98
		user.setMobile_verified(false);
99
		user.setReferral_url("");
100
		user.setGroup_id(1);
101
		user.setStatus(0);
102
		user.setActivated(false);
103
 
21278 ashik.ali 104
		try {
105
			user.setCreateTimestamp(LocalDateTime.now());
106
			user.setUpdateTimestamp(LocalDateTime.now());
107
			userRepository.persist(user);
21282 ashik.ali 108
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("USR_OK_1000"));
21278 ashik.ali 109
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
110
		}catch (ProfitMandiBusinessException pmbe) {
111
			LOGGER.error("ProfitMandi error: ", pmbe);
112
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
113
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
114
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
115
		}catch (Exception e) {
116
			LOGGER.error("Internal Server Error : ",e);
117
			final Response response=new Response("","","", e.getMessage());
118
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
119
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
120
		}
121
	}
122
 
21248 ashik.ali 123
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ALL,method=RequestMethod.GET)
124
	public ResponseEntity<?> getAll(HttpServletRequest request){
125
		LOGGER.info("requested url : "+request.getRequestURL().toString());
126
		try {
127
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectAll());
128
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
129
		}catch (Exception e) {
130
			LOGGER.error("Internal Server Error : ",e);
131
			final Response response=new Response("","","", e.getMessage());
132
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
133
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
134
		}
135
	}
136
 
137
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ID,method=RequestMethod.GET)
21404 kshitij.so 138
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
21248 ashik.ali 139
		LOGGER.info("requested url : "+request.getRequestURL().toString());
140
		try {
141
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectById(id));
142
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
143
		}catch (ProfitMandiBusinessException pmbe) {
144
			LOGGER.error("ProfitMandi error: ", pmbe);
145
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
146
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
147
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
148
		}catch (Exception e) {
149
			LOGGER.error("Internal Server Error: ", e);
150
			final Response response=new Response("","","", e.getMessage());
151
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
152
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
153
		}
154
	}
155
 
156
	@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER,method=RequestMethod.GET)
157
	public ResponseEntity<?> getByMobileNumber(HttpServletRequest request, @RequestParam(name = "mobileNumber") String mobileNumber){
158
		LOGGER.info("requested url : "+request.getRequestURL().toString());
159
		try {
160
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectByMobileNumber(mobileNumber));
161
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
162
		}catch (ProfitMandiBusinessException pmbe) {
163
			LOGGER.error("ProfitMandi error: ", pmbe);
164
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
165
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
166
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
167
		}catch (Exception e) {
168
			LOGGER.error("Internal Server Error: ", e);
169
			final Response response=new Response("","","", e.getMessage());
170
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
171
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
172
		}
173
	}
174
 
175
 
176
	@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID,method=RequestMethod.GET)
177
	public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId){
178
		LOGGER.info("requested url : "+request.getRequestURL().toString());
179
		try {
180
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectByEmailId(emailId));
181
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
182
		}catch (ProfitMandiBusinessException pmbe) {
183
			LOGGER.error("ProfitMandi error: ", pmbe);
184
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
185
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
186
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
187
		}catch (Exception e) {
188
			LOGGER.error("Internal Server Error: ", e);
189
			final Response response=new Response("","","", e.getMessage());
190
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
191
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
192
		}
193
	}
194
 
195
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_ID, method = RequestMethod.PUT)
21404 kshitij.so 196
	public ResponseEntity<?> addRoleByIdWithId(HttpServletRequest request, @RequestParam(name = "roleId") int roleId, @RequestParam(name = "userId") int userId){
21248 ashik.ali 197
		LOGGER.info("requested url : "+request.getRequestURL().toString());
198
		try {
199
			userRepository.addRoleByIdWithId(roleId, userId);
200
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
201
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
202
		}catch (ProfitMandiBusinessException pmbe) {
203
			LOGGER.error("ProfitMandi error: ", pmbe);
204
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
205
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
206
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
207
		}catch (Exception e) {
208
			LOGGER.error("Internal Server Error : ",e);
209
			final Response response=new Response("","","", e.getMessage());
210
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
211
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
212
		}
213
	}
214
 
215
 
216
 
217
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_MOBILE_NUMBER, method = RequestMethod.PUT)
21404 kshitij.so 218
	public ResponseEntity<?> addRoleByIdWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleId") int id, @RequestParam(name = "mobileNumber") String mobileNumber){
21248 ashik.ali 219
		LOGGER.info("requested url : "+request.getRequestURL().toString());
220
		try {
221
			userRepository.addRoleByIdWithMobileNumber(id, mobileNumber);
222
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
223
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
224
		}catch (ProfitMandiBusinessException pmbe) {
225
			LOGGER.error("ProfitMandi error: ", pmbe);
226
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
227
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
228
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
229
		}catch (Exception e) {
230
			LOGGER.error("Internal Server Error : ",e);
231
			final Response response=new Response("","","", e.getMessage());
232
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
233
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
234
		}
235
	}
236
 
237
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_EMAIL_ID, method = RequestMethod.PUT)
21404 kshitij.so 238
	public ResponseEntity<?> addRoleByIdWithEmailId(HttpServletRequest request, @RequestParam(name = "roleId") int id, @RequestParam(name = "emailId") String emailId){
21248 ashik.ali 239
		LOGGER.info("requested url : "+request.getRequestURL().toString());
240
		try {
241
			userRepository.addRoleByIdWithEmailId(id, emailId);
242
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
243
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
244
		}catch (ProfitMandiBusinessException pmbe) {
245
			LOGGER.error("ProfitMandi error: ", pmbe);
246
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
247
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
248
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
249
		}catch (Exception e) {
250
			LOGGER.error("Internal Server Error : ",e);
251
			final Response response=new Response("","","", e.getMessage());
252
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
253
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
254
		}
255
	}
256
 
257
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_ID, method = RequestMethod.PUT)
21404 kshitij.so 258
	public ResponseEntity<?> addRoleByNameWithId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "userId") int id){
21248 ashik.ali 259
		LOGGER.info("requested url : "+request.getRequestURL().toString());
260
		try {
261
			userRepository.addRoleByNameWithId(roleName, id);
262
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
263
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
264
		}catch (ProfitMandiBusinessException pmbe) {
265
			LOGGER.error("ProfitMandi error: ", pmbe);
266
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
267
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
268
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
269
		}catch (Exception e) {
270
			LOGGER.error("Internal Server Error : ",e);
271
			final Response response=new Response("","","", e.getMessage());
272
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
273
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
274
		}
275
	}
276
 
277
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_MOBILE_NUMBER, method = RequestMethod.PUT)
278
	public ResponseEntity<?> addRoleByNameWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "mobileNumber") String mobileNumber){
279
		LOGGER.info("requested url : "+request.getRequestURL().toString());
280
		try {
281
			userRepository.addRoleByNameWithMobileNumber(roleName, mobileNumber);
282
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
283
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
284
		}catch (ProfitMandiBusinessException pmbe) {
285
			LOGGER.error("ProfitMandi error: ", pmbe);
286
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
287
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
288
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
289
		}catch (Exception e) {
290
			LOGGER.error("Internal Server Error : ",e);
291
			final Response response=new Response("","","", e.getMessage());
292
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
293
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
294
		}
295
	}
296
 
297
 
298
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_EMAIL_ID, method = RequestMethod.PUT)
299
	public ResponseEntity<?> addRoleByNameWithEmailId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "emailId") String emailId){
300
		LOGGER.info("requested url : "+request.getRequestURL().toString());
301
		try {
302
			userRepository.addRoleByNameWithEmailId(roleName, emailId);
303
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
304
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
305
		}catch (ProfitMandiBusinessException pmbe) {
306
			LOGGER.error("ProfitMandi error: ", pmbe);
307
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
308
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
309
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
310
		}catch (Exception e) {
311
			LOGGER.error("Internal Server Error : ",e);
312
			final Response response=new Response("","","", e.getMessage());
313
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
314
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
315
		}
316
	}
317
 
318
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_ID, method = RequestMethod.DELETE)
21404 kshitij.so 319
	public ResponseEntity<?> removeRoleByIdWithId(HttpServletRequest request, @RequestParam(name = "roleId") int roleId, @RequestParam(name = "userId") int userId){
21248 ashik.ali 320
		LOGGER.info("requested url : "+request.getRequestURL().toString());
321
		try {
322
			userRepository.deleteRoleByIdWithId(roleId, userId);
323
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
324
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
325
		}catch (ProfitMandiBusinessException pmbe) {
326
			LOGGER.error("ProfitMandi error: ", pmbe);
327
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
328
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
329
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
330
		}catch (Exception e) {
331
			LOGGER.error("Internal Server Error : ",e);
332
			final Response response=new Response("","","", e.getMessage());
333
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
334
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
335
		}
336
	}
337
 
338
 
339
 
340
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_MOBILE_NUMBER, method = RequestMethod.DELETE)
21404 kshitij.so 341
	public ResponseEntity<?> removeRoleByIdWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleId") int id, @RequestParam(name = "mobileNumber") String mobileNumber){
21248 ashik.ali 342
		LOGGER.info("requested url : "+request.getRequestURL().toString());
343
		try {
344
			userRepository.deleteRoleByIdWithMobileNumber(id, mobileNumber);
345
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
346
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
347
		}catch (ProfitMandiBusinessException pmbe) {
348
			LOGGER.error("ProfitMandi error: ", pmbe);
349
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
350
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
351
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
352
		}catch (Exception e) {
353
			LOGGER.error("Internal Server Error : ",e);
354
			final Response response=new Response("","","", e.getMessage());
355
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
356
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
357
		}
358
	}
359
 
360
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_EMAIL_ID, method = RequestMethod.DELETE)
21404 kshitij.so 361
	public ResponseEntity<?> removeRoleByIdWithEmailId(HttpServletRequest request, @RequestParam(name = "roleId") int id, @RequestParam(name = "emailId") String emailId){
21248 ashik.ali 362
		LOGGER.info("requested url : "+request.getRequestURL().toString());
363
		try {
364
			userRepository.deleteRoleByIdWithEmailId(id, emailId);
365
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
366
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
367
		}catch (ProfitMandiBusinessException pmbe) {
368
			LOGGER.error("ProfitMandi error: ", pmbe);
369
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
370
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
371
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
372
		}catch (Exception e) {
373
			LOGGER.error("Internal Server Error : ",e);
374
			final Response response=new Response("","","", e.getMessage());
375
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
376
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
377
		}
378
	}
379
 
380
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_ID, method = RequestMethod.DELETE)
21404 kshitij.so 381
	public ResponseEntity<?> removeRoleByNameWithId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "userId") int id){
21248 ashik.ali 382
		LOGGER.info("requested url : "+request.getRequestURL().toString());
383
		try {
384
			userRepository.deleteRoleByNameWithId(roleName, id);
385
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
386
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
387
		}catch (ProfitMandiBusinessException pmbe) {
388
			LOGGER.error("ProfitMandi error: ", pmbe);
389
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
390
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
391
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
392
		}catch (Exception e) {
393
			LOGGER.error("Internal Server Error : ",e);
394
			final Response response=new Response("","","", e.getMessage());
395
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
396
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
397
		}
398
	}
399
 
400
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_MOBILE_NUMBER, method = RequestMethod.DELETE)
401
	public ResponseEntity<?> removeRoleByNameWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "mobileNumber") String mobileNumber){
402
		LOGGER.info("requested url : "+request.getRequestURL().toString());
403
		try {
404
			userRepository.deleteRoleByNameWithMobileNumber(roleName, mobileNumber);
405
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
406
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
407
		}catch (ProfitMandiBusinessException pmbe) {
408
			LOGGER.error("ProfitMandi error: ", pmbe);
409
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
410
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
411
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
412
		}catch (Exception e) {
413
			LOGGER.error("Internal Server Error : ",e);
414
			final Response response=new Response("","","", e.getMessage());
415
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
416
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
417
		}
418
	}
419
 
420
 
421
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_EMAIL_ID, method = RequestMethod.DELETE)
422
	public ResponseEntity<?> removeRoleByNameWithEmailId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "emailId") String emailId){
423
		LOGGER.info("requested url : "+request.getRequestURL().toString());
424
		try {
425
			userRepository.deleteRoleByNameWithEmailId(roleName, emailId);
426
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
427
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
428
		}catch (ProfitMandiBusinessException pmbe) {
429
			LOGGER.error("ProfitMandi error: ", pmbe);
430
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
431
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
432
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
433
		}catch (Exception e) {
434
			LOGGER.error("Internal Server Error : ",e);
435
			final Response response=new Response("","","", e.getMessage());
436
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
437
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
438
		}
439
	}
440
}