Subversion Repositories SmartDukaan

Rev

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

Rev 21469 Rev 21556
Line 12... Line 12...
12
import org.springframework.stereotype.Component;
12
import org.springframework.stereotype.Component;
13
 
13
 
14
import com.fasterxml.jackson.core.JsonProcessingException;
14
import com.fasterxml.jackson.core.JsonProcessingException;
15
import com.fasterxml.jackson.databind.JsonNode;
15
import com.fasterxml.jackson.databind.JsonNode;
16
import com.fasterxml.jackson.databind.ObjectMapper;
16
import com.fasterxml.jackson.databind.ObjectMapper;
-
 
17
import com.spice.profitmandi.common.enumuration.SchemeType;
17
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
18
import com.spice.profitmandi.common.model.ProfitMandiConstants;
19
import com.spice.profitmandi.common.model.ProfitMandiConstants;
19
import com.spice.profitmandi.common.util.JWTUtil;
20
import com.spice.profitmandi.common.util.JWTUtil;
-
 
21
import com.spice.profitmandi.common.web.client.RestClient;
20
import com.spice.profitmandi.dao.entity.Role;
22
import com.spice.profitmandi.dao.entity.Role;
21
import com.spice.profitmandi.dao.entity.SocialUser;
23
import com.spice.profitmandi.dao.entity.SocialUser;
22
import com.spice.profitmandi.dao.entity.User;
24
import com.spice.profitmandi.dao.entity.User;
23
import com.spice.profitmandi.dao.enumuration.Gender;
25
import com.spice.profitmandi.dao.enumuration.Gender;
24
import com.spice.profitmandi.dao.enumuration.SocialType;
26
import com.spice.profitmandi.dao.enumuration.SocialType;
25
import com.spice.profitmandi.dao.repository.SocialUserRepository;
27
import com.spice.profitmandi.dao.repository.SocialUserRepository;
26
import com.spice.profitmandi.dao.repository.UserRepository;
28
import com.spice.profitmandi.dao.repository.UserRepository;
27
import com.spice.profitmandi.web.client.RestClient;
-
 
28
import com.spice.profitmandi.web.enumuration.SchemeType;
-
 
29
 
29
 
30
@Component
30
@Component
31
public class GoogleLoginProcessor {
31
public class GoogleLoginProcessor {
32
	
32
	
33
	private static final String HOST_NAME = "content.googleapis.com";
33
	private static final String V1_HOST_NAME = "content.googleapis.com";
34
	private static final String URI = "/plus/v1/people/me";
34
	private static final String V1_URI = "/plus/v1/people/me";
-
 
35
	private static final String V3_HOST_NAME = "www.googleapis.com";
-
 
36
	private static final String V3_URI = "/oauth2/v3/tokeninfo";
35
	private static final int PORT_NUMBER = 443;
37
	private static final int PORT_NUMBER = 443;
36
	private final ObjectMapper objectMapper = new ObjectMapper();
38
	private final ObjectMapper objectMapper = new ObjectMapper();
37
	
39
	
38
	@Autowired
40
	@Autowired
39
	SocialUserRepository socialUserRepository;
41
	SocialUserRepository socialUserRepository;
40
	
42
	
41
	@Autowired
43
	@Autowired
42
	UserRepository userRepository;
44
	UserRepository userRepository;
43
	
45
	
44
	public Map<String, Object> process(Map<String, Object> map) throws ProfitMandiBusinessException{
46
	public Map<String, Object> process(Map<String, Object> map) throws ProfitMandiBusinessException{
45
		RestClient restClient = new RestClient(SchemeType.HTTPS, HOST_NAME, PORT_NUMBER);
47
		RestClient restClient = new RestClient(SchemeType.HTTPS, V1_HOST_NAME, PORT_NUMBER);
46
		Map<String, String> params = new HashMap<>();
48
		Map<String, String> params = new HashMap<>();
47
		params.put(ProfitMandiConstants.ACCESS_TOKEN, map.get(ProfitMandiConstants.TOKEN).toString());
49
		params.put(ProfitMandiConstants.ACCESS_TOKEN, map.get(ProfitMandiConstants.TOKEN).toString());
48
		String responseString = restClient.get(URI, params);
50
		String responseString = restClient.get(V1_URI, params);
49
		try {
51
		try {
50
			JsonNode rootNode = objectMapper.readTree(responseString);
52
			JsonNode rootNode = objectMapper.readTree(responseString);
51
			SocialUser socialUser = new SocialUser();
53
			SocialUser socialUser = new SocialUser();
52
			if(rootNode.has("emails")){
54
			if(rootNode.has("emails")){
53
				JsonNode emails = rootNode.get("emails");
55
				JsonNode emails = rootNode.get("emails");
Line 104... Line 106...
104
		}catch (IOException ioException) {
106
		}catch (IOException ioException) {
105
			//LOGGER.error("IO Exception occurred while parsing json String");
107
			//LOGGER.error("IO Exception occurred while parsing json String");
106
			throw new ProfitMandiBusinessException("", "", "VE_1001");
108
			throw new ProfitMandiBusinessException("", "", "VE_1001");
107
		}
109
		}
108
	}
110
	}
-
 
111
	
-
 
112
	public Map<String, Object> getFofoDetail(String token) throws ProfitMandiBusinessException{
-
 
113
		RestClient restClient = new RestClient(SchemeType.HTTPS, V3_HOST_NAME, PORT_NUMBER);
-
 
114
		Map<String, String> params = new HashMap<>();
-
 
115
		params.put(ProfitMandiConstants.ID_TOKEN, token);
-
 
116
		String responseString = restClient.get(V3_URI, params);
-
 
117
		try {
-
 
118
			JsonNode rootNode = objectMapper.readTree(responseString);
-
 
119
			try{
-
 
120
				User user = userRepository.selectByEmailId(rootNode.get("email").asText());
-
 
121
				Map<String, Object> responseMap = new HashMap<>(2);
-
 
122
				responseMap.put(ProfitMandiConstants.FOFO_ID, user.getId());
-
 
123
				responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
-
 
124
				return responseMap;
-
 
125
			}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
126
				throw new ProfitMandiBusinessException(profitMandiBusinessException.getRejectedType(), profitMandiBusinessException.getRejectedValue(), "");
-
 
127
			}
-
 
128
			
-
 
129
		}catch (JsonProcessingException jsonProcessingException) {
-
 
130
			throw new ProfitMandiBusinessException("", "", "VE_1001");
-
 
131
		}catch (IOException ioException) {
-
 
132
			throw new ProfitMandiBusinessException("", "", "VE_1001");
-
 
133
		}
-
 
134
	}
109
}
135
}