Subversion Repositories SmartDukaan

Rev

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