Subversion Repositories SmartDukaan

Rev

Rev 21277 | Go to most recent revision | Details | 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;
4
 
5
import javax.servlet.http.HttpServletRequest;
6
 
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9
import org.springframework.http.HttpStatus;
10
import org.springframework.http.ResponseEntity;
11
import org.springframework.stereotype.Controller;
12
import org.springframework.web.bind.annotation.RequestMapping;
13
import org.springframework.web.bind.annotation.RequestMethod;
14
import org.springframework.web.bind.annotation.RequestParam;
15
 
16
import com.spice.profitmandi.common.ResponseCodeHolder;
17
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
18
import com.spice.profitmandi.common.model.ProfitMandiConstants;
19
import com.spice.profitmandi.dao.repository.UserRepository;
20
import com.spice.profitmandi.dao.repository.UserRepositoryImpl;
21
import com.spice.profitmandi.web.model.ProfitMandiResponse;
22
import com.spice.profitmandi.web.model.Response;
23
import com.spice.profitmandi.web.model.ResponseStatus;
24
 
25
/**
26
 * @author ashikali
27
 *
28
 */
29
@Controller
30
public class UserController {
31
 
32
	private static final Logger LOGGER=LoggerFactory.getLogger(UserController.class);
33
 
34
	private UserRepository userRepository = UserRepositoryImpl.getInstance();
35
 
36
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ALL,method=RequestMethod.GET)
37
	public ResponseEntity<?> getAll(HttpServletRequest request){
38
		LOGGER.info("requested url : "+request.getRequestURL().toString());
39
		try {
40
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectAll());
41
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
42
		}catch (Exception e) {
43
			LOGGER.error("Internal Server Error : ",e);
44
			final Response response=new Response("","","", e.getMessage());
45
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
46
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
47
		}
48
	}
49
 
50
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ID,method=RequestMethod.GET)
51
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") long id){
52
		LOGGER.info("requested url : "+request.getRequestURL().toString());
53
		try {
54
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectById(id));
55
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
56
		}catch (ProfitMandiBusinessException pmbe) {
57
			LOGGER.error("ProfitMandi error: ", pmbe);
58
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
59
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
60
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
61
		}catch (Exception e) {
62
			LOGGER.error("Internal Server Error: ", e);
63
			final Response response=new Response("","","", e.getMessage());
64
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
65
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
66
		}
67
	}
68
 
69
	@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER,method=RequestMethod.GET)
70
	public ResponseEntity<?> getByMobileNumber(HttpServletRequest request, @RequestParam(name = "mobileNumber") String mobileNumber){
71
		LOGGER.info("requested url : "+request.getRequestURL().toString());
72
		try {
73
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectByMobileNumber(mobileNumber));
74
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
75
		}catch (ProfitMandiBusinessException pmbe) {
76
			LOGGER.error("ProfitMandi error: ", pmbe);
77
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
78
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
79
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
80
		}catch (Exception e) {
81
			LOGGER.error("Internal Server Error: ", e);
82
			final Response response=new Response("","","", e.getMessage());
83
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
84
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
85
		}
86
	}
87
 
88
 
89
	@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID,method=RequestMethod.GET)
90
	public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId){
91
		LOGGER.info("requested url : "+request.getRequestURL().toString());
92
		try {
93
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectByEmailId(emailId));
94
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
95
		}catch (ProfitMandiBusinessException pmbe) {
96
			LOGGER.error("ProfitMandi error: ", pmbe);
97
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
98
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
99
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
100
		}catch (Exception e) {
101
			LOGGER.error("Internal Server Error: ", e);
102
			final Response response=new Response("","","", e.getMessage());
103
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
104
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
105
		}
106
	}
107
 
