package com.vst.webapp.action;
import com.vst.model.DetailDurability;
import com.vst.model.PipeLineElement;
import com.vst.service.DetailDurabilityManager;
import com.vst.service.ObjectInspectionManager;
import com.vst.service.PipeLineElementManager;
import com.vst.util.FileHelper;
import com.vst.webapp.util.PageHelper;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Created by IntelliJ IDEA.
* User: Администратор
* Date: 30.06.2009
* Time: 18:38:34
* To change this template use File | Settings | File Templates.
*/
public class DetailDurabilityController implements Controller {
DetailDurabilityManager detailDurabilityManager;
PipeLineElementManager pipeLineElementManager;
ObjectInspectionManager objectInspectionManager;
public void setDetailDurabilityManager(DetailDurabilityManager detailDurabilityManager) {
this.detailDurabilityManager = detailDurabilityManager;
}
public void setPipeLineElementManager(PipeLineElementManager pipeLineElementManager) {
this.pipeLineElementManager = pipeLineElementManager;
}
public void setObjectInspectionManager(ObjectInspectionManager objectInspectionManager) {
this.objectInspectionManager = objectInspectionManager;
}
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ModelAndView modelAndView = new ModelAndView("detailDurabilityList");
Integer detailType = Integer.valueOf(httpServletRequest.getParameter("detailType"));
Integer pipeElementId = Integer.valueOf(httpServletRequest.getParameter("pipeElementId"));
Integer objectId = Integer.valueOf(httpServletRequest.getParameter("objectId"));
if (httpServletRequest.getParameter("delete") != null) {
Integer deleteElementId = Integer.valueOf(httpServletRequest.getParameter("delete"));
PipeLineElement pipeLineElement = pipeLineElementManager.getPipeLineElementById(pipeElementId);
DetailDurability detailDurability = detailDurabilityManager.getDetailDurabilityById(deleteElementId);
pipeLineElement.getDetailDurabilityList().remove(detailDurability);
pipeLineElementManager.update(pipeLineElement);
detailDurabilityManager.delete(detailDurability);
}
modelAndView.addObject("objectId", objectId);
modelAndView.addObject("detailType", detailType);
modelAndView.addObject("pipeElementId", pipeElementId);
Integer page = new Integer(0);
Integer pageCount;
if (httpServletRequest.getParameter("page") != null) {
page = (Integer) Integer.parseInt(httpServletRequest.getParameter("page"));
}
modelAndView.addObject("detailDurabilityList", PageHelper.getListByPage(page, detailDurabilityManager.getDetailDurabilityListByElementId(pipeElementId, FileHelper.getCurrentPath(httpServletRequest))));
pageCount = (Integer) detailDurabilityManager.getDetailDurabilityListByElementId(pipeElementId, FileHelper.getCurrentPath(httpServletRequest)).size();
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);
return modelAndView;
}
}