Subversion Repositories SmartDukaan

Rev

Rev 21366 | Rev 21404 | 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
 
87
	@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_DETAIL, method=RequestMethod.GET)
88
	public ResponseEntity<?> tokenDetail(HttpServletRequest request, @RequestParam(name = "token") String token){
89
		LOGGER.info("requested url : "+request.getRequestURL().toString());
90
		try {
91
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectById(JWTUtil.getUserId(token)));
92
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
93
		}catch (ProfitMandiBusinessException pmbe) {
94
			LOGGER.error("ProfitMandi error: ", pmbe);
95
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
96
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
97
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
98
		}catch (Exception e) {
99
			LOGGER.error("Internal Server Error: ", e);
100
			final Response response=new Response("","","", e.getMessage());
101
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
102
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
103
		}
104
	}
105
 
21278 ashik.ali 106
	@RequestMapping(value = ProfitMandiConstants.URL_USER, method=RequestMethod.POST)
21366 kshitij.so 107
	public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest){
21278 ashik.ali 108
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21368 kshitij.so 109
		User user = new User();
110
		user.setFirstName(userRequest.getFirstName());
111
		user.setLastName(userRequest.getLastName());
112
		user.setCity(userRequest.getCity());
113
		user.setPinCode(Integer.valueOf(userRequest.getPinCode()));
114
		user.setEmailId(userRequest.getEmailId());
115
		user.setUsername("");
116
		user.setPassword("");
117
		user.setMobile_verified(false);
118
		user.setReferral_url("");
119
		user.setGroup_id(1);
120
		user.setStatus(0);
121
		user.setActivated(false);
122
 
21278 ashik.ali 123
		try {
124
			user.setCreateTimestamp(LocalDateTime.now());
125
			user.setUpdateTimestamp(LocalDateTime.now());
126
			userRepository.persist(user);
21282 ashik.ali 127
			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 128
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
129
		}catch (ProfitMandiBusinessException pmbe) {
130
			LOGGER.error("ProfitMandi error: ", pmbe);
131
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
132
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
133
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
134
		}catch (Exception e) {
135
			LOGGER.error("Internal Server Error : ",e);
136
			final Response response=new Response("","","", e.getMessage());
137
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
138
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
139
		}
140
	}
141
 
21248 ashik.ali 142
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ALL,method=RequestMethod.GET)
143
	public ResponseEntity<?> getAll(HttpServletRequest request){
144
		LOGGER.info("requested url : "+request.getRequestURL().toString());
145
		try {
146
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectAll());
147
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
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_ID,method=RequestMethod.GET)
157
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") long id){
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.selectById(id));
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
	@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER,method=RequestMethod.GET)
176
	public ResponseEntity<?> getByMobileNumber(HttpServletRequest request, @RequestParam(name = "mobileNumber") String mobileNumber){
177
		LOGGER.info("requested url : "+request.getRequestURL().toString());
178
		try {
179
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectByMobileNumber(mobileNumber));
180
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
181
		}catch (ProfitMandiBusinessException pmbe) {
182
			LOGGER.error("ProfitMandi error: ", pmbe);
183
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
184
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
185
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
186
		}catch (Exception e) {
187
			LOGGER.error("Internal Server Error: ", e);
188
			final Response response=new Response("","","", e.getMessage());
189
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
190
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
191
		}
192
	}
193
 
194
 
195
	@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID,method=RequestMethod.GET)
196
	public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId){
197
		LOGGER.info("requested url : "+request.getRequestURL().toString());
198
		try {
199
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectByEmailId(emailId));
200
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
201
		}catch (ProfitMandiBusinessException pmbe) {
202
			LOGGER.error("ProfitMandi error: ", pmbe);
203
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
204
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
205
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
206
		}catch (Exception e) {
207
			LOGGER.error("Internal Server Error: ", e);
208
			final Response response=new Response("","","", e.getMessage());
209
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
210
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
211
		}
212
	}
213
 
