Package com.vst.webapp.validators

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

package com.vst.webapp.validators;

import com.vst.model.DetailSymbol;
import com.vst.service.DetailSymbolManager;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

/**
* Created by IntelliJ IDEA.
* User: Lilia
* Date: 26.11.2009
* Time: 12:06:19
* To change this template use File | Settings | File Templates.
*/
public class DetailSymbolValidator implements Validator {

    DetailSymbolManager detailSymbolManager;

    public void setDetailSymbolManager(DetailSymbolManager detailSymbolManager) {
        this.detailSymbolManager = detailSymbolManager;
    }

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

    public void validate(Object o, Errors errors) {
        DetailSymbol detailSymbol = (DetailSymbol) o;


        if ((detailSymbol.getType().equals("defect") && (detailSymbol.getDefectType() == null || detailSymbol.getDefectType().getDefectTypeId().longValue() == -1)) ||
                (detailSymbol.getType().equals("detail") && (detailSymbol.getConstructionType() == null || detailSymbol.getConstructionType().getConstructionTypeId().longValue() == -1)
                )) {

            if (detailSymbol.getType().equals("defect") && (detailSymbol.getDefectType() == null || detailSymbol.getDefectType().getDefectTypeId().longValue() == -1)) {
                errors.rejectValue("defectType", "reason.noDefectType");
            }
            if (detailSymbol.getType().equals("detail") &&
                    (detailSymbol.getConstructionType() == null || detailSymbol.getConstructionType().getConstructionTypeId().longValue() == -1)) {
                errors.rejectValue("constructionType", "reason.constructionType.error");
            }

        } else if (detailSymbol.getSymbolId() == null && detailSymbolManager.detailSymbolExist(detailSymbol)) {
            errors.rejectValue("symbolId", "detailSymbol.exist");
        }


    }
}
TOP

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

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.