package org.yacos.web.PCmember.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.yacos.core.evaluation.IEvaluationManager;
import org.yacos.core.evaluation.Rating;
import org.yacos.core.evaluation.Report;
import org.yacos.web.system.controller.NoConferenceSelectedException;


public class ListReportController extends SimpleFormController {

    protected final Log logger = LogFactory.getLog(getClass());
  
    private IEvaluationManager evaluationManager;

	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, NoConferenceSelectedException {
		
        logger.info("Returning listReport view");
        
        List<Report> listReport;
        String id=request.getParameter("id");
        int idd=Integer.parseInt(id);
		
        Map <String, Object> model = new HashMap<String, Object>();
        
		listReport = evaluationManager.getReportsForArticle(idd);
	    model.put("listReport", listReport);
	    
		List<Rating> ratings=evaluationManager.getRatingForReport(listReport.get(listReport.size()-1).getId());
		model.put("rtgs", ratings);
		
        return new ModelAndView("listReport", model);
    }
	
    public IEvaluationManager getEvaluationManager() {
		return evaluationManager;
	}

	public void setEvaluationManager(IEvaluationManager evaluationManager) {
		this.evaluationManager = evaluationManager;
	}
}