Subversion Repositories SmartDukaan

Rev

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