| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| 4 |
import java.util.HashMap;
|
4 |
import java.util.HashMap;
|
| 5 |
import java.util.Map;
|
5 |
import java.util.Map;
|
| 6 |
|
6 |
|
| 7 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 8 |
import org.springframework.stereotype.Component;
|
7 |
import org.springframework.stereotype.Component;
|
| 9 |
|
8 |
|
| 10 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
9 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
| 11 |
import com.fasterxml.jackson.databind.JsonNode;
|
10 |
import com.fasterxml.jackson.databind.JsonNode;
|
| 12 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
11 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 13 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
12 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 14 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
13 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 15 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
14 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 16 |
import com.spice.profitmandi.common.web.client.RestClient;
|
15 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 17 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
- |
|
| 18 |
import com.spice.profitmandi.web.model.FofoDetails;
|
- |
|
| 19 |
|
16 |
|
| 20 |
@Component
|
17 |
@Component
|
| 21 |
public class GoogleLoginUtil {
|
18 |
public class GoogleTokenUtil {
|
| 22 |
|
- |
|
| 23 |
@Autowired
|
- |
|
| 24 |
RetailerRepository retailerRepository;
|
- |
|
| 25 |
|
19 |
|
| 26 |
private static final String V3_HOST_NAME = "www.googleapis.com";
|
20 |
private static final String V3_HOST_NAME = "www.googleapis.com";
|
| 27 |
private static final String V3_URI = "/oauth2/v3/tokeninfo";
|
21 |
private static final String V3_URI = "/oauth2/v3/tokeninfo";
|
| 28 |
private static final int PORT_NUMBER = 443;
|
22 |
private static final int PORT_NUMBER = 443;
|
| 29 |
private final ObjectMapper objectMapper = new ObjectMapper();
|
23 |
private final ObjectMapper objectMapper = new ObjectMapper();
|
| 30 |
|
24 |
|
| 31 |
public FofoDetails getFofoDetail(String token) throws ProfitMandiBusinessException{
|
25 |
public String getEmailId(String token) throws ProfitMandiBusinessException{
|
| 32 |
RestClient restClient = new RestClient(SchemeType.HTTPS, V3_HOST_NAME, PORT_NUMBER);
|
26 |
RestClient restClient = new RestClient(SchemeType.HTTPS, V3_HOST_NAME, PORT_NUMBER);
|
| 33 |
Map<String, String> params = new HashMap<>();
|
27 |
Map<String, String> params = new HashMap<>();
|
| 34 |
params.put(ProfitMandiConstants.ID_TOKEN, token);
|
28 |
params.put(ProfitMandiConstants.ID_TOKEN, token);
|
| 35 |
String responseString = restClient.get(V3_URI, params);
|
29 |
String responseString = restClient.get(V3_URI, params);
|
| 36 |
try {
|
30 |
try {
|
| 37 |
JsonNode rootNode = objectMapper.readTree(responseString);
|
31 |
JsonNode rootNode = objectMapper.readTree(responseString);
|
| 38 |
Object[] idAndEmailId = retailerRepository.selectFofoIdAndEmailIdByEmailId(rootNode.get("email").asText());
|
- |
|
| 39 |
FofoDetails fofoDetails = new FofoDetails();
|
32 |
return rootNode.get("email").asText();
|
| 40 |
fofoDetails.setFofoId((Integer)idAndEmailId[0]);
|
- |
|
| 41 |
fofoDetails.setEmailId((String)idAndEmailId[1]);
|
- |
|
| 42 |
return fofoDetails;
|
33 |
|
| 43 |
}catch (JsonProcessingException jsonProcessingException) {
|
34 |
}catch (JsonProcessingException jsonProcessingException) {
|
| 44 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
35 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
| 45 |
}catch (IOException ioException) {
|
36 |
}catch (IOException ioException) {
|
| 46 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
37 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
| 47 |
}
|
38 |
}
|