| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.processor;
|
1 |
package com.spice.profitmandi.web.processor;
|
| 2 |
|
2 |
|
| 3 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| 4 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| 5 |
import java.util.HashMap;
|
5 |
import java.util.HashMap;
|
| 6 |
import java.util.HashSet;
|
- |
|
| 7 |
import java.util.Iterator;
|
6 |
import java.util.Iterator;
|
| - |
|
7 |
import java.util.List;
|
| 8 |
import java.util.Map;
|
8 |
import java.util.Map;
|
| 9 |
import java.util.Set;
|
- |
|
| 10 |
|
9 |
|
| 11 |
import org.springframework.beans.factory.annotation.Autowired;
|
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 12 |
import org.springframework.stereotype.Component;
|
11 |
import org.springframework.stereotype.Component;
|
| 13 |
|
12 |
|
| 14 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
13 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
| Line 17... |
Line 16... |
| 17 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
16 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
17 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 19 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
18 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 20 |
import com.spice.profitmandi.common.util.JWTUtil;
|
19 |
import com.spice.profitmandi.common.util.JWTUtil;
|
| 21 |
import com.spice.profitmandi.common.web.client.RestClient;
|
20 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 22 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
- |
|
| 23 |
import com.spice.profitmandi.dao.entity.dtr.SocialUser;
|
21 |
import com.spice.profitmandi.dao.entity.dtr.SocialUser;
|
| 24 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
22 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| - |
|
23 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| 25 |
import com.spice.profitmandi.dao.enumuration.dtr.Gender;
|
24 |
import com.spice.profitmandi.dao.enumuration.dtr.Gender;
|
| 26 |
import com.spice.profitmandi.dao.enumuration.dtr.SocialType;
|
25 |
import com.spice.profitmandi.dao.enumuration.dtr.SocialType;
|
| 27 |
import com.spice.profitmandi.dao.repository.dtr.SocialUserRepository;
|
26 |
import com.spice.profitmandi.dao.repository.dtr.SocialUserRepository;
|
| 28 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
27 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| - |
|
28 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| - |
|
29 |
|
| 29 |
|
30 |
|
| 30 |
@Component
|
31 |
@Component
|
| 31 |
public class GoogleLoginProcessor {
|
32 |
public class GoogleLoginProcessor {
|
| 32 |
|
33 |
|
| 33 |
private static final String V1_HOST_NAME = "content.googleapis.com";
|
34 |
private static final String V1_HOST_NAME = "content.googleapis.com";
|
| Line 41... |
Line 42... |
| 41 |
SocialUserRepository socialUserRepository;
|
42 |
SocialUserRepository socialUserRepository;
|
| 42 |
|
43 |
|
| 43 |
@Autowired
|
44 |
@Autowired
|
| 44 |
UserRepository userRepository;
|
45 |
UserRepository userRepository;
|
| 45 |
|
46 |
|
| - |
|
47 |
@Autowired
|
| - |
|
48 |
UserRoleRepository userRoleRepository;
|
| - |
|
49 |
|
| 46 |
public Map<String, Object> process(Map<String, Object> map) throws ProfitMandiBusinessException{
|
50 |
public Map<String, Object> process(Map<String, Object> map) throws ProfitMandiBusinessException{
|
| 47 |
RestClient restClient = new RestClient(SchemeType.HTTPS, V1_HOST_NAME, PORT_NUMBER);
|
51 |
RestClient restClient = new RestClient(SchemeType.HTTPS, V1_HOST_NAME, PORT_NUMBER);
|
| 48 |
Map<String, String> params = new HashMap<>();
|
52 |
Map<String, String> params = new HashMap<>();
|
| 49 |
params.put(ProfitMandiConstants.ACCESS_TOKEN, map.get(ProfitMandiConstants.TOKEN).toString());
|
53 |
params.put(ProfitMandiConstants.ACCESS_TOKEN, map.get(ProfitMandiConstants.TOKEN).toString());
|
| 50 |
String responseString = restClient.get(V1_URI, params);
|
54 |
String responseString = restClient.get(V1_URI, params);
|
| Line 85... |
Line 89... |
| 85 |
socialUserRepository.persist(socialUser);
|
89 |
socialUserRepository.persist(socialUser);
|
| 86 |
Map<String, Object> responseMap = new HashMap<>(2);
|
90 |
Map<String, Object> responseMap = new HashMap<>(2);
|
| 87 |
try{
|
91 |
try{
|
| 88 |
User user = userRepository.selectByEmailId(socialUser.getEmailId());
|
92 |
User user = userRepository.selectByEmailId(socialUser.getEmailId());
|
| 89 |
//Set<Role> roles = user.getRoles();
|
93 |
//Set<Role> roles = user.getRoles();
|
| - |
|
94 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
| 90 |
Set<Role> roles = new HashSet<>();
|
95 |
//Set<Role> roles = new HashSet<>();
|
| 91 |
String[] roleNames = new String[roles.size()];
|
96 |
String[] roleTypes = new String[userRoles.size()];
|
| 92 |
int index = 0;
|
97 |
int index = 0;
|
| 93 |
for(Role role : roles){
|
98 |
for (UserRole userRole : userRoles) {
|
| 94 |
roleNames[index++] = role.getName();
|
99 |
roleTypes[index++] = userRole.getRoleType().toString();
|
| 95 |
}
|
100 |
}
|
| 96 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), roleNames));
|
101 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), roleTypes));
|
| 97 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
102 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
| 98 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
103 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 99 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(socialUser.getEmailId()));
|
104 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(socialUser.getEmailId()));
|
| 100 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
105 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
| 101 |
}
|
106 |
}
|