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