108
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_ID, method = RequestMethod.PUT)
109
	public ResponseEntity<?> addRoleByIdWithId(HttpServletRequest request, @RequestParam(name = "roleId") long roleId, @RequestParam(name = "userId") long userId){
110
		LOGGER.info("requested url : "+request.getRequestURL().toString());
111
		try {
112
			userRepository.addRoleByIdWithId(roleId, userId);
113
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
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> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
119
			return new ResponseEntity<>(profitMandiResponse,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> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
124
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
125
		}
126
	}
127
 
128
 
129
 
130
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_MOBILE_NUMBER, method = RequestMethod.PUT)
131
	public ResponseEntity<?> addRoleByIdWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "mobileNumber") String mobileNumber){
132
		LOGGER.info("requested url : "+request.getRequestURL().toString());
133
		try {
134
			userRepository.addRoleByIdWithMobileNumber(id, mobileNumber);
135
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
136
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
137
		}catch (ProfitMandiBusinessException pmbe) {
138
			LOGGER.error("ProfitMandi error: ", pmbe);
139
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
140
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
141
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
142
		}catch (Exception e) {
143
			LOGGER.error("Internal Server Error : ",e);
144
			final Response response=new Response("","","", e.getMessage());
145
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
146
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
147
		}
148
	}
149
 
150
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_EMAIL_ID, method = RequestMethod.PUT)
151
	public ResponseEntity<?> addRoleByIdWithEmailId(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "emailId") String emailId){
152
		LOGGER.info("requested url : "+request.getRequestURL().toString());
153
		try {
154
			userRepository.addRoleByIdWithEmailId(id, emailId);
155
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
156
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
157
		}catch (ProfitMandiBusinessException pmbe) {
158
			LOGGER.error("ProfitMandi error: ", pmbe);
159
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
160
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
161
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
162
		}catch (Exception e) {
163
			LOGGER.error("Internal Server Error : ",e);
164
			final Response response=new Response("","","", e.getMessage());
165
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
166
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
167
		}
168
	}
169
 
170
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_ID, method = RequestMethod.PUT)
171
	public ResponseEntity<?> addRoleByNameWithId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "userId") long id){
172
		LOGGER.info("requested url : "+request.getRequestURL().toString());
173
		try {
174
			userRepository.addRoleByNameWithId(roleName, id);
175
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
176
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
177
		}catch (ProfitMandiBusinessException pmbe) {
178
			LOGGER.error("ProfitMandi error: ", pmbe);
179
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
180
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
181
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
182
		}catch (Exception e) {
183
			LOGGER.error("Internal Server Error : ",e);
184
			final Response response=new Response("","","", e.getMessage());
185
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
186
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
187
		}
188
	}
189
 
190
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_MOBILE_NUMBER, method = RequestMethod.PUT)
191
	public ResponseEntity<?> addRoleByNameWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "mobileNumber") String mobileNumber){
192
		LOGGER.info("requested url : "+request.getRequestURL().toString());
193
		try {
194
			userRepository.addRoleByNameWithMobileNumber(roleName, mobileNumber);
195
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
196
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
197
		}catch (ProfitMandiBusinessException pmbe) {
198
			LOGGER.error("ProfitMandi error: ", pmbe);
199
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
200
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
201
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
202
		}catch (Exception e) {
203
			LOGGER.error("Internal Server Error : ",e);
204
			final Response response=new Response("","","", e.getMessage());
205
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
206
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
207
		}
208
	}
209
 
210
 
211
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_EMAIL_ID, method = RequestMethod.PUT)
212
	public ResponseEntity<?> addRoleByNameWithEmailId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "emailId") String emailId){
213
		LOGGER.info("requested url : "+request.getRequestURL().toString());
214
		try {
215
			userRepository.addRoleByNameWithEmailId(roleName, emailId);
216
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
217
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
218
		}catch (ProfitMandiBusinessException pmbe) {
219
			LOGGER.error("ProfitMandi error: ", pmbe);
220
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
221
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
222
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
223
		}catch (Exception e) {
224
			LOGGER.error("Internal Server Error : ",e);
225
			final Response response=new Response("","","", e.getMessage());
226
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
227
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
228
		}
229
	}
230
 
