package de.thomasjacob.improve.presentation.issue.search;

import de.thomasjacob.improve.presentation.ImproveAction;
import de.thomasjacob.improve.presentation.login.LoginManager;
import de.thomasjacob.webcore.TechnicalException;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class SearchRHAction extends ImproveAction
{
	/*
	 * (non-Javadoc)
	 *
	 * @see de.thomasjacob.webcore.presentation.BaseAction#executeChecked(org.apache.struts.action.ActionMapping,
	 * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
	 * javax.servlet.http.HttpServletResponse)
	 */
	protected ActionForward executeChecked(ActionMapping mapping, ActionForm form, HttpServletRequest request,
		HttpServletResponse response) throws TechnicalException
	{
		HttpSession session = request.getSession();

		if (!LoginManager.getInstance(session).isLoggedIn())
		{
			return mapping.findForward("login");
		}

		IssueSearchForm issueSearchForm = (IssueSearchForm) form;
		if (request.getParameter("Reset") != null)
		{
			issueSearchForm.setFilterProjectId("");
			issueSearchForm.setFilterType("");
			issueSearchForm.setFilterPriority("");
			issueSearchForm.setFilterStatus("");
			issueSearchForm.setFilterReporter("");
			issueSearchForm.setFilterDeveloper("");
			issueSearchForm.setFilterIssueId("");
			issueSearchForm.setFilterSearchString("");
		}

		validateAndAddErrors(form, request, mapping);

		return mapping.findForward("success");
	}
}
