package com.vst.webapp.action;
import com.vst.model.ObjectInspection;
import com.vst.model.PipeLineElement;
import com.vst.service.DetailManager;
import com.vst.service.ObjectInspectionManager;
import com.vst.service.PipeLineElementManager;
import com.vst.util.FileHelper;
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: And Lilia
* Date: 26.05.2009
* Time: 13:32:12
* To change this template use File | Settings | File Templates.
*/
public class LookPipeLineElementController implements Controller {
PipeLineElementManager pipeLineElementManager;
ObjectInspectionManager objectInspectionManager;
DetailManager detailManager;
public void setDetailManager(DetailManager detailManager) {
this.detailManager = detailManager;
}
public void setObjectInspectionManager(ObjectInspectionManager objectInspectionManager) {
this.objectInspectionManager = objectInspectionManager;
}
public void setPipeLineElementManager(PipeLineElementManager pipeLineElementManager) {
this.pipeLineElementManager = pipeLineElementManager;
}
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ModelAndView modelAndView = new ModelAndView("lookPipeLineElement");
if (httpServletRequest.getParameter("edited") != null) {
httpServletRequest.setAttribute("addition", "?edited=1");
}
if (httpServletRequest.getParameter("objectId") != null) {
Integer objectId = (Integer) Integer.parseInt(httpServletRequest.getParameter("objectId"));
if (httpServletRequest.getParameter("detailType") != null) {
if (httpServletRequest.getParameter("delete") != null) {
Integer id = (Integer) Integer.parseInt(httpServletRequest.getParameter("delete"));
PipeLineElement pipeLineElement = pipeLineElementManager.getPipeLineElementById(id);
ObjectInspection objectInspection = objectInspectionManager.getObjectInspectionBy(objectId);
objectInspection.getPipeLineList().remove(pipeLineElement);
objectInspectionManager.updateObjectInspection(objectInspection);
pipeLineElementManager.delete(pipeLineElement);
}
Integer detailType = (Integer) Integer.parseInt(httpServletRequest.getParameter("detailType"));
if (detailType.intValue() == 1 || detailType.intValue() == 5 || detailType.intValue() == 7 || detailType.intValue() == 8) {
modelAndView.addObject("count", new Integer(7));
}
if (detailType.intValue() == 2 || detailType.intValue() == 6) {
modelAndView.addObject("count", new Integer(8));
}
if (detailType.intValue() == 3 || detailType.intValue() == 4) {
modelAndView.addObject("count", new Integer(9));
}
modelAndView.addObject("pipeList", pipeLineElementManager.getPipeLineListByObjectInspectionAndDetailType(detailType, objectId, FileHelper.getCurrentPath(httpServletRequest)));
modelAndView.addObject("detailType", detailType);
} else {
modelAndView.addObject("pipeLine", pipeLineElementManager.getPipeLineListByObjectInspectionId(objectId, FileHelper.getCurrentPath(httpServletRequest)));
}
modelAndView.addObject("detailTypeRadioButton", detailManager.getTypes());
modelAndView.addObject("objectId", objectId);
modelAndView.addObject("detailName", detailManager.getDetailTypesById(Integer.valueOf(httpServletRequest.getParameter("detailType"))).getSecondName());
}
return modelAndView;
}
}