| 21277 |
ashik.ali |
1 |
package com.spice.profitmandi.web.processor;
|
|
|
2 |
|
|
|
3 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
4 |
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
5 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 21556 |
ashik.ali |
6 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 21277 |
ashik.ali |
7 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
8 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
9 |
import com.spice.profitmandi.common.util.JWTUtil;
|
| 21556 |
ashik.ali |
10 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 34294 |
vikas.jang |
11 |
import com.spice.profitmandi.dao.entity.fofo.PincodePartner;
|
| 24491 |
amit.gupta |
12 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 27043 |
amit.gupta |
13 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 30295 |
amit.gupta |
14 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 34294 |
vikas.jang |
15 |
import com.spice.profitmandi.dao.repository.fofo.PincodePartnerRepository;
|
| 24491 |
amit.gupta |
16 |
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
|
|
|
17 |
import com.spice.profitmandi.service.AuthService;
|
| 26590 |
amit.gupta |
18 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 30295 |
amit.gupta |
19 |
import org.apache.http.conn.HttpHostConnectException;
|
|
|
20 |
import org.apache.logging.log4j.LogManager;
|
|
|
21 |
import org.apache.logging.log4j.Logger;
|
|
|
22 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
23 |
import org.springframework.http.HttpHeaders;
|
|
|
24 |
import org.springframework.http.MediaType;
|
|
|
25 |
import org.springframework.stereotype.Component;
|
| 21277 |
ashik.ali |
26 |
|
| 30295 |
amit.gupta |
27 |
import java.io.IOException;
|
|
|
28 |
import java.util.HashMap;
|
|
|
29 |
import java.util.List;
|
|
|
30 |
import java.util.Map;
|
|
|
31 |
|
| 21282 |
ashik.ali |
32 |
@Component
|
| 21277 |
ashik.ali |
33 |
public class GoogleLoginProcessor {
|
| 24491 |
amit.gupta |
34 |
|
| 21556 |
ashik.ali |
35 |
private static final String V1_HOST_NAME = "content.googleapis.com";
|
|
|
36 |
private static final String V1_URI = "/plus/v1/people/me";
|
|
|
37 |
private static final String V3_HOST_NAME = "www.googleapis.com";
|
|
|
38 |
private static final String V3_URI = "/oauth2/v3/tokeninfo";
|
| 24491 |
amit.gupta |
39 |
private static final Logger LOGGER = LogManager.getLogger(GoogleLoginProcessor.class);
|
| 21277 |
ashik.ali |
40 |
private static final int PORT_NUMBER = 443;
|
|
|
41 |
private final ObjectMapper objectMapper = new ObjectMapper();
|
| 24491 |
amit.gupta |
42 |
|
| 21278 |
ashik.ali |
43 |
@Autowired
|
| 22931 |
ashik.ali |
44 |
private SocialUserRepository socialUserRepository;
|
| 24491 |
amit.gupta |
45 |
|
| 21278 |
ashik.ali |
46 |
@Autowired
|
| 22931 |
ashik.ali |
47 |
private UserRepository userRepository;
|
| 24491 |
amit.gupta |
48 |
|
|
|
49 |
@Autowired
|
|
|
50 |
private AuthService authService;
|
| 25388 |
tejbeer |
51 |
|
| 22011 |
ashik.ali |
52 |
@Autowired
|
| 25388 |
tejbeer |
53 |
com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
|
|
54 |
|
|
|
55 |
@Autowired
|
| 24491 |
amit.gupta |
56 |
private AuthRepository authRepository;
|
| 25388 |
tejbeer |
57 |
|
| 26590 |
amit.gupta |
58 |
|
| 23860 |
ashik.ali |
59 |
@Autowired
|
| 24491 |
amit.gupta |
60 |
private UserRoleRepository userRoleRepository;
|
|
|
61 |
|
|
|
62 |
@Autowired
|
|
|
63 |
private PromoterRepository promoterRepository;
|
|
|
64 |
|
|
|
65 |
@Autowired
|
| 23860 |
ashik.ali |
66 |
private UserAccountRepository userAccountRepository;
|
| 27043 |
amit.gupta |
67 |
|
|
|
68 |
@Autowired
|
| 28094 |
amit.gupta |
69 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
70 |
|
|
|
71 |
@Autowired
|
| 27043 |
amit.gupta |
72 |
private CsService csService;
|
| 24491 |
amit.gupta |
73 |
|
| 23860 |
ashik.ali |
74 |
@Autowired
|
|
|
75 |
private RestClient restClient;
|
| 26590 |
amit.gupta |
76 |
@Autowired
|
|
|
77 |
private RetailerService retailerService;
|
| 25388 |
tejbeer |
78 |
|
| 34294 |
vikas.jang |
79 |
@Autowired
|
|
|
80 |
private PincodePartnerRepository pincodePartnerRepository;
|
|
|
81 |
|
| 30295 |
amit.gupta |
82 |
public String process(String token) throws ProfitMandiBusinessException {
|
| 21556 |
ashik.ali |
83 |
Map<String, String> params = new HashMap<>();
|
|
|
84 |
params.put(ProfitMandiConstants.ID_TOKEN, token);
|
| 26673 |
amit.gupta |
85 |
Map<String, String> headers = new HashMap<>();
|
| 22355 |
ashik.ali |
86 |
headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
| 23860 |
ashik.ali |
87 |
String responseString = null;
|
| 21556 |
ashik.ali |
88 |
try {
|
| 23532 |
amit.gupta |
89 |
responseString = restClient.get(SchemeType.HTTPS, V3_HOST_NAME, PORT_NUMBER, V3_URI, params, headers);
|
| 23860 |
ashik.ali |
90 |
} catch (HttpHostConnectException e) {
|
|
|
91 |
// TODO Auto-generated catch block
|
|
|
92 |
e.printStackTrace();
|
| 23532 |
amit.gupta |
93 |
}
|
|
|
94 |
try {
|
| 21556 |
ashik.ali |
95 |
JsonNode rootNode = objectMapper.readTree(responseString);
|
| 26396 |
amit.gupta |
96 |
String email = rootNode.get("email").asText();
|
|
|
97 |
|
| 30295 |
amit.gupta |
98 |
return email;
|
| 24491 |
amit.gupta |
99 |
} catch (JsonProcessingException jsonProcessingException) {
|
| 21556 |
ashik.ali |
100 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
|
|
101 |
}
|
|
|
102 |
}
|
| 26590 |
amit.gupta |
103 |
|
|
|
104 |
public Map<String, Object> processStore(String storeCode) throws ProfitMandiBusinessException {
|
|
|
105 |
Map<String, Object> responseMap = new HashMap<>();
|
| 26598 |
amit.gupta |
106 |
int retailerId = retailerService.getStoreCodeRetailerMap().get(storeCode);
|
| 26590 |
amit.gupta |
107 |
int userId = userAccountRepository.selectUserIdByRetailerId(retailerId);
|
|
|
108 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(userId);
|
| 34294 |
vikas.jang |
109 |
PincodePartner partnerPin = pincodePartnerRepository.selectPinCodeByPartnerId(retailerId);
|
| 26590 |
amit.gupta |
110 |
String[] roleTypes = new String[roleIds.size()];
|
|
|
111 |
int index = 0;
|
|
|
112 |
for (int roleId : roleIds) {
|
|
|
113 |
roleTypes[index++] = String.valueOf(roleId);
|
|
|
114 |
}
|
|
|
115 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(userId, retailerId, roleTypes));
|
|
|
116 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
| 34294 |
vikas.jang |
117 |
responseMap.put(ProfitMandiConstants.PIN_CODE, partnerPin != null ? partnerPin.getPincode() : partnerPin);
|
| 26590 |
amit.gupta |
118 |
return responseMap;
|
|
|
119 |
}
|
| 21277 |
ashik.ali |
120 |
}
|