Subversion Repositories SmartDukaan

Rev

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

Rev 25384 Rev 25388
Line 38... Line 38...
38
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
38
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
39
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
39
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
40
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
40
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
41
import com.spice.profitmandi.service.AuthService;
41
import com.spice.profitmandi.service.AuthService;
42
 
42
 
43
 
-
 
44
@Component
43
@Component
45
public class GoogleLoginProcessor {
44
public class GoogleLoginProcessor {
46
 
45
 
47
	private static final String V1_HOST_NAME = "content.googleapis.com";
46
	private static final String V1_HOST_NAME = "content.googleapis.com";
48
	private static final String V1_URI = "/plus/v1/people/me";
47
	private static final String V1_URI = "/plus/v1/people/me";
Line 58... Line 57...
58
	@Autowired
57
	@Autowired
59
	private UserRepository userRepository;
58
	private UserRepository userRepository;
60
 
59
 
61
	@Autowired
60
	@Autowired
62
	private AuthService authService;
61
	private AuthService authService;
-
 
62
 
-
 
63
	@Autowired
-
 
64
	com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
63
	
65
 
64
	@Autowired
66
	@Autowired
65
	private AuthRepository authRepository;
67
	private AuthRepository authRepository;
66
	
68
 
67
	@Autowired
69
	@Autowired
68
	private UserRoleRepository userRoleRepository;
70
	private UserRoleRepository userRoleRepository;
69
 
71
 
70
	@Autowired
72
	@Autowired
71
	private PromoterRepository promoterRepository;
73
	private PromoterRepository promoterRepository;
Line 73... Line 75...
73
	@Autowired
75
	@Autowired
74
	private UserAccountRepository userAccountRepository;
76
	private UserAccountRepository userAccountRepository;
75
 
77
 
76
	@Autowired
78
	@Autowired
77
	private RestClient restClient;
79
	private RestClient restClient;
78
	
-
 
79
	
80
 
80
	public Map<String, Object> process(GoogleLoginRequest googleLoginRequest) throws ProfitMandiBusinessException {
81
	public Map<String, Object> process(GoogleLoginRequest googleLoginRequest) throws ProfitMandiBusinessException {
81
		LOGGER.info("1");
82
		LOGGER.info("1");
82
		Map<String, String> params = new HashMap<>();
83
		Map<String, String> params = new HashMap<>();
83
		params.put(ProfitMandiConstants.ACCESS_TOKEN, googleLoginRequest.getToken());
84
		params.put(ProfitMandiConstants.ACCESS_TOKEN, googleLoginRequest.getToken());
84
		Map<String, String> headers = new HashMap<>(1);
85
		Map<String, String> headers = new HashMap<>(1);
Line 97... Line 98...
97
				if (emails.isArray()) {
98
				if (emails.isArray()) {
98
					Iterator<JsonNode> emailsIterator = emails.elements();
99
					Iterator<JsonNode> emailsIterator = emails.elements();
99
					if (emailsIterator.hasNext()) {
100
					if (emailsIterator.hasNext()) {
100
						JsonNode email = emailsIterator.next();
101
						JsonNode email = emailsIterator.next();
101
						if (email.has("value")) {
102
						if (email.has("value")) {
102
							if(ProfitMandiConstants.BLOCKED_EMAILS.contains(email.get("value").asText())) {
103
							if (ProfitMandiConstants.BLOCKED_EMAILS.contains(email.get("value").asText())) {
103
								throw new ProfitMandiBusinessException("User Account", email.get("value").asText(), "User is temporarily suspended.");
104
								throw new ProfitMandiBusinessException("User Account", email.get("value").asText(),
-
 
105
										"User is temporarily suspended.");
104
							}
106
							}
105
							socialUser.setEmailId(email.get("value").asText());
107
							socialUser.setEmailId(email.get("value").asText());
106
						}
108
						}
107
					}
109
					}
108
				}
110
				}
Line 134... Line 136...
134
			Map<String, Object> responseMap = new HashMap<>(2);
136
			Map<String, Object> responseMap = new HashMap<>(2);
135
 
137
 
136
			LOGGER.info("3");
138
			LOGGER.info("3");
137
			String name = authService.getNameByEmailId(socialUser.getEmailId());
139
			String name = authService.getNameByEmailId(socialUser.getEmailId());
138
			LOGGER.info("User Name from getNameByEmailId({}) is {}", socialUser.getEmailId(), name);
140
			LOGGER.info("User Name from getNameByEmailId({}) is {}", socialUser.getEmailId(), name);
139
			if(name != null) {
141
			if (name != null) {
140
				User registeredUser = null;
142
				User registeredUser = null;
141
				AuthUser authUser = authRepository.selectByGmailId(socialUser.getEmailId());
143
				AuthUser authUser = authRepository.selectByGmailId(socialUser.getEmailId());
142
				
144
 
143
				if(authRepository.selectByGmailId(socialUser.getEmailId())!=null) {
145
				if (authRepository.selectByGmailId(socialUser.getEmailId()) != null) {
144
					registeredUser = userRepository.selectByEmailId(authUser.getEmailId());
146
					registeredUser = userRepository.selectByEmailId(authUser.getEmailId());
145
				} else if(promoterRepository.isExistByEmailId(socialUser.getEmailId())) {
147
				} else if (promoterRepository.isExistByEmailId(socialUser.getEmailId())) {
146
					Promoter promoter = promoterRepository.selectByEmailId(socialUser.getEmailId());
148
					Promoter promoter = promoterRepository.selectByEmailId(socialUser.getEmailId());
147
					int userId = userAccountRepository.selectUserIdByRetailerId(promoter.getRetailerId());
149
					int userId = userAccountRepository.selectUserIdByRetailerId(promoter.getRetailerId());
148
					registeredUser = userRepository.selectById(userId);
150
					registeredUser = userRepository.selectById(userId);
149
				} else if(userRepository.isExistBySecondryEmailId(socialUser.getEmailId())) {
151
				} else if (userRepository.isExistBySecondryEmailId(socialUser.getEmailId())) {
150
					registeredUser = userRepository.selectBySecondryEmailId(socialUser.getEmailId());
152
					registeredUser = userRepository.selectBySecondryEmailId(socialUser.getEmailId());
151
				}
153
				}
152
				LOGGER.info("4");
154
				LOGGER.info("4");
153
				List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(registeredUser.getId());
155
				List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(registeredUser.getId());
154
				String[] roleTypes = new String[roleIds.size()];
156
				String[] roleTypes = new String[roleIds.size()];
155
				int index = 0;
157
				int index = 0;
156
				for (int roleId : roleIds) {
158
				for (int roleId : roleIds) {
157
					roleTypes[index++] = String.valueOf(roleId);
159
					roleTypes[index++] = String.valueOf(roleId);
158
				}
160
				}
-
 
161
				int retailerId;
-
 
162
				try {
159
				int retailerId = userAccountRepository.selectRetailerIdByUserId(registeredUser.getId());
163
					retailerId = userAccountRepository.selectRetailerIdByUserId(registeredUser.getId());
-
 
164
				} catch (Exception e) {
-
 
165
					com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectByEmailId(Utils.SYSTEM_PARTNER);
-
 
166
					retailerId = user.getId();
-
 
167
				}
-
 
168
				responseMap.put(ProfitMandiConstants.TOKEN,
160
				responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(socialUser.getEmailId(), registeredUser.getId(), retailerId, roleTypes));
169
						JWTUtil.create(socialUser.getEmailId(), registeredUser.getId(), retailerId, roleTypes));
-
 
170
				LOGGER.info(
161
						LOGGER.info("Param value for socialUser.getEmailId(), registeredUser.getId(), retailerId, roleTypes are {}, {}, {} and {}", socialUser.getEmailId(), registeredUser.getId(), retailerId, Arrays.asList(roleTypes));
171
						"Param value for socialUser.getEmailId(), registeredUser.getId(), retailerId, roleTypes are {}, {}, {} and {}",
-
 
172
						socialUser.getEmailId(), registeredUser.getId(), retailerId, Arrays.asList(roleTypes));
162
				responseMap.put(ProfitMandiConstants.REGISTERED, true);
173
				responseMap.put(ProfitMandiConstants.REGISTERED, true);
163
				return responseMap;
174
				return responseMap;
164
			}
175
			}
165
			
176
 
166
			User user = null;
177
			User user = null;
167
			try {
178
			try {
168
				user = userRepository.selectByEmailId(socialUser.getEmailId());
179
				user = userRepository.selectByEmailId(socialUser.getEmailId());
169
			} catch (ProfitMandiBusinessException profitMandiBusinessException) {
180
			} catch (ProfitMandiBusinessException profitMandiBusinessException) {
170
 
181