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.*;
import javax.servlet.http.*;

import br.dsc.upe.poli.basicas.Aluno;
import br.dsc.upe.poli.dao.AlunoDAO;
import flexjson.JSONSerializer;

/**
 * Servlet implementation class BuscarAluno
 */
public class BuscarAluno extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BuscarAluno() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String nome = request.getParameter("campoNomeAluno");
		
		String identidade = request.getParameter("campoIdentidadeAluno");
		
		String turma = request.getParameter("campoTurmaAluno");
		
		try {
			
			AlunoDAO alunoDAO = new AlunoDAO();
			HashMap<String,ArrayList<Aluno>> hashalunos = new HashMap<String,ArrayList<Aluno>>();
			
		

			hashalunos = alunoDAO.buscarGeral(nome, identidade, turma);
			JSONSerializer serializer = new JSONSerializer();
			response.setCharacterEncoding("UTF-8");
			response.getWriter().write(serializer.serialize(hashalunos));
		} 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 {
		
		
}
}