Subversion Repositories SmartDukaan

Rev

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

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