package de.thomasjacob.improve.presentation;

import de.thomasjacob.improve.logic.user.User;
import de.thomasjacob.improve.presentation.login.LoginManager;
import de.thomasjacob.webcore.TechnicalException;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionMapping;


public class NavigationFiller
{
	private static NavigationFiller singleton;

	private NavigationFiller()
	{
	}

	public static synchronized NavigationFiller getInstance()
	{
		if (singleton == null)
		{
			singleton = new NavigationFiller();
		}

		return singleton;
	}

	public void fill(ActionMapping mapping, HttpServletRequest request, HttpSession session) throws TechnicalException
	{
		Map editAccountParameters = new HashMap();
		editAccountParameters.put("userId", new Integer(LoginManager.getInstance(session).getUser().getId()));
		request.setAttribute("editAccountParameters", editAccountParameters);

		User user = LoginManager.getInstance(session).getUser();
		request.setAttribute("administrator", new Boolean(user.isAdministrator()));
		request.setAttribute("developer", new Boolean(user.isDeveloper()));
		request.setAttribute("manager", new Boolean(user.isManager()));
		request.setAttribute("reporter", new Boolean(user.isReporter()));
		request.setAttribute("guest", new Boolean(user.isGuest()));
	}
}