/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package paqueteCMD;

/**
 *
 * @author sysmq
 */
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import paqueteBL.Evento;
import paqueteBL.FvcBL;
import paqueteBL.Host;
import paqueteBL.Plantilla;
import paqueteBL.Pool;
import paqueteDAO.BaseDAO;
import paqueteDAO.EventoDAO;
import paqueteDAO.PoolDAO;
import paqueteView.HostView;
import paqueteView.PoolView;

public class cmdPool implements interfaceCMD{

public String procesa(String accion,HttpServletRequest request, HttpServletResponse response) throws Exception
{
     if (accion.equals("ver")) return verPool(request,response);
     else if (accion.equals("guardar")) return guardar(request,response);
     else if (accion.equals("nuevoHost")) return nuevoHost(request,response);
     else if (accion.equals("addHost")) return addHost(request,response);
     else return "/viewPool.jsp";
}

public String verPool(HttpServletRequest request, HttpServletResponse response) throws Exception
{
    Pool pool=new FvcBL().loadPool();
    return PoolView.viewPool(request,pool);
}

public String guardar(HttpServletRequest request, HttpServletResponse response) throws Exception
{
    int id;
    String dataStore=request.getParameter("txtDataStore");
    String responsable=request.getParameter("txtResponsable");
    String hora=request.getParameter("txtHoraBackup");
    String pathBackup=request.getParameter("txtPathBackup");
    Pool pool=new Pool();
    //pool=new FvcBL().loadPool();
    pool.setDataStore(dataStore);
    pool.setResponsable(responsable);
    pool.setHoraBackup(BaseDAO.hora22(hora));
    pool.setPathBackup(pathBackup);

    int n=Integer.valueOf(request.getParameter("nPlantillas"));
    int i;
    for(i=0;i<n;i++)
    {
        if((i==(n-1) && !request.getParameter("txtPlantilla"+i).equals("")) || (i<(n-1) && request.getParameter("chkPlantilla"+i).equals("true")))
        {
            Plantilla p=new Plantilla();
            p.setId(Integer.valueOf(request.getParameter("IDplantilla"+i)));
            p.setNombre(request.getParameter("txtPlantilla"+i));
            p.setPath(request.getParameter("txtPathPlantilla"+i));
            pool.addPlantilla(p);
        }
    }

    pool=new FvcBL().updatePool(pool);
    return PoolView.viewPool(request,pool);
}


public String nuevoHost(HttpServletRequest request, HttpServletResponse response) throws Exception
{
    return HostView.nuevoHost(request);
}

public String addHost(HttpServletRequest request, HttpServletResponse response) throws Exception
{
    int id;
    //id=Integer.valueOf(request.getParameter("id"));
    String nombre=request.getParameter("txtNombre");
    String ip=request.getParameter("txtIP");
    String usuario=request.getParameter("txtUsuario");
    String password=request.getParameter("txtPassword");
    Host host=new Host();
    //host.setId(id);
    host.setNombre(nombre);
    host.setIp(ip);
    host.setPassword(password);
    host.setUser(usuario);
    host=new FvcBL().addHost(host);
    return HostView.verHost(request, host);
}


}