package q02b.cuestionariosSMAnu.router;





//import java.util.ArrayList;

import java.util.HashMap;

//import org.apache.struts.action.ActionError;

import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;



import q02b.exe.cuestionariosSMAnu.valueobjects.Q02bCuestionarioSMFiltro;

import q02b.exe.utils.Q02bVoUtils;

import q02b.exe.utils.Q02bFormatData;

//import es.ejie.frmk.infraestructura.traza.Q70TraceLevel;

import es.ejie.frmk.infraestructura.traza.Q70Traza;

import es.ejie.frmk.presentacion.operacion.Q70DefaultRouterClass;

import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;



public class Q02bRouterObtenerGrupoCuestionariosSM extends Q70DefaultRouterClass {

	

	private static Q70Traza tr = Q70Traza.getSingleton();

	//private static final String COMPONENTE = "Q70_ROUTERCLASS";

	

	final static String VARIABLE_FILTRO= "filtro";

	final static String VARIABLE_NI_GRUPO= "niGrupoCuesSMAnu";

	final static String VARIABLE_HAY_CUESTIONARIOS= "hayCuestionarios";

	final static String VARIABLE_INICIO= "inicio";

	final static String VARIABLE_PORTADASM= "JSP_PORTADASM";

	final static String VARIABLE_PORTADA= "JSP_PORTADA";

	

	final static String  MAPPING_ERROR_FILTRO_NULO= "error.oi.altaModifGrupoCuestionariosSMAnu";

	

	final static String MAPPING_ERROR = "error";

	final static String MAPPING_SIN_REALIZAR_PREVSUELO = "noPrevSuelo";

	final static String MAPPING_LISTA="irListaCuestionariosSMAnu";

	final static String MAPPING_PORTADASM="irPortadaSM";

	final static String MAPPING_PORTADA="irPortada";

	

	//final static String MAPPING_ERROR_NO_CUES= "error.oi.noCuestionariosSMAnu";

	

	

		/**

		 * @see es.ejie.frmk.presentacion.operacion.paso.ActionPasoOP#processForward(es.ejie.frmk.presentacion.sesiondatos.ContextoEJIE, org.apache.struts.action.ActionErrors, org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

		 */  

	public  ActionForward processForward(Q70ContextoEJIE contexto,ActionErrors errores,ActionMapping mapping) throws Exception 

	{    

			ActionForward salida = new ActionForward();			

			Q02bCuestionarioSMFiltro cuestionarioSMAnuFiltro= null;

			String prevSuelo = null;

			//HashMap cuestionarioSMAnu = new HashMap();			

			HashMap mapaCuestionarioSMAnuFiltro = (HashMap)contexto.get(VARIABLE_FILTRO); 

			String niGrupoCuesSMAnu = (String)contexto.get(VARIABLE_NI_GRUPO);

			String hayCuestionarios = (String)contexto.get(VARIABLE_HAY_CUESTIONARIOS);

			String inicio = (String)contexto.get(VARIABLE_INICIO);



			if((Q02bFormatData.esNull(inicio)).equals(VARIABLE_PORTADASM)){

				salida = mapping.findForward(MAPPING_PORTADASM);	

			}

			else if((Q02bFormatData.esNull(inicio)).equals(VARIABLE_PORTADA)){

				salida = mapping.findForward(MAPPING_PORTADA);	

			}

			else{

			

				if (mapaCuestionarioSMAnuFiltro != null)

				{

					cuestionarioSMAnuFiltro = (Q02bCuestionarioSMFiltro)Q02bVoUtils.getValueObject(mapaCuestionarioSMAnuFiltro,"q02b.exe.cuestionariosSMAnu.valueobjects.Q02bCuestionarioSMFiltro");

					prevSuelo =	Q02bFormatData.checkStringNull(cuestionarioSMAnuFiltro.getPrevSuelo());	

					if(prevSuelo.equals("1"))

					{

						if(Q02bFormatData.esVacio(niGrupoCuesSMAnu))

						{

							salida = mapping.findForward(MAPPING_ERROR);	

							//errores.add("filtrar",new ActionError(MAPPING_ERROR_FILTRO_NULO));

						}

						else{

							salida = mapping.findForward(MAPPING_LISTA);	
                        }
							

					}

					else if ((prevSuelo.equals("0")) && (hayCuestionarios.equals("false")))

					{

						

						salida = mapping.findForward(MAPPING_SIN_REALIZAR_PREVSUELO);

					}

					else if ((prevSuelo.equals("0")) && (hayCuestionarios.equals("true")))

					{

						

						salida = mapping.findForward(MAPPING_LISTA);

					}

				}

				else

				{

					salida = mapping.findForward(MAPPING_ERROR);	

					//errores.add("filtrar",new ActionError(MAPPING_ERROR_FILTRO_NULO));

				}

			}

			

			

			return salida;

	}

}

