package com.vst.webapp.action;
import com.vst.model.PipeLineElement;
import com.vst.model.VisualInspection;
import com.vst.service.PipeLineElementManager;
import com.vst.service.VisualInspectionManager;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
/**
* Created by IntelliJ IDEA.
* User: Администратор
* Date: 01.07.2009
* Time: 17:20:27
* To change this template use File | Settings | File Templates.
*/
public class VisualInspectionFormController extends BaseFormController {
VisualInspectionManager visualInspectionManager;
PipeLineElementManager pipeLineElementManager;
public PipeLineElementManager getPipeLineElementManager() {
return pipeLineElementManager;
}
public void setPipeLineElementManager(PipeLineElementManager pipeLineElementManager) {
this.pipeLineElementManager = pipeLineElementManager;
}
public void setVisualInspectionManager(VisualInspectionManager visualInspectionManager) {
this.visualInspectionManager = visualInspectionManager;
}
public VisualInspectionFormController() {
setCommandClass(VisualInspection.class);
setCommandName("visualInspection");
}
protected Object formBackingObject(HttpServletRequest request) throws Exception {
if (!isFormSubmission(request)) {
request.getSession().setAttribute("detailType", request.getParameter("detailType"));
request.getSession().setAttribute("objectId", request.getParameter("objectId"));
request.getSession().setAttribute("pipeElementId", request.getParameter("pipeElementId"));
Integer pipeId = Integer.valueOf(request.getParameter("pipeElementId"));
PipeLineElement pipeLineElement = pipeLineElementManager.getPipeLineElementById(pipeId);
Integer visualInspectionId = pipeLineElement.getVisualInspection().getInspectionId();
VisualInspection visualInspection = visualInspectionManager.getById(visualInspectionId);
return visualInspection;
}
return super.formBackingObject(request);
}
public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) throws IOException, SQLException {
VisualInspection visualInspection = (VisualInspection) command;
visualInspectionManager.update(visualInspection);
return new ModelAndView("redirect:lookPipeLineElement.html?objectId=" + request.getSession().getAttribute("objectId") + "&detailType=" + request.getSession().getAttribute("detailType"));
}
}