Subversion Repositories SmartDukaan

Rev

Rev 21278 | Rev 21368 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.controller;

import java.time.LocalDateTime;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.spice.profitmandi.common.ResponseCodeHolder;
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.common.model.ProfitMandiConstants;
import com.spice.profitmandi.common.util.JWTUtil;
import com.spice.profitmandi.dao.entity.User;
import com.spice.profitmandi.dao.repository.UserRepository;
import com.spice.profitmandi.web.model.ProfitMandiResponse;
import com.spice.profitmandi.web.model.Response;
import com.spice.profitmandi.web.model.ResponseStatus;
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;

/**
 * @author ashikali
 *
 */
@Controller
public class UserController {
        
        private static final Logger LOGGER=LoggerFactory.getLogger(UserController.class);
        
        @Autowired
        UserRepository userRepository;
        
        @Autowired
        GoogleLoginProcessor googleLoginProcessor;
                
        @SuppressWarnings("unchecked")
        @RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN,method=RequestMethod.POST)
        public ResponseEntity<?> googleLogin(HttpServletRequest request){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                final Map<String, Object> googleLoginMap = (Map<String, Object>)request.getAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
                request.removeAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
                try {
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, googleLoginProcessor.process(googleLoginMap));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method=RequestMethod.GET)
        public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, JWTUtil.isExpired(token));
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error: ", e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_DETAIL, method=RequestMethod.GET)
        public ResponseEntity<?> tokenDetail(HttpServletRequest request, @RequestParam(name = "token") String token){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectById(JWTUtil.getUserId(token)));
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error: ", e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER, method=RequestMethod.POST)
        public ResponseEntity<?> createUser(HttpServletRequest request){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                final User user = (User)request.getAttribute(ProfitMandiConstants.USER);
                request.removeAttribute(ProfitMandiConstants.USER);
                try {
                        user.setCreateTimestamp(LocalDateTime.now());
                        user.setUpdateTimestamp(LocalDateTime.now());
                        userRepository.persist(user);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("USR_OK_1000"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ALL,method=RequestMethod.GET)
        public ResponseEntity<?> getAll(HttpServletRequest request){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectAll());
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ID,method=RequestMethod.GET)
        public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") long id){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectById(id));
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error: ", e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER,method=RequestMethod.GET)
        public ResponseEntity<?> getByMobileNumber(HttpServletRequest request, @RequestParam(name = "mobileNumber") String mobileNumber){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectByMobileNumber(mobileNumber));
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error: ", e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID,method=RequestMethod.GET)
        public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectByEmailId(emailId));
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error: ", e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_ID, method = RequestMethod.PUT)
        public ResponseEntity<?> addRoleByIdWithId(HttpServletRequest request, @RequestParam(name = "roleId") long roleId, @RequestParam(name = "userId") long userId){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.addRoleByIdWithId(roleId, userId);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_MOBILE_NUMBER, method = RequestMethod.PUT)
        public ResponseEntity<?> addRoleByIdWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "mobileNumber") String mobileNumber){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.addRoleByIdWithMobileNumber(id, mobileNumber);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_EMAIL_ID, method = RequestMethod.PUT)
        public ResponseEntity<?> addRoleByIdWithEmailId(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "emailId") String emailId){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.addRoleByIdWithEmailId(id, emailId);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_ID, method = RequestMethod.PUT)
        public ResponseEntity<?> addRoleByNameWithId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "userId") long id){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.addRoleByNameWithId(roleName, id);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_MOBILE_NUMBER, method = RequestMethod.PUT)
        public ResponseEntity<?> addRoleByNameWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "mobileNumber") String mobileNumber){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.addRoleByNameWithMobileNumber(roleName, mobileNumber);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_EMAIL_ID, method = RequestMethod.PUT)
        public ResponseEntity<?> addRoleByNameWithEmailId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "emailId") String emailId){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.addRoleByNameWithEmailId(roleName, emailId);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_ID, method = RequestMethod.DELETE)
        public ResponseEntity<?> removeRoleByIdWithId(HttpServletRequest request, @RequestParam(name = "roleId") long roleId, @RequestParam(name = "userId") long userId){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.deleteRoleByIdWithId(roleId, userId);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_MOBILE_NUMBER, method = RequestMethod.DELETE)
        public ResponseEntity<?> removeRoleByIdWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "mobileNumber") String mobileNumber){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.deleteRoleByIdWithMobileNumber(id, mobileNumber);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_ID_WITH_EMAIL_ID, method = RequestMethod.DELETE)
        public ResponseEntity<?> removeRoleByIdWithEmailId(HttpServletRequest request, @RequestParam(name = "roleId") long id, @RequestParam(name = "emailId") String emailId){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.deleteRoleByIdWithEmailId(id, emailId);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_ID, method = RequestMethod.DELETE)
        public ResponseEntity<?> removeRoleByNameWithId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "userId") long id){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.deleteRoleByNameWithId(roleName, id);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_MOBILE_NUMBER, method = RequestMethod.DELETE)
        public ResponseEntity<?> removeRoleByNameWithMobileNumber(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "mobileNumber") String mobileNumber){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.deleteRoleByNameWithMobileNumber(roleName, mobileNumber);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
        
        
        @RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_BY_NAME_WITH_EMAIL_ID, method = RequestMethod.DELETE)
        public ResponseEntity<?> removeRoleByNameWithEmailId(HttpServletRequest request, @RequestParam(name = "roleName") String roleName, @RequestParam(name = "emailId") String emailId){
                LOGGER.info("requested url : "+request.getRequestURL().toString());
                try {
                        userRepository.deleteRoleByNameWithEmailId(roleName, emailId);
                        final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("ROL_OK_1001"));
                        return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
                }catch (ProfitMandiBusinessException pmbe) {
                        LOGGER.error("ProfitMandi error: ", pmbe);
                        final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
                }catch (Exception e) {
                        LOGGER.error("Internal Server Error : ",e);
                        final Response response=new Response("","","", e.getMessage());
                        final ProfitMandiResponse<Response> profitMandiResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
                        return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
                }
        }
}