Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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();
21583 ashik.ali 21
		String fofoIdFound = null, emailIdFound = null;
22
		for(Cookie cookie : cookies){
23
			if(cookie.getName().equals(ProfitMandiConstants.FOFO_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
24
				fofoIdFound = cookie.getValue();
25
			}
26
			if(cookie.getName().equals(ProfitMandiConstants.FOFO_ID) && cookie.getValue() != null && !cookie.getValue().isEmpty()){
27
				emailIdFound = cookie.getValue();
28
			}
29
			if(fofoIdFound != null && emailIdFound != null){
30
				break;
31
			}
32
		}
33
 
34
		if(fofoIdFound == null || emailIdFound == null){
21577 ashik.ali 35
			LOGGER.error("Requested session is not valid");
36
			throw new ProfitMandiBusinessException("", "", "");
37
		}else{
38
			FofoDetails fofoDetails = new FofoDetails();
21583 ashik.ali 39
			fofoDetails.setFofoId(Integer.parseInt(fofoIdFound));
40
			fofoDetails.setEmailId(emailIdFound);
21577 ashik.ali 41
			return fofoDetails;
42
		}
21583 ashik.ali 43
 
21577 ashik.ali 44
	}
45
}