// Generated by the WOLips Templateengine Plug-in at Apr 10, 2009 5:30:01 PM
package mildo.wiwo;

import mildo.wiwo.data.WiwoUser;
import mildo.wiwo.persistence.PersistHelper;
import mildo.wiwo.search.SearchHelper;
import mildo.wiwo.user.SessionWithUser;
import mildo.wiwo.user.UserManager;
import mildo.wiwo.user.UserRoleDefs;

import com.webobjects.appserver.WOSession;

public class Session 
	extends WOSession 
	implements SessionWithUser, UserRoleDefs
{
	private static final long serialVersionUID = 1L;

	public Session() {
		initHelpers();
		initManagers();
	}
	
	protected void initHelpers() {
		persistHelper = new PersistHelper(defaultEditingContext());
		searchHelper = new SearchHelper(persistHelper);
	}
	
	protected void initManagers() {
		userManager = new UserManager(defaultEditingContext());
	}

	// -----------
	
	private WiwoUser actualSessionUser;
	
	public WiwoUser getActualSessionUser() {
		return actualSessionUser;
	}

	public boolean isActualSessionUserLoggedIn() {
		return actualSessionUser != null;
	}

	public void setActualSessionUser(WiwoUser aValue) {
		actualSessionUser = aValue;
	}
	
	// --------------
	
	public boolean isMasterLoggedIn() {
		return (actualSessionUser != null && actualSessionUser.conformsToRole(MASTER));
	}
	
	public boolean isAdminLoggedIn() {
		return (actualSessionUser != null && actualSessionUser.conformsToRole(ADMIN));
	}
	
	public boolean isEditorLoggedIn() {
		return (actualSessionUser != null && actualSessionUser.conformsToRole(EDITOR));
	}
	
	// ----------
	
	private UserManager userManager;
	
	public UserManager getManager() {
		return userManager;
	}
	
	// ----------
	
	private SearchHelper searchHelper;
	
	public SearchHelper getSearchHelper() {
		return searchHelper;
	}
	
	// -----------
	
	private PersistHelper persistHelper;
	
	public PersistHelper getPersistHelper() {
		return persistHelper;
	}
	
	// ------------
	
}