214
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_ID, method = RequestMethod.PUT)
215
	public ResponseEntity<?> addRoleByIdWithId(HttpServletRequest request, @RequestParam(name = "roleId") long roleId, @RequestParam(name = "userId") long userId){
216
		LOGGER.info("requested url : "+request.getRequestURL().toString());
217
		try {
218
			userRepository.addRoleByIdWithId(roleId, userId);
219
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
220
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
221
		}catch (ProfitMandiBusinessException pmbe) {
222
			LOGGER.error("ProfitMandi error: ", pmbe);
223
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
224
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
225
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
226
		}catch (Exception e) {
227
			LOGGER.error("Internal Server Error : ",e);
228
			final Response response=new Response("","","", e.getMessage());
229
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
230
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
231
		}
232
	}
233
 
234
 
235
 
236
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_MOBILE_NUMBER, method = RequestMethod.PUT)
237
	public ResponseEntity<?> addRoleByIdWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "mobileNumber") String mobileNumber){
238
		LOGGER.info("requested url : "+request.getRequestURL().toString());
239
		try {
240
			userRepository.addRoleByIdWithMobileNumber(id, mobileNumber);
241
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
242
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
243
		}catch (ProfitMandiBusinessException pmbe) {
244
			LOGGER.error("ProfitMandi error: ", pmbe);
245
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
246
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
247
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
248
		}catch (Exception e) {
249
			LOGGER.error("Internal Server Error : ",e);
250
			final Response response=new Response("","","", e.getMessage());
251
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
252
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
253
		}
254
	}
255
 
256
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_EMAIL_ID, method = RequestMethod.PUT)
257
	public ResponseEntity<?> addRoleByIdWithEmailId(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "emailId") String emailId){
258
		LOGGER.info("requested url : "+request.getRequestURL().toString());
259
		try {
260
			userRepository.addRoleByIdWithEmailId(id, emailId);
261
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
262
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
263
		}catch (ProfitMandiBusinessException pmbe) {
264
			LOGGER.error("ProfitMandi error: ", pmbe);
265
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
266
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
267
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
268
		}catch (Exception e) {
269
			LOGGER.error("Internal Server Error : ",e);
270
			final Response response=new Response("","","", e.getMessage());
271
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
272
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
273
		}
274
	}
275
 
276
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_ID, method = RequestMethod.PUT)
277
	public ResponseEntity<?> addRoleByNameWithId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "userId") long id){
278
		LOGGER.info("requested url : "+request.getRequestURL().toString());
279
		try {
280
			userRepository.addRoleByNameWithId(roleName, id);
281
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
282
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
283
		}catch (ProfitMandiBusinessException pmbe) {
284
			LOGGER.error("ProfitMandi error: ", pmbe);
285
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
286
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
287
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
288
		}catch (Exception e) {
289
			LOGGER.error("Internal Server Error : ",e);
290
			final Response response=new Response("","","", e.getMessage());
291
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
292
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
293
		}
294
	}
295
 
296
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_MOBILE_NUMBER, method = RequestMethod.PUT)
297
	public ResponseEntity<?> addRoleByNameWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "mobileNumber") String mobileNumber){
298
		LOGGER.info("requested url : "+request.getRequestURL().toString());
299
		try {
300
			userRepository.addRoleByNameWithMobileNumber(roleName, mobileNumber);
301
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
302
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
303
		}catch (ProfitMandiBusinessException pmbe) {
304
			LOGGER.error("ProfitMandi error: ", pmbe);
305
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
306
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
307
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
308
		}catch (Exception e) {
309
			LOGGER.error("Internal Server Error : ",e);
310
			final Response response=new Response("","","", e.getMessage());
311
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
312
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
313
		}
314
	}
315
 
316
 
317
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_EMAIL_ID, method = RequestMethod.PUT)
318
	public ResponseEntity<?> addRoleByNameWithEmailId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "emailId") String emailId){
319
		LOGGER.info("requested url : "+request.getRequestURL().toString());
320
		try {
321
			userRepository.addRoleByNameWithEmailId(roleName, emailId);
322
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
323
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
324
		}catch (ProfitMandiBusinessException pmbe) {
325
			LOGGER.error("ProfitMandi error: ", pmbe);
326
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
327
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
328
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
329
		}catch (Exception e) {
330
			LOGGER.error("Internal Server Error : ",e);
331
			final Response response=new Response("","","", e.getMessage());
332
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
333
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
334
		}
335
	}
336
 