231
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_ID, method = RequestMethod.DELETE)
232
	public ResponseEntity<?> removeRoleByIdWithId(HttpServletRequest request, @RequestParam(name = "roleId") long roleId, @RequestParam(name = "userId") long userId){
233
		LOGGER.info("requested url : "+request.getRequestURL().toString());
234
		try {
235
			userRepository.deleteRoleByIdWithId(roleId, userId);
236
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
237
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
238
		}catch (ProfitMandiBusinessException pmbe) {
239
			LOGGER.error("ProfitMandi error: ", pmbe);
240
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
241
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
242
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
243
		}catch (Exception e) {
244
			LOGGER.error("Internal Server Error : ",e);
245
			final Response response=new Response("","","", e.getMessage());
246
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
247
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
248
		}
249
	}
250
 
251
 
252
 
253
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_MOBILE_NUMBER, method = RequestMethod.DELETE)
254
	public ResponseEntity<?> removeRoleByIdWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "mobileNumber") String mobileNumber){
255
		LOGGER.info("requested url : "+request.getRequestURL().toString());
256
		try {
257
			userRepository.deleteRoleByIdWithMobileNumber(id, mobileNumber);
258
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
259
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
260
		}catch (ProfitMandiBusinessException pmbe) {
261
			LOGGER.error("ProfitMandi error: ", pmbe);
262
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
263
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
264
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
265
		}catch (Exception e) {
266
			LOGGER.error("Internal Server Error : ",e);
267
			final Response response=new Response("","","", e.getMessage());
268
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
269
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
270
		}
271
	}
272
 
273
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_EMAIL_ID, method = RequestMethod.DELETE)
274
	public ResponseEntity<?> removeRoleByIdWithEmailId(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "emailId") String emailId){
275
		LOGGER.info("requested url : "+request.getRequestURL().toString());
276
		try {
277
			userRepository.deleteRoleByIdWithEmailId(id, emailId);
278
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
279
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
280
		}catch (ProfitMandiBusinessException pmbe) {
281
			LOGGER.error("ProfitMandi error: ", pmbe);
282
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
283
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
284
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
285
		}catch (Exception e) {
286
			LOGGER.error("Internal Server Error : ",e);
287
			final Response response=new Response("","","", e.getMessage());
288
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
289
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
290
		}
291
	}
292
 
293
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_ID, method = RequestMethod.DELETE)
294
	public ResponseEntity<?> removeRoleByNameWithId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "userId") long id){
295
		LOGGER.info("requested url : "+request.getRequestURL().toString());
296
		try {
297
			userRepository.deleteRoleByNameWithId(roleName, id);
298
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
299
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
300
		}catch (ProfitMandiBusinessException pmbe) {
301
			LOGGER.error("ProfitMandi error: ", pmbe);
302
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
303
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
304
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
305
		}catch (Exception e) {
306
			LOGGER.error("Internal Server Error : ",e);
307
			final Response response=new Response("","","", e.getMessage());
308
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
309
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
310
		}
311
	}
312
 
313
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_MOBILE_NUMBER, method = RequestMethod.DELETE)
314
	public ResponseEntity<?> removeRoleByNameWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "mobileNumber") String mobileNumber){
315
		LOGGER.info("requested url : "+request.getRequestURL().toString());
316
		try {
317
			userRepository.deleteRoleByNameWithMobileNumber(roleName, mobileNumber);
318
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
319
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
320
		}catch (ProfitMandiBusinessException pmbe) {
321
			LOGGER.error("ProfitMandi error: ", pmbe);
322
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
323
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
324
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
325
		}catch (Exception e) {
326
			LOGGER.error("Internal Server Error : ",e);
327
			final Response response=new Response("","","", e.getMessage());
328
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
329
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
330
		}
331
	}
332
 
333
 
334
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_EMAIL_ID, method = RequestMethod.DELETE)
335
	public ResponseEntity<?> removeRoleByNameWithEmailId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "emailId") String emailId){
336
		LOGGER.info("requested url : "+request.getRequestURL().toString());
337
		try {
338
			userRepository.deleteRoleByNameWithEmailId(roleName, emailId);
339
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
340
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
341
		}catch (ProfitMandiBusinessException pmbe) {
342
			LOGGER.error("ProfitMandi error: ", pmbe);
343
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
344
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
345
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
346
		}catch (Exception e) {
347
			LOGGER.error("Internal Server Error : ",e);
348
			final Response response=new Response("","","", e.getMessage());
349
			final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
350
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
351
		}
352
	}
353
}