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