Package com.vst.webapp.validators

Source Code of com.vst.webapp.validators.PipeLineElementValidator

package com.vst.webapp.validators;

import com.vst.model.PipeLineElement;
import com.vst.service.PipeLineElementManager;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

/**
* Created by IntelliJ IDEA.
* User: And Lilia
* Date: 26.05.2009
* Time: 13:36:00
* To change this template use File | Settings | File Templates.
*/
public class PipeLineElementValidator implements Validator {

    PipeLineElementManager pipeLineElementManager;

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

    public boolean supports(Class aClass) {
        return PipeLineElement.class.isAssignableFrom(aClass);
    }

    public void validate(Object o, Errors errors) {

        System.out.println("validate");

        PipeLineElement p=(PipeLineElement)o;
        if ((p.getDetailType().getTypeId().intValue()==1 || p.getDetailType().getTypeId().intValue()==2 || p.getDetailType().getTypeId().intValue()==5 || p.getDetailType().getTypeId().intValue()==6)&& (p.getDiametr()==null || p.getThickness()==null)) {
              if (p.getDiametr()==null){
                errors.rejectValue("diametr","detail.diametr");
              }
              if (p.getThickness()==null){
                errors.rejectValue("thickness","detail.thickness");
              }
        }

        if ((p.getDetailType().getTypeId().intValue()==7 || p.getDetailType().getTypeId().intValue()==8)&& (p.getDiametr()==null || p.getThickness()==null)) {
              if (p.getDiametr()==null){
                errors.rejectValue("diametr","detail.diametr");
              }             
        }

         if (p.getDetailType().getTypeId().intValue()==2 && (p.getCorner()==null)) {
                     if (p.getCorner()==null){
                        errors.rejectValue("corner","detail.corner");
                      }
        }

         if ((p.getDetailType().getTypeId().intValue()==3 || p.getDetailType().getTypeId().intValue()==4) && (p.getFirstDiametr()==null || p.getFirstThickness()==null || p.getSecondDiametr()==null || p.getSecondThickness()==null)) {
              if (p.getFirstDiametr()==null){
                errors.rejectValue("firstDiametr","detail.diametr");
              }
              if (p.getFirstThickness()==null){
                errors.rejectValue("firstThickness","detail.thickness");
              }
             if (p.getSecondDiametr()==null){
                errors.rejectValue("secondDiametr","detail.diametr");
              }
              if (p.getSecondThickness()==null){
                errors.rejectValue("secondThickness","detail.thickness");
              }
        }



         if ((p.getDetailType().getTypeId().intValue()==6 || p.getDetailType().getTypeId().intValue()==7 || p.getDetailType().getTypeId().intValue()==8) && (p.getPressure()==null)) {
              if (p.getPressure()==null){
                  errors.rejectValue("pressure","detail.pressure");
              }
        }


         if (p.getMarkElement()==null || p.getMarkElement().trim().equals(""))
         {
              errors.rejectValue("markElement","detail.marks");
         }
        if (p.getNumberElement().trim().equals("")){
             errors.rejectValue("numberElement","detail.number");
        }

        if ( p.getDetail().getDetailId()==null || p.getDetail().getDetailId().intValue()==-1){
             errors.rejectValue("detail.detailId","detail.exist");
        }


    }
}
TOP

Related Classes of com.vst.webapp.validators.PipeLineElementValidator

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.