package com.vst.webapp.action;
import com.vst.model.DetailSymbol;
import com.vst.model.LevelPlan;
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.List;
/**
* Created by IntelliJ IDEA.
* User: Lilia
* Date: 09.12.2009
* Time: 12:50:20
* To change this template use File | Settings | File Templates.
*/
public class LevelPlanController 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("levelPlanList");
if (httpServletRequest.getParameter("objectId")!=null){
Integer id=Integer.valueOf(httpServletRequest.getParameter("objectId")) ;
Integer page = new Integer(0);
Integer pageCount = new Integer(1);
if (httpServletRequest.getParameter("delete") != null) {
detailSymbolManager.delete(detailSymbolManager.getByIdLevelPlan(Integer.valueOf(httpServletRequest.getParameter("delete"))));
}
if (httpServletRequest.getParameter("page") != null) {
page = (Integer) Integer.parseInt(httpServletRequest.getParameter("page"));
}
List list = detailSymbolManager.getAllLevelPlan(page,id);
pageCount = (Integer) detailSymbolManager.getAllLevelPlan().size();
for (int i = 0; i < list.size(); i++) {
LevelPlan levelPlan = (LevelPlan) list.get(i);
DetailSymbol detailSymbol=new DetailSymbol();
detailSymbol.setSymbolBlob(levelPlan.getLevelBlob());
detailSymbol.setWayToSymbol(levelPlan.getWayToLevelPlan());
detailSymbol.setWayToSymbolImage(levelPlan.getWayToLevelPlanImage());
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("objectId", id);
modelAndView.addObject("pageCount", pageCount);
modelAndView.addObject("levelPlanList", list);
}
return modelAndView;
}
}