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

package hu.nir.nmail.spring.controllers;

import hu.nir.nmail.ejb.entity.NmailUser;
import hu.nir.nmail.services.ProcesTableUpdaterService;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author attila
 */
public class ProcesController extends AbstractController {
    private String successView;
    private ProcesTableUpdaterService procesTableUpdaterService;
    
    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
        HttpSession session = request.getSession();
        NmailUser nmailUser = (NmailUser) session.getAttribute("nmailUser");
        Map<String, Object> model = procesTableUpdaterService.processCommand(nmailUser);
        
        if (model == null) {
            model = (Map) session.getAttribute("procesTableData");
            if (model == null) {
                return new ModelAndView(getSuccessView());
            }
        }
        else {
            session.setAttribute("procesTableData", model);
        }
        
        return new ModelAndView(getSuccessView(), model);
    }

    public String getSuccessView() {
        return successView;
    }

    public void setSuccessView(String successView) {
        this.successView = successView;
    }

    public ProcesTableUpdaterService getProcesTableUpdaterService() {
        return procesTableUpdaterService;
    }

    public void setProcesTableUpdaterService(ProcesTableUpdaterService procesTableUpdaterService) {
        this.procesTableUpdaterService = procesTableUpdaterService;
    }

}
