//===========================================================================
// package
//===========================================================================
package jp.gr.java_conf.bugslife.action;

//===========================================================================
// import
//===========================================================================
import java.io.IOException;
import java.util.Locale;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.logging.*;
import org.apache.struts.action.*;
import org.apache.struts.util.*;
import org.apache.commons.beanutils.*;

import java.util.*;
import jp.gr.java_conf.bugslife.selections.*;
import jp.gr.java_conf.bugslife.user.*;
import jp.gr.java_conf.bugslife.bug.*;
import jp.gr.java_conf.bugslife.form.*;
/**
 *<PRE>
 * 
 * SessionControlクラス
 *
 *</PRE>
 * @version	0.0
 * @author	鰐川 正寛
 */
public final class SessionControl
{
//===========================================================================
// attributes
//===========================================================================
	/**
	 * Log
	 */
	private Log log = LogFactory.getLog(this.getClass().getName());
//===========================================================================
// methods
//===========================================================================
	/**
	 * セッションに区分をセット
	 */
	public static void initSession(HttpSession session, UserInfo logonUser) {
		//appVersions
		Collection appVersions = (Collection)session.getAttribute("appVersions");
		if (appVersions == null) {
			appVersions = AppVersion.getLabelCollection();
			session.setAttribute("appVersions", appVersions);
		}
		
		//browsers
		Collection browsers = (Collection)session.getAttribute("browsers");
		if (browsers == null) {
			browsers = Browser.getLabelCollection();
			session.setAttribute("browsers", browsers);
		}
		
		//dbVersions
		Collection dbVersions = (Collection)session.getAttribute("dbVersions");
		if (dbVersions == null) {
			dbVersions = DbVersion.getLabelCollection();
			session.setAttribute("dbVersions", dbVersions);
		}
		
		//errorCauses
		Collection errorCauses = (Collection)session.getAttribute("errorCauses");
		if (errorCauses == null) {
			errorCauses = ErrorCause.getLabelCollection();
			session.setAttribute("errorCauses", errorCauses);
		}
		
		//errorDelayReasons
		Collection errorDelayReasons = (Collection)session.getAttribute("errorDelayReasons");
		if (errorDelayReasons == null) {
			errorDelayReasons = ErrorDelayReason.getLabelCollection();
			session.setAttribute("errorDelayReasons", errorDelayReasons);
		}
		
		//errorPoints
		Collection errorPoints = (Collection)session.getAttribute("errorPoints");
		if (errorPoints == null) {
			errorPoints = ErrorPoint.getLabelCollection();
			session.setAttribute("errorPoints", errorPoints);
		}
		
		//errorTypes
		Collection errorTypes = (Collection)session.getAttribute("errorTypes");
		if (errorTypes == null) {
			errorTypes = ErrorType.getLabelCollection();
			session.setAttribute("errorTypes", errorTypes);
		}
		
		//htmlVersions
		Collection htmlVersions = (Collection)session.getAttribute("htmlVersions");
		if (htmlVersions == null) {
			htmlVersions = HtmlVersion.getLabelCollection();
			session.setAttribute("htmlVersions", htmlVersions);
		}
		
		//specVersions
		Collection specVersions = (Collection)session.getAttribute("specVersions");
		if (specVersions == null) {
			specVersions = SpecVersion.getLabelCollection();
			session.setAttribute("specVersions", specVersions);
		}
		
		//locations
		Collection locations = (Collection)session.getAttribute("locations");
		if (locations == null) {
			locations = Location.getLabelCollection();
			session.setAttribute("locations", locations);
		}
		
		//milestones
		Collection milestones = (Collection)session.getAttribute("milestones");
		if (milestones == null) {
			milestones = Milestone.getLabelCollection();
			session.setAttribute("milestones", milestones);
		}
		
		//oss
		Collection oss = (Collection)session.getAttribute("oss");
		if (oss == null) {
			oss = Os.getLabelCollection();
			session.setAttribute("oss", oss);
		}
		
		//prioritys
		Collection prioritys = (Collection)session.getAttribute("prioritys");
		if (prioritys == null) {
			prioritys = Priority.getLabelCollection();
			session.setAttribute("prioritys", prioritys);
		}
		
		//processNames
		Collection processNames = (Collection)session.getAttribute("processNames");
		if (processNames == null) {
			processNames = ProcessName.getLabelCollection();
			session.setAttribute("processNames", processNames);
		}
		
		//resolutions
		Collection resolutions = (Collection)session.getAttribute("resolutions");
		if (resolutions == null) {
			resolutions = Resolution.getLabelCollection();
			session.setAttribute("resolutions", resolutions);
		}
		
		//severitys
		Collection severitys = (Collection)session.getAttribute("severitys");
		if (severitys == null) {
			severitys = Severity.getLabelCollection();
			session.setAttribute("severitys", severitys);
		}
		
		//subsystems
		Collection subsystems = (Collection)session.getAttribute("subsystems");
		if (subsystems == null) {
			subsystems = Subsystem.getLabelCollection();
			session.setAttribute("subsystems", subsystems);
		}
		
		//screen
		Collection screens = (Collection)session.getAttribute("screens");
		if (screens == null) {
			screens = Screen.getLabelCollection();
			session.setAttribute("screens", screens);
		}
		//functions
		Collection functions = (Collection)session.getAttribute("functions");
		if (functions == null) {
			functions = FunctionName.getLabelCollection();
			session.setAttribute("functions", functions);
		}
		//components
		Collection components = (Collection)session.getAttribute("components");
		if (components == null) {
			components = ComponentName.getLabelCollection();
			session.setAttribute("components", components);
		}
		//sysconf
		Sysconf sysconf = (Sysconf)session.getAttribute("sysconf");
		if (sysconf == null) {
			sysconf = Sysconf.getSysconf();
			session.setAttribute("sysconf", sysconf);
		}
		//status
		Collection statuses = (Collection)session.getAttribute("statuses");
		if (statuses == null) {
			statuses =Bug.getStatusCollection();
			session.setAttribute("statuses", statuses);
		}
		
		//dispatchList
		Collection dispatchList = (Collection)session.getAttribute("dispatchList");
		if (dispatchList == null) {
		    dispatchList = DispatchList.getEnableDispatchList(logonUser.getUno());
			session.setAttribute("dispatchList", dispatchList);
		}
		
		/*
		 * ユーザ情報のセット
		 */
		
		Collection allUsers = new ArrayList();
		Collection allUsers2 = new ArrayList();
		Iterator ite = null;
		
		
		Collection users = UserInfo.getAllUser();	//ユーザを取得
		//有効なユーザが１件もない場合
		if (users != null) {
			
			//alluserセット
			allUsers = users;					//ユーザをセット
			
			//allUser2セット
			allUsers2.add(new UserInfo());		//空のユーザを１番目に追加
			ite = users.iterator();
			while(ite.hasNext()) {
				allUsers2.add(ite.next());		//以降ユーザを追加
			}
		}
		session.setAttribute("allUsers", allUsers);
		session.setAttribute("allUsers2", allUsers2);
		
/*-------------- 権限ごとのユーザは使っていない
		//個別ユーザ
		Collection admins = new ArrayList();			//システム管理者
		Collection managers = new ArrayList();			//プロジェクトマネージャー
		Collection developers = new ArrayList();		//開発者
		Collection testers = new ArrayList();			//テスター
		Collection users = new ArrayList();				//ユーザ
		
		ite = allUsers.iterator();
		while(ite.hasNext()) {
			UserInfo user = (UserInfo)ite.next();
			if (user.isForgiven(UserInfo.SYSTEM_MANAGER)) {
				admins.add(user);
			}
			if (user.isForgiven(UserInfo.PROJECT_MANAGER)) {
				managers.add(user);
			}
			if (user.isForgiven(UserInfo.DEVELOPER)) {
				developers.add(user);
			}
			if (user.isForgiven(UserInfo.TESTER)) {
				testers.add(user);
			}
			if (user.isForgiven(UserInfo.USER)) {
				users.add(user);
			}
		}
		
		session.setAttribute("admins", admins);
		session.setAttribute("managers", managers);
		session.setAttribute("developers", developers);
		session.setAttribute("testers", testers);
		session.setAttribute("users", users);
--------------*/
	}
}
