Subversion Repositories SmartDukaan

Rev

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

Rev 23786 Rev 23860
Line 4... Line 4...
4
import java.time.LocalDateTime;
4
import java.time.LocalDateTime;
5
import java.util.HashMap;
5
import java.util.HashMap;
6
import java.util.Iterator;
6
import java.util.Iterator;
7
import java.util.List;
7
import java.util.List;
8
import java.util.Map;
8
import java.util.Map;
9
import java.util.logging.Logger;
-
 
10
 
9
 
11
import org.apache.http.conn.HttpHostConnectException;
10
import org.apache.http.conn.HttpHostConnectException;
12
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.http.HttpHeaders;
12
import org.springframework.http.HttpHeaders;
14
import org.springframework.http.MediaType;
13
import org.springframework.http.MediaType;
Line 23... Line 22...
23
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22
import com.spice.profitmandi.common.model.ProfitMandiConstants;
24
import com.spice.profitmandi.common.util.JWTUtil;
23
import com.spice.profitmandi.common.util.JWTUtil;
25
import com.spice.profitmandi.common.web.client.RestClient;
24
import com.spice.profitmandi.common.web.client.RestClient;
26
import com.spice.profitmandi.dao.entity.dtr.SocialUser;
25
import com.spice.profitmandi.dao.entity.dtr.SocialUser;
27
import com.spice.profitmandi.dao.entity.dtr.User;
26
import com.spice.profitmandi.dao.entity.dtr.User;
28
import com.spice.profitmandi.dao.entity.dtr.UserRole;
-
 
29
import com.spice.profitmandi.dao.enumuration.dtr.Gender;
27
import com.spice.profitmandi.dao.enumuration.dtr.Gender;
30
import com.spice.profitmandi.dao.enumuration.dtr.SocialType;
28
import com.spice.profitmandi.dao.enumuration.dtr.SocialType;
31
import com.spice.profitmandi.dao.repository.dtr.SocialUserRepository;
29
import com.spice.profitmandi.dao.repository.dtr.SocialUserRepository;
-
 
30
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
32
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
31
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
33
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
32
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
34
 
33
 
35
 
34
 
36
@Component
35
@Component
Line 50... Line 49...
50
	private UserRepository userRepository;
49
	private UserRepository userRepository;
51
	
50
	
52
	@Autowired
51
	@Autowired
53
	private UserRoleRepository userRoleRepository;
52
	private UserRoleRepository userRoleRepository;
54
	
53
	
-
 
54
	@Autowired
-
 
55
	private UserAccountRepository userAccountRepository;
-
 
56
	
-
 
57
	@Autowired
-
 
58
	private RestClient restClient;
-
 
59
	
55
	public Map<String, Object> process(GoogleLoginRequest googleLoginRequest) throws ProfitMandiBusinessException{
60
	public Map<String, Object> process(GoogleLoginRequest googleLoginRequest) throws ProfitMandiBusinessException{
56
		RestClient restClient = new RestClient();
-
 
57
		Map<String, String> params = new HashMap<>();
61
		Map<String, String> params = new HashMap<>();
58
		params.put(ProfitMandiConstants.ACCESS_TOKEN, googleLoginRequest.getToken());
62
		params.put(ProfitMandiConstants.ACCESS_TOKEN, googleLoginRequest.getToken());
59
		Map<String, String> headers = new HashMap<>(1);
63
		Map<String, String> headers = new HashMap<>(1);
60
		headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
64
		headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
61
		String responseString; 
65
		String responseString = null;
62
		try {
66
		try {
63
			responseString = restClient.get(SchemeType.HTTPS, V1_HOST_NAME, PORT_NUMBER, V1_URI, params, headers);
67
			responseString = restClient.get(SchemeType.HTTPS, V1_HOST_NAME, PORT_NUMBER, V1_URI, params, headers);
64
		} catch (HttpHostConnectException e) {
68
		} catch (HttpHostConnectException e) {
65
			throw new ProfitMandiBusinessException("", "", "Could not connect to remote host");
69
			throw new ProfitMandiBusinessException("", "", "Could not connect to remote host");
66
		}
70
		}
Line 116... Line 120...
116
					responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(socialUser.getEmailId()));
120
					responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(socialUser.getEmailId()));
117
					responseMap.put(ProfitMandiConstants.REGISTERED, false);
121
					responseMap.put(ProfitMandiConstants.REGISTERED, false);
118
				}
122
				}
119
			}
123
			}
120
			if(user != null){
124
			if(user != null){
-
 
125
				//Set<Role> roles = user.getRoles();
121
				List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
126
				List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
-
 
127
				int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
-
 
128
				//Set<Role> roles = new HashSet<>();
122
				String[] roleIds = new String[userRoles.size()];
129
				String[] roleTypes = new String[roleIds.size()];
123
				int index = 0;
130
				int index = 0;
124
				for (UserRole userRole : userRoles) {
131
				for (int roleId : roleIds) {
125
					roleIds[index++] = String.valueOf(userRole.getRoleId());
132
					roleTypes[index++] = String.valueOf(roleId);
126
				}
133
				}
127
				responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), roleIds));
134
				responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), retailerId, roleTypes));
128
				responseMap.put(ProfitMandiConstants.REGISTERED, true);
135
				responseMap.put(ProfitMandiConstants.REGISTERED, true);
129
			}
136
			}
130
			
137
			
131
			return responseMap;
138
			return responseMap;
132
		}catch (JsonProcessingException jsonProcessingException) {
139
		}catch (JsonProcessingException jsonProcessingException) {
Line 137... Line 144...
137
			throw new ProfitMandiBusinessException("", "", "VE_1001");
144
			throw new ProfitMandiBusinessException("", "", "VE_1001");
138
		}
145
		}
139
	}
146
	}
140
	
147
	
141
	public Map<String, Object> getFofoDetail(String token) throws ProfitMandiBusinessException{
148
	public Map<String, Object> getFofoDetail(String token) throws ProfitMandiBusinessException{
142
		RestClient restClient = new RestClient();
-
 
143
		Map<String, String> params = new HashMap<>();
149
		Map<String, String> params = new HashMap<>();
144
		params.put(ProfitMandiConstants.ID_TOKEN, token);
150
		params.put(ProfitMandiConstants.ID_TOKEN, token);
145
		Map<String, String> headers = new HashMap<>(1);
151
		Map<String, String> headers = new HashMap<>(1);
146
		headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
152
		headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
147
		String responseString;
153
		String responseString = null;
148
		try {
154
		try {
149
			responseString = restClient.get(SchemeType.HTTPS, V3_HOST_NAME, PORT_NUMBER, V3_URI, params, headers);
155
			responseString = restClient.get(SchemeType.HTTPS, V3_HOST_NAME, PORT_NUMBER, V3_URI, params, headers);
150
		} catch(HttpHostConnectException e) {
156
		} catch (HttpHostConnectException e) {
151
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
157
			// TODO Auto-generated catch block
-
 
158
			e.printStackTrace();
152
		}
159
		}
153
		
-
 
154
		try {
160
		try {
155
			JsonNode rootNode = objectMapper.readTree(responseString);
161
			JsonNode rootNode = objectMapper.readTree(responseString);
156
			User user = null;
162
			User user = null;
157
			try{
163
			try{
158
				user = userRepository.selectByEmailId(rootNode.get("email").asText());
164
				user = userRepository.selectByEmailId(rootNode.get("email").asText());