337
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_ID, method = RequestMethod.DELETE)
338
	public ResponseEntity<?> removeRoleByIdWithId(HttpServletRequest request, @RequestParam(name = "roleId") long roleId, @RequestParam(name = "userId") long userId){
339
		LOGGER.info("requested url : "+request.getRequestURL().toString());
340
		try {
341
			userRepository.deleteRoleByIdWithId(roleId, userId);
342
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
343
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
344
		}catch (ProfitMandiBusinessException pmbe) {
345
			LOGGER.error("ProfitMandi error: ", pmbe);
346
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
347
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
348
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
349
		}catch (Exception e) {
350
			LOGGER.error("Internal Server Error : ",e);
351
			final Response response=new Response("","","", e.getMessage());
352
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
353
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
354
		}
355
	}
356
 
357
 
358
 
359
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_MOBILE_NUMBER, method = RequestMethod.DELETE)
360
	public ResponseEntity<?> removeRoleByIdWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "mobileNumber") String mobileNumber){
361
		LOGGER.info("requested url : "+request.getRequestURL().toString());
362
		try {
363
			userRepository.deleteRoleByIdWithMobileNumber(id, mobileNumber);
364
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
365
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
366
		}catch (ProfitMandiBusinessException pmbe) {
367
			LOGGER.error("ProfitMandi error: ", pmbe);
368
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
369
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
370
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
371
		}catch (Exception e) {
372
			LOGGER.error("Internal Server Error : ",e);
373
			final Response response=new Response("","","", e.getMessage());
374
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
375
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
376
		}
377
	}
378
 
379
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_EMAIL_ID, method = RequestMethod.DELETE)
380
	public ResponseEntity<?> removeRoleByIdWithEmailId(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "emailId") String emailId){
381
		LOGGER.info("requested url : "+request.getRequestURL().toString());
382
		try {
383
			userRepository.deleteRoleByIdWithEmailId(id, emailId);
384
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
385
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
386
		}catch (ProfitMandiBusinessException pmbe) {
387
			LOGGER.error("ProfitMandi error: ", pmbe);
388
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
389
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
390
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
391
		}catch (Exception e) {
392
			LOGGER.error("Internal Server Error : ",e);
393
			final Response response=new Response("","","", e.getMessage());
394
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
395
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
396
		}
397
	}
398
 
399
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_ID, method = RequestMethod.DELETE)
400
	public ResponseEntity<?> removeRoleByNameWithId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "userId") long id){
401
		LOGGER.info("requested url : "+request.getRequestURL().toString());
402
		try {
403
			userRepository.deleteRoleByNameWithId(roleName, id);
404
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
405
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
406
		}catch (ProfitMandiBusinessException pmbe) {
407
			LOGGER.error("ProfitMandi error: ", pmbe);
408
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
409
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
410
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
411
		}catch (Exception e) {
412
			LOGGER.error("Internal Server Error : ",e);
413
			final Response response=new Response("","","", e.getMessage());
414
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
415
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
416
		}
417
	}
418
 
419
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_MOBILE_NUMBER, method = RequestMethod.DELETE)
420
	public ResponseEntity<?> removeRoleByNameWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "mobileNumber") String mobileNumber){
421
		LOGGER.info("requested url : "+request.getRequestURL().toString());
422
		try {
423
			userRepository.deleteRoleByNameWithMobileNumber(roleName, mobileNumber);
424
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
425
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
426
		}catch (ProfitMandiBusinessException pmbe) {
427
			LOGGER.error("ProfitMandi error: ", pmbe);
428
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
429
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
430
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
431
		}catch (Exception e) {
432
			LOGGER.error("Internal Server Error : ",e);
433
			final Response response=new Response("","","", e.getMessage());
434
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
435
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
436
		}
437
	}
438
 
439
 
440
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_EMAIL_ID, method = RequestMethod.DELETE)
441
	public ResponseEntity<?> removeRoleByNameWithEmailId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "emailId") String emailId){
442
		LOGGER.info("requested url : "+request.getRequestURL().toString());
443
		try {
444
			userRepository.deleteRoleByNameWithEmailId(roleName, emailId);
445
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
446
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
447
		}catch (ProfitMandiBusinessException pmbe) {
448
			LOGGER.error("ProfitMandi error: ", pmbe);
449
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
450
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
451
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
452
		}catch (Exception e) {
453
			LOGGER.error("Internal Server Error : ",e);
454
			final Response response=new Response("","","", e.getMessage());
455
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
456
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
457
		}
458
	}
459
}