Subversion Repositories SmartDukaan

Rev

Rev 21277 | Rev 21282 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21277 Rev 21278
Line 5... Line 5...
5
 
5
 
6
import javax.servlet.http.HttpServletRequest;
6
import javax.servlet.http.HttpServletRequest;
7
 
7
 
8
import org.slf4j.Logger;
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
9
import org.slf4j.LoggerFactory;
-
 
10
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.http.HttpStatus;
11
import org.springframework.http.HttpStatus;
11
import org.springframework.http.ResponseEntity;
12
import org.springframework.http.ResponseEntity;
12
import org.springframework.stereotype.Controller;
13
import org.springframework.stereotype.Controller;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestMethod;
15
import org.springframework.web.bind.annotation.RequestMethod;
15
import org.springframework.web.bind.annotation.RequestParam;
16
import org.springframework.web.bind.annotation.RequestParam;
16
 
17
 
17
import com.spice.profitmandi.common.ResponseCodeHolder;
18
import com.spice.profitmandi.common.ResponseCodeHolder;
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.model.ProfitMandiConstants;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
21
import com.spice.profitmandi.dao.entity.User;
20
import com.spice.profitmandi.dao.repository.UserRepository;
22
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.ProfitMandiResponse;
23
import com.spice.profitmandi.web.model.Response;
24
import com.spice.profitmandi.web.model.Response;
24
import com.spice.profitmandi.web.model.ResponseStatus;
25
import com.spice.profitmandi.web.model.ResponseStatus;
25
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
26
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
26
 
27
 
Line 31... Line 32...
31
@Controller
32
@Controller
32
public class UserController {
33
public class UserController {
33
	
34
	
34
	private static final Logger LOGGER=LoggerFactory.getLogger(UserController.class);
35
	private static final Logger LOGGER=LoggerFactory.getLogger(UserController.class);
35
	
36
	
-
 
37
	@Autowired
36
	private UserRepository userRepository = UserRepositoryImpl.getInstance();
38
	UserRepository userRepository;
37
	
39
	
-
 
40
	@Autowired
-
 
41
	GoogleLoginProcessor googleLoginProcessor;
-
 
42
		
38
	@SuppressWarnings("unchecked")
43
	@SuppressWarnings("unchecked")
39
	@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN,method=RequestMethod.POST)
44
	@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN,method=RequestMethod.POST)
40
	public ResponseEntity<?> googleLogin(HttpServletRequest request){
45
	public ResponseEntity<?> googleLogin(HttpServletRequest request){
41
		LOGGER.info("requested url : "+request.getRequestURL().toString());
46
		LOGGER.info("requested url : "+request.getRequestURL().toString());
42
		final Map<String, Object> googleLoginMap = (Map<String, Object>)request.getAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
47
		final Map<String, Object> googleLoginMap = (Map<String, Object>)request.getAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
43
		request.removeAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
48
		request.removeAttribute(ProfitMandiConstants.GOOGLE_LOGIN_MAP);
44
		GoogleLoginProcessor googleLoginProcessor = GoogleLoginProcessor.getInstance();
-
 
45
		try {
49
		try {
46
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, googleLoginProcessor.process(googleLoginMap));
50
			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);
51
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
48
		}catch (ProfitMandiBusinessException pmbe) {
52
		}catch (ProfitMandiBusinessException pmbe) {
49
			LOGGER.error("ProfitMandi error: ", pmbe);
53
			LOGGER.error("ProfitMandi error: ", pmbe);
Line 56... Line 60...
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);
60
			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);
61
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
58
		}
62
		}
59
	}
63
	}
60
	
64
	
-
 
65
	@RequestMapping(value = ProfitMandiConstants.URL_USER, method=RequestMethod.POST)
-
 
66
	public ResponseEntity<?> createUser(HttpServletRequest request){
-
 
67
		LOGGER.info("requested url : "+request.getRequestURL().toString());
-
 
68
		final User user = (User)request.getAttribute(ProfitMandiConstants.USER);
-
 
69
		request.removeAttribute(ProfitMandiConstants.USER);
-
 
70
		try {
-
 
71
			user.setCreateTimestamp(LocalDateTime.now());
-
 
72
			user.setUpdateTimestamp(LocalDateTime.now());
-
 
73
			userRepository.persist(user);
-
 
74
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1000"));
-
 
75
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
-
 
76
		}catch (ProfitMandiBusinessException pmbe) {
-
 
77
			LOGGER.error("ProfitMandi error: ", pmbe);
-
 
78
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
-
 
79
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
-
 
80
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
-
 
81
		}catch (Exception e) {
-
 
82
			LOGGER.error("Internal Server Error : ",e);
-
 
83
			final Response response=new Response("","","", e.getMessage());
-
 
84
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
-
 
85
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
86
		}
-
 
87
	}
-
 
88
	
61
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ALL,method=RequestMethod.GET)
89
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ALL,method=RequestMethod.GET)
62
	public ResponseEntity<?> getAll(HttpServletRequest request){
90
	public ResponseEntity<?> getAll(HttpServletRequest request){
63
		LOGGER.info("requested url : "+request.getRequestURL().toString());
91
		LOGGER.info("requested url : "+request.getRequestURL().toString());
64
		try {
92
		try {
65
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectAll());
93
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, userRepository.selectAll());