package org.yacos.web.system.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
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.article.Article;
import org.yacos.core.article.IArticleManager;
import org.yacos.web.system.controller.NoConferenceSelectedException;
import org.yacos.web.system.session.SessionService;

public class StateArticleController extends SimpleFormController {

    protected final Log logger = LogFactory.getLog(getClass());
    private IArticleManager articleManager;


	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, NoConferenceSelectedException {
		
        logger.info("Returning stateArticle view");
        
        String role=request.getParameter("role");
        Integer confId=SessionService.getInstance().getCurrentConferenceId();
        String authorId=SessionService.getInstance().getCurrentUserLogin();
       // Hashtable<String,Object> ht=new Hashtable<String, Object>();
        List<Article> articles=new ArrayList<Article>();
        
        if(role.equals("author"))
        {
         articles=articleManager.getArticleOfAuthor(confId, authorId);
        	
         if (articles==null|articles.isEmpty())
         {
         	System.out.println("Liste est Null");
         	
         	
         }
         else
         {
        	 
        	 return new ModelAndView("stateArticle","articles",articles);
        	 
         }
         
    	 
         
        }
        
        else if (role.equals("referee"))
        {
         articles=articleManager.getArticlesOfMember(confId, authorId);
        
         if (articles==null|articles.isEmpty())
         {
         	System.out.println("Liste est Null");
         	
         	
         }
         else
         {
        	 return new ModelAndView("stateArticle","articles",articles);}
         
    	}
        
        
        return null;
    }


	public IArticleManager getArticleManager() {
		return articleManager;
	}


	public void setArticleManager(IArticleManager articleManager) {
		this.articleManager = articleManager;
	}
	

}