package br.dsc.upe.poli.mvc;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.dsc.upe.poli.basicas.Atividade;
import br.dsc.upe.poli.dao.AtividadeDAO;
import flexjson.JSONSerializer;

/**
 * Servlet implementation class CarregaAt
 */
public class CarregaAt extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public CarregaAt() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String login = request.getParameter("logado");
		try {
			HashMap<String, ArrayList<Atividade>> hash = new HashMap<String,ArrayList<Atividade>>();
			AtividadeDAO atividadeDAO = new AtividadeDAO();
			ArrayList<String> ass = new ArrayList<String>();
			
		

			ass = atividadeDAO.listarAtividadesPorLogin(login);
			hash = atividadeDAO.listarAtividades(login, ass);
			JSONSerializer serializer = new JSONSerializer();
			response.setCharacterEncoding("UTF-8");
			response.getWriter().write(serializer.serialize(hash));
			response.setCharacterEncoding("UTF-8");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
