| 21577 |
ashik.ali |
1 |
package com.spice.profitmandi.web.util;
|
|
|
2 |
|
|
|
3 |
import javax.servlet.http.Cookie;
|
|
|
4 |
import javax.servlet.http.HttpServletRequest;
|
|
|
5 |
|
|
|
6 |
import org.slf4j.Logger;
|
|
|
7 |
import org.slf4j.LoggerFactory;
|
|
|
8 |
import org.springframework.stereotype.Component;
|
|
|
9 |
|
|
|
10 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
11 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
12 |
import com.spice.profitmandi.web.model.FofoDetails;
|
|
|
13 |
|
|
|
14 |
@Component
|
|
|
15 |
public class CookiesFetcher {
|
|
|
16 |
|
|
|
17 |
private static final Logger LOGGER = LoggerFactory.getLogger(CookiesFetcher.class);
|
|
|
18 |
|
|
|
19 |
public FofoDetails getCookiesObject(HttpServletRequest request) throws ProfitMandiBusinessException{
|
|
|
20 |
Cookie[] cookies = request.getCookies();
|
| 21626 |
kshitij.so |
21 |
if (cookies == null){
|
| 21598 |
ashik.ali |
22 |
throw new ProfitMandiBusinessException("", "", "");
|
|
|
23 |
}
|
| 21583 |
ashik.ali |
24 |
String fofoIdFound = null, emailIdFound = null;
|
|
|
25 |
for(Cookie cookie : cookies){
|
|
|
26 |
if(cookie.getName().equals(ProfitMandiConstants.FOFO_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
|
|
|
27 |
fofoIdFound = cookie.getValue();
|
|
|
28 |
}
|
| 21626 |
kshitij.so |
29 |
if(cookie.getName().equals(ProfitMandiConstants.EMAIL_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
|
| 21583 |
ashik.ali |
30 |
emailIdFound = cookie.getValue();
|
|
|
31 |
}
|
|
|
32 |
if(fofoIdFound != null && emailIdFound != null){
|
|
|
33 |
break;
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
if(fofoIdFound == null || emailIdFound == null){
|
| 21577 |
ashik.ali |
38 |
LOGGER.error("Requested session is not valid");
|
|
|
39 |
throw new ProfitMandiBusinessException("", "", "");
|
|
|
40 |
}else{
|
|
|
41 |
FofoDetails fofoDetails = new FofoDetails();
|
| 21583 |
ashik.ali |
42 |
fofoDetails.setFofoId(Integer.parseInt(fofoIdFound));
|
|
|
43 |
fofoDetails.setEmailId(emailIdFound);
|
| 21577 |
ashik.ali |
44 |
return fofoDetails;
|
|
|
45 |
}
|
| 21583 |
ashik.ali |
46 |
|
| 21577 |
ashik.ali |
47 |
}
|
|
|
48 |
}
|