Package com.vst.webapp.action

Source Code of com.vst.webapp.action.InsertPipeLineElementController

package com.vst.webapp.action;

import com.vst.model.ObjectInspection;
import com.vst.model.PipeLineElement;
import com.vst.model.VisualInspection;
import com.vst.service.DetailManager;
import com.vst.service.ObjectInspectionManager;
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;



/**
* Created by IntelliJ IDEA.
* User: And Lilia
* Date: 26.05.2009
* Time: 13:32:36
* To change this template use File | Settings | File Templates.
*/
public class InsertPipeLineElementController extends BaseFormController{
    VisualInspectionManager visualInspectionManager;
    PipeLineElementManager pipeLineElementManager;

    DetailManager detailManager;

    ObjectInspectionManager objectInspectionManager;

    public void setVisualInspectionManager(VisualInspectionManager visualInspectionManager) {
        this.visualInspectionManager = visualInspectionManager;
    }

    public void setObjectInspectionManager(ObjectInspectionManager objectInspectionManager) {
        this.objectInspectionManager = objectInspectionManager;
    }

    public void setDetailManager(DetailManager detailManager) {
        this.detailManager = detailManager;
    }

    public void setPipeLineElementManager(PipeLineElementManager pipeLineElementManager) {
        this.pipeLineElementManager = pipeLineElementManager;
    }

    public InsertPipeLineElementController() {

              setCommandName("pipe");
              setCommandClass(PipeLineElement.class);
          }

        protected Object formBackingObject(HttpServletRequest request) throws Exception {


                request.setAttribute("detailTypeRadioButton",detailManager.getTypes());
                request.setAttribute("objectId",request.getParameter("objectId"));


               if (!isFormSubmission(request)) {

                Integer objectId=(Integer)Integer.parseInt(request.getParameter("objectId"));
                request.getSession().setAttribute("objectId",objectId);
                Integer detailType=(Integer)Integer.parseInt(request.getParameter("detailType"));





                                              if (detailType.equals(new Integer(1))){
                                                 request.setAttribute("detailList",detailManager.getAllPipe());
                                              }
                                                if (detailType.equals(new Integer(2))){
                                                 request.setAttribute("detailList",detailManager.getAllTap());
                                              }
                                                if (detailType.equals(new Integer(3))){
                                                 request.setAttribute("detailList",detailManager.getAllTransition());
                                              }
                                                if (detailType.equals(new Integer(4))){
                                                request.setAttribute("detailList",detailManager.getAllTee());
                                              }
                                                if (detailType.equals(new Integer(5))){
                                                 request.setAttribute("detailList",detailManager.getAllZaglushka());
                                              }
                                                if (detailType.equals(new Integer(6))){
                                                 request.setAttribute("detailList",detailManager.getAllFlange());
                                              }
                                                if (detailType.equals(new Integer(7))){
                                                request.setAttribute("detailList",detailManager.getAllArmature());
                                              }
                                                if (detailType.equals(new Integer(8))){
                                                request.setAttribute("detailList",detailManager.getAllOborudovanie());
                                              }





                  if (request.getParameter("update")!=null){

                  Integer id=(Integer)Integer.parseInt(request.getParameter("update"));
                  PipeLineElement pipeLineElement=pipeLineElementManager.getPipeLineElementById(id);
                  request.setAttribute("detailType",detailType);
                  return pipeLineElement;

            }

               else{

                                 PipeLineElement pipeLineElement=new PipeLineElement();
                                 pipeLineElement.setDetailType(detailManager.getDetailTypesById(detailType));
                                 request.setAttribute("detailType",detailType);
                                 return pipeLineElement;

            }
          }
               return super.formBackingObject(request);

           }

           public ModelAndView onSubmit(HttpServletRequest request,
                                        HttpServletResponse response,
                                        Object command,
                                        BindException errors)   throws Exception{




               ModelAndView mav = new ModelAndView(getSuccessView());



               PipeLineElement pipeLineElement=(PipeLineElement)command;
               Integer objectId=(Integer)request.getSession().getAttribute("objectId");

               if(request.getParameter("cansel")!=null){
                   return new ModelAndView("redirect:/lookPipeLineElement.html?detailType="+request.getParameter("newDetailType")+"&objectId="+objectId);
               }



                   Integer detailType=pipeLineElement.getDetailType().getTypeId();
                   pipeLineElement.setDetailType(detailManager.getDetailTypesById(detailType));

               if(request.getParameter("newDetailType")!=null){



                       if (detailType.equals(new Integer(1))){

                         mav.addObject("detailList",detailManager.getAllPipe());
                       }
                         if (detailType.equals(new Integer(2))){

                         mav.addObject("detailList",detailManager.getAllTap());
                       }
                         if (detailType.equals(new Integer(3))){

                         mav.addObject("detailList",detailManager.getAllTransition());
                       }
                         if (detailType.equals(new Integer(4))){

                         mav.addObject("detailList",detailManager.getAllTee());
                       }
                         if (detailType.equals(new Integer(5))){

                         mav.addObject("detailList",detailManager.getAllZaglushka());
                       }
                         if (detailType.equals(new Integer(6))){

                         mav.addObject("detailList",detailManager.getAllFlange());
                       }
                         if (detailType.equals(new Integer(7))){

                         mav.addObject("detailList",detailManager.getAllArmature());
                       }
                         if (detailType.equals(new Integer(8))){

                         mav.addObject("detailList",detailManager.getAllOborudovanie());
                       }
                   mav.addObject("detailType",detailType);
                   mav.addObject("pipe",pipeLineElement);

                   return mav;

               }

                    if (detailType.equals(new Integer(1))){
                         pipeLineElement.setDetail(detailManager.getPipeById(pipeLineElement.getDetail().getDetailId()));
                       }
                         if (detailType.equals(new Integer(2))){
                              pipeLineElement.setDetail(detailManager.getTapById(pipeLineElement.getDetail().getDetailId()));
                       }
                         if (detailType.equals(new Integer(3))){
                              pipeLineElement.setDetail(detailManager.getTransitionById(pipeLineElement.getDetail().getDetailId()));
                       }
                         if (detailType.equals(new Integer(4))){
                              pipeLineElement.setDetail(detailManager.getTeeById(pipeLineElement.getDetail().getDetailId()));
                       }
                         if (detailType.equals(new Integer(5))){
                              pipeLineElement.setDetail(detailManager.getZaglushkaById(pipeLineElement.getDetail().getDetailId()));
                       }
                         if (detailType.equals(new Integer(6))){
                              pipeLineElement.setDetail(detailManager.getFlangeById(pipeLineElement.getDetail().getDetailId()));

                       }
                         if (detailType.equals(new Integer(7))){
                              pipeLineElement.setDetail(detailManager.getArmatureById(pipeLineElement.getDetail().getDetailId()));

                       }
                         if (detailType.equals(new Integer(8))){
                              pipeLineElement.setDetail(detailManager.getOborudovanieById(pipeLineElement.getDetail().getDetailId()));

                       }

          

                if (pipeLineElement.getIdElement()!=null){

                       pipeLineElementManager.update(pipeLineElement);
                     return new ModelAndView("redirect:/lookPipeLineElement.html?detailType="+detailType+"&objectId="+objectId);
                   }

                else{
                    VisualInspection visualInspection=new VisualInspection();
                    visualInspection.setInspectionDescription("");
                    visualInspection.setInspectionValidity(false);
                    visualInspectionManager.insert(visualInspection);
                    pipeLineElement.setVisualInspection(visualInspection);
                    pipeLineElementManager.insert(pipeLineElement);
                    ObjectInspection objectInspection=objectInspectionManager.getObjectInspectionBy(objectId);
                    objectInspection.getPipeLineList().add(pipeLineElement);
                    objectInspectionManager.updateObjectInspection(objectInspection);
                    return new ModelAndView("redirect:/lookPipeLineElement.html?detailType="+detailType+"&objectId="+objectId);
                   }
                     

           }


    public ModelAndView processFormSubmission(HttpServletRequest request,
                                                 HttpServletResponse response,
                                                 Object command,
                                                 BindException errors)
               throws Exception {
              ModelAndView mav = new ModelAndView(getSuccessView());
              PipeLineElement pipeLineElement=(PipeLineElement)command;



         if(request.getParameter("newDetailType")!=null){




                   Integer detailType=pipeLineElement.getDetailType().getTypeId();
                   pipeLineElement.setDetailType(detailManager.getDetailTypesById(detailType));

                       if (detailType.equals(new Integer(1))){

                         mav.addObject("detailList",detailManager.getAllPipe());
                       }
                         if (detailType.equals(new Integer(2))){

                         mav.addObject("detailList",detailManager.getAllTap());
                       }
                         if (detailType.equals(new Integer(3))){

                         mav.addObject("detailList",detailManager.getAllTransition());
                       }
                         if (detailType.equals(new Integer(4))){

                         mav.addObject("detailList",detailManager.getAllTee());
                       }
                         if (detailType.equals(new Integer(5))){

                         mav.addObject("detailList",detailManager.getAllZaglushka());
                       }
                         if (detailType.equals(new Integer(6))){

                         mav.addObject("detailList",detailManager.getAllFlange());
                       }
                         if (detailType.equals(new Integer(7))){

                         mav.addObject("detailList",detailManager.getAllArmature());
                       }
                         if (detailType.equals(new Integer(8))){

                         mav.addObject("detailList",detailManager.getAllOborudovanie());
                       }
                   mav.addObject("detailType",detailType);
                   mav.addObject("pipe",pipeLineElement);

                   return mav;

       }





                   Integer detailType=pipeLineElement.getDetailType().getTypeId();



                   pipeLineElement.setDetailType(detailManager.getDetailTypesById(detailType));

                       if (detailType.equals(new Integer(1))){

                         request.setAttribute("detailList",detailManager.getAllPipe());
                       }
                         if (detailType.equals(new Integer(2))){

                         request.setAttribute("detailList",detailManager.getAllTap());
                       }
                         if (detailType.equals(new Integer(3))){

                         request.setAttribute("detailList",detailManager.getAllTransition());
                       }
                         if (detailType.equals(new Integer(4))){

                         request.setAttribute("detailList",detailManager.getAllTee());
                       }
                         if (detailType.equals(new Integer(5))){

                         request.setAttribute("detailList",detailManager.getAllZaglushka());
                       }
                         if (detailType.equals(new Integer(6))){

                         request.setAttribute("detailList",detailManager.getAllFlange());
                       }
                         if (detailType.equals(new Integer(7))){

                         request.setAttribute("detailList",detailManager.getAllArmature());
                       }
                         if (detailType.equals(new Integer(8))){

                         request.setAttribute("detailList",detailManager.getAllOborudovanie());
                       }
                   request.setAttribute("detailType",detailType);


                   return super.processFormSubmission(request,
                   response,
                   pipeLineElement,
                   errors);
    }
       
}
TOP

Related Classes of com.vst.webapp.action.InsertPipeLineElementController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.