| Line 209... |
Line 209... |
| 209 |
// LOGGER.error("IO Exception occurred while parsing json String");
|
209 |
// LOGGER.error("IO Exception occurred while parsing json String");
|
| 210 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
210 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
| 211 |
}
|
211 |
}
|
| 212 |
}
|
212 |
}
|
| 213 |
|
213 |
|
| 214 |
public Map<String, Object> getFofoDetail(String token) throws ProfitMandiBusinessException {
|
214 |
public Map<String, Object> process(String token) throws ProfitMandiBusinessException {
|
| 215 |
Map<String, String> params = new HashMap<>();
|
215 |
Map<String, String> params = new HashMap<>();
|
| 216 |
params.put(ProfitMandiConstants.ID_TOKEN, token);
|
216 |
params.put(ProfitMandiConstants.ID_TOKEN, token);
|
| 217 |
Map<String, String> headers = new HashMap<>(1);
|
217 |
Map<String, String> headers = new HashMap<>(1);
|
| 218 |
headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
218 |
headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
|
| 219 |
String responseString = null;
|
219 |
String responseString = null;
|
| Line 223... |
Line 223... |
| 223 |
// TODO Auto-generated catch block
|
223 |
// TODO Auto-generated catch block
|
| 224 |
e.printStackTrace();
|
224 |
e.printStackTrace();
|
| 225 |
}
|
225 |
}
|
| 226 |
try {
|
226 |
try {
|
| 227 |
JsonNode rootNode = objectMapper.readTree(responseString);
|
227 |
JsonNode rootNode = objectMapper.readTree(responseString);
|
| - |
|
228 |
String email = rootNode.get("email").asText();
|
| - |
|
229 |
|
| - |
|
230 |
String name = authService.getNameByEmailId(email);
|
| - |
|
231 |
|
| - |
|
232 |
Map<String, Object> responseMap = new HashMap<>(2);
|
| - |
|
233 |
LOGGER.info("User Name from getNameByEmailId({}) is {}", email, name);
|
| - |
|
234 |
if (name != null) {
|
| - |
|
235 |
User registeredUser = null;
|
| - |
|
236 |
AuthUser authUser = authRepository.selectByGmailId(email);
|
| - |
|
237 |
|
| - |
|
238 |
if (authRepository.selectByGmailId(email) != null) {
|
| - |
|
239 |
registeredUser = userRepository.selectByEmailId(authUser.getEmailId());
|
| - |
|
240 |
} else if (promoterRepository.isExistByEmailId(email)) {
|
| - |
|
241 |
Promoter promoter = promoterRepository.selectByEmailId(email);
|
| - |
|
242 |
int userId = userAccountRepository.selectUserIdByRetailerId(promoter.getRetailerId());
|
| - |
|
243 |
registeredUser = userRepository.selectById(userId);
|
| - |
|
244 |
} else if (userRepository.isExistBySecondryEmailId(email)) {
|
| - |
|
245 |
registeredUser = userRepository.selectBySecondryEmailId(email);
|
| - |
|
246 |
}
|
| - |
|
247 |
LOGGER.info("4");
|
| - |
|
248 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(registeredUser.getId());
|
| - |
|
249 |
String[] roleTypes = new String[roleIds.size()];
|
| - |
|
250 |
int index = 0;
|
| - |
|
251 |
for (int roleId : roleIds) {
|
| - |
|
252 |
roleTypes[index++] = String.valueOf(roleId);
|
| - |
|
253 |
}
|
| - |
|
254 |
int retailerId;
|
| - |
|
255 |
try {
|
| - |
|
256 |
retailerId = userAccountRepository.selectRetailerIdByUserId(registeredUser.getId());
|
| - |
|
257 |
} catch (Exception e) {
|
| - |
|
258 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectByEmailId(Utils.SYSTEM_PARTNER);
|
| - |
|
259 |
retailerId = user.getId();
|
| - |
|
260 |
}
|
| - |
|
261 |
responseMap.put(ProfitMandiConstants.TOKEN,
|
| - |
|
262 |
JWTUtil.create(email, registeredUser.getId(), retailerId, roleTypes));
|
| - |
|
263 |
LOGGER.info(
|
| - |
|
264 |
"Param value for email, registeredUser.getId(), retailerId, roleTypes are {}, {}, {} and {}",
|
| - |
|
265 |
email, registeredUser.getId(), retailerId, Arrays.asList(roleTypes));
|
| - |
|
266 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
| - |
|
267 |
return responseMap;
|
| - |
|
268 |
}
|
| - |
|
269 |
|
| 228 |
User user = null;
|
270 |
User user = null;
|
| 229 |
try {
|
271 |
try {
|
| 230 |
user = userRepository.selectByEmailId(rootNode.get("email").asText());
|
272 |
user = userRepository.selectByEmailId(email);
|
| 231 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
273 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 232 |
|
274 |
|
| 233 |
}
|
275 |
}
|
| 234 |
if (user == null) {
|
276 |
if (user == null) {
|
| - |
|
277 |
try {
|
| 235 |
user = userRepository.selectBySecondryEmailId(rootNode.get("email").asText());
|
278 |
user = userRepository.selectByEmailId(email);
|
| - |
|
279 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| - |
|
280 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(email));
|
| - |
|
281 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
| 236 |
}
|
282 |
}
|
| 237 |
if (user != null) {
|
283 |
} else {
|
| - |
|
284 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
| - |
|
285 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| 238 |
Map<String, Object> responseMap = new HashMap<>(2);
|
286 |
String[] roleTypes = new String[roleIds.size()];
|
| - |
|
287 |
int index = 0;
|
| - |
|
288 |
for (int roleId : roleIds) {
|
| 239 |
responseMap.put(ProfitMandiConstants.FOFO_ID, user.getId());
|
289 |
roleTypes[index++] = String.valueOf(roleId);
|
| - |
|
290 |
}
|
| 240 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
291 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), retailerId, roleTypes));
|
| 241 |
return responseMap;
|
292 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
| 242 |
}
|
293 |
}
|
| 243 |
|
294 |
|
| - |
|
295 |
return responseMap;
|
| - |
|
296 |
|
| 244 |
} catch (JsonProcessingException jsonProcessingException) {
|
297 |
} catch (JsonProcessingException jsonProcessingException) {
|
| 245 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
298 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
| 246 |
} catch (IOException ioException) {
|
299 |
} catch (IOException ioException) {
|
| 247 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
300 |
throw new ProfitMandiBusinessException("", "", "VE_1001");
|
| 248 |
}
|
301 |
}
|