package com.vst.webapp.action;
import com.vst.model.DetailSymbol;
import com.vst.service.DetailSymbolManager;
import com.vst.util.FileHelper;
import com.vst.webapp.util.ObjectPictureUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: Lilia
* Date: 26.11.2009
* Time: 12:01:43
* To change this template use File | Settings | File Templates.
*/
public class DetailSymbolController implements Controller
{
DetailSymbolManager detailSymbolManager;
public void setDetailSymbolManager(DetailSymbolManager detailSymbolManager) {
this.detailSymbolManager = detailSymbolManager;
}
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ModelAndView modelAndView = new ModelAndView("detailSymbolList");
Integer page = new Integer(0);
Integer pageCount = new Integer(1);
if (httpServletRequest.getParameter("delete") != null) {
detailSymbolManager.delete(detailSymbolManager.getByIdPDetailSymbol(Integer.valueOf(httpServletRequest.getParameter("delete"))));
}
if (httpServletRequest.getParameter("page") != null) {
page = (Integer) Integer.parseInt(httpServletRequest.getParameter("page"));
}
List list = new ArrayList();
if (httpServletRequest.getParameter("type").equals("detail")) {
pageCount = (Integer) detailSymbolManager.getAllDetailSymbol().size();
list = detailSymbolManager.getAllDetailSymbol(page);
} else if (httpServletRequest.getParameter("type").equals("defect")) {
pageCount = (Integer) detailSymbolManager.getAllDefectSymbol().size();
list = detailSymbolManager.getAllDefectSymbol(page);
}
for (int i = 0; i < list.size(); i++) {
DetailSymbol detailSymbol = (DetailSymbol) list.get(i);
ObjectPictureUtil.addDetailSymbolJPEG(detailSymbol, FileHelper.getCurrentPath(httpServletRequest));
}
if ((pageCount.intValue() % 15) > 0) {
pageCount = (Integer) (1 + (pageCount.intValue() / 15));
} else {
pageCount = (Integer) (pageCount.intValue() / 15);
}
if (pageCount.intValue() == 0) {
pageCount = new Integer(1);
}
modelAndView.addObject("page", page);
modelAndView.addObject("pageCount", pageCount);
modelAndView.addObject("detailSymbolList", list);
modelAndView.addObject("type", httpServletRequest.getParameter("type"));
return modelAndView; //To change body of implemented methods use File | Settings | File Templates.
}
}