package q02b.resultados.action;



import java.util.HashMap;



import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;



import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;



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

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

import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;

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





public class Q02bActionCargarProvMunCompartidoResultados extends Q70ActionPasoOP {

	private static Q70Traza tr = Q70Traza.getSingleton();

	private static final String COMPONENTE = "ACTION PASOOP";



	//Declaracion de las variables que no se modificaran

    final static String CODPROVINCIACOMPARTIDO = "codProvinciaCompartido";

    final static String CODMUNICIPIOCOMPARTIDO = "codMunicipioCompartido";

    final static String COD_PROVINCIA			= "codProvinciaContexto";

	final static String COD_MUNICIPIO			= "codMunicipioContexto";

	final static String CODPROVINCIA_FILTRO 	= "idProvincia";

	final static String CODMUNICIPIO_FILTRO		= "idMunicipio";



	final static String VARIABLE_ACCION= "accion";

	final static String VARIABLE_INICIO= "inicio";

    /**

     * @see es.ejie.frmk.presentacion.operacion.paso.ActionPasoOP#processOP(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)

     */

    protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores,

        ActionMapping mapping, ActionForm form, HttpServletRequest request,

        HttpServletResponse response) throws Exception {

        //Recogida de atributos del contexto de OP        

		contexto.set(CODPROVINCIACOMPARTIDO, contexto.get(COD_PROVINCIA));

		contexto.set(CODMUNICIPIOCOMPARTIDO, contexto.get(COD_MUNICIPIO));

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

		if ((inicio.equals("ALTA")||(inicio.equals("MODIFICAR")))){

			HashMap mapa = (HashMap) contexto.get("filtro");

			mapa.put(CODPROVINCIA_FILTRO, contexto.get(COD_PROVINCIA));

			mapa.put(CODMUNICIPIO_FILTRO, contexto.get(COD_MUNICIPIO));

			contexto.set("filtro", mapa);	

		}

    }



	

	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,

			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

		

		try{

			if (tr.isTraceActive()){

				tr.trace(COMPONENTE, Q70TraceLevel.INFO, this.getClass().getName() + ":processForward: entrando");

			}		

			String accion = (String)contexto.get(VARIABLE_ACCION);

			return mapping.findForward(accion);					

		}catch(Exception ex){

            java.io.StringWriter sw = new java.io.StringWriter();

            java.io.PrintWriter pw = new java.io.PrintWriter(sw);

            ex.printStackTrace(pw);

            if (tr.isTraceActive()){

				tr.trace(COMPONENTE, Q70TraceLevel.ERROR, this.getClass().getName() + ":processForward " + sw.getBuffer ().toString());

			}

            throw ex;

		 }finally{

			 if (tr.isTraceActive()){

					tr.trace(COMPONENTE, Q70TraceLevel.INFO, this.getClass().getName() + ":processForward: saliendo");

			 }

		 }

	}

}