Rev 34294 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.processor;import com.fasterxml.jackson.core.JsonProcessingException;import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import com.spice.profitmandi.common.enumuration.SchemeType;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.service.authentication.JWTUtil;import com.spice.profitmandi.common.web.client.RestClient;import com.spice.profitmandi.dao.entity.fofo.PincodePartner;import com.spice.profitmandi.dao.repository.auth.AuthRepository;import com.spice.profitmandi.dao.repository.cs.CsService;import com.spice.profitmandi.dao.repository.dtr.*;import com.spice.profitmandi.dao.repository.fofo.PincodePartnerRepository;import com.spice.profitmandi.dao.repository.user.PromoterRepository;import com.spice.profitmandi.service.AuthService;import com.spice.profitmandi.service.user.RetailerService;import org.apache.http.conn.HttpHostConnectException;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.HttpHeaders;import org.springframework.http.MediaType;import org.springframework.stereotype.Component;import java.util.HashMap;import java.util.List;import java.util.Map;@Componentpublic class GoogleLoginProcessor {private static final String V1_HOST_NAME = "content.googleapis.com";private static final String V1_URI = "/plus/v1/people/me";private static final String V3_HOST_NAME = "www.googleapis.com";private static final String V3_URI = "/oauth2/v3/tokeninfo";private static final Logger LOGGER = LogManager.getLogger(GoogleLoginProcessor.class);private static final int PORT_NUMBER = 443;private final ObjectMapper objectMapper = new ObjectMapper();@Autowiredprivate SocialUserRepository socialUserRepository;@Autowiredprivate UserRepository userRepository;@Autowiredprivate AuthService authService;@Autowiredcom.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;@Autowiredprivate AuthRepository authRepository;@Autowiredprivate UserRoleRepository userRoleRepository;@Autowiredprivate PromoterRepository promoterRepository;@Autowiredprivate UserAccountRepository userAccountRepository;@Autowiredprivate FofoStoreRepository fofoStoreRepository;@Autowiredprivate CsService csService;@Autowiredprivate RestClient restClient;@Autowiredprivate RetailerService retailerService;@Autowiredprivate PincodePartnerRepository pincodePartnerRepository;@AutowiredJWTUtil jwtUtil;public String process(String token) throws ProfitMandiBusinessException {Map<String, String> params = new HashMap<>();params.put(ProfitMandiConstants.ID_TOKEN, token);Map<String, String> headers = new HashMap<>();headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);String responseString = null;try {responseString = restClient.get(SchemeType.HTTPS, V3_HOST_NAME, PORT_NUMBER, V3_URI, params, headers);} catch (HttpHostConnectException e) {// TODO Auto-generated catch blocke.printStackTrace();}try {JsonNode rootNode = objectMapper.readTree(responseString);String email = rootNode.get("email").asText();return email;} catch (JsonProcessingException jsonProcessingException) {throw new ProfitMandiBusinessException("", "", "VE_1001");}}public Map<String, Object> processStore(String storeCode) throws ProfitMandiBusinessException {Map<String, Object> responseMap = new HashMap<>();int retailerId = retailerService.getStoreCodeRetailerMap().get(storeCode);int userId = userAccountRepository.selectUserIdByRetailerId(retailerId);List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(userId);PincodePartner partnerPin = pincodePartnerRepository.selectPinCodeByPartnerId(retailerId);String[] roleTypes = new String[roleIds.size()];int index = 0;for (int roleId : roleIds) {roleTypes[index++] = String.valueOf(roleId);}responseMap.put(ProfitMandiConstants.TOKEN, jwtUtil.create(userId, retailerId, roleTypes));responseMap.put(ProfitMandiConstants.REGISTERED, true);responseMap.put(ProfitMandiConstants.PIN_CODE, partnerPin != null ? partnerPin.getPincode() : partnerPin);return responseMap;}}