001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.module.purap.document.validation.impl;
017    
018    import java.util.List;
019    
020    import org.apache.commons.lang.StringUtils;
021    import org.kuali.kfs.module.purap.PurapKeyConstants;
022    import org.kuali.kfs.module.purap.PurapPropertyConstants;
023    import org.kuali.kfs.module.purap.businessobject.PurchaseOrderVendorStipulation;
024    import org.kuali.kfs.module.purap.document.PurchaseOrderDocument;
025    import org.kuali.kfs.sys.KFSConstants;
026    import org.kuali.kfs.sys.document.validation.GenericValidation;
027    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
028    import org.kuali.rice.kns.util.GlobalVariables;
029    
030    public class PurchaseOrderProcessVendorStipulationValidation extends GenericValidation {
031    
032        /**
033         * Validation for the Stipulation tab.
034         * 
035         * @param poDocument the purchase order document to be validated
036         * @return boolean false if the vendor stipulation description is blank.
037         */
038        public boolean validate(AttributedDocumentEvent event) {
039            boolean valid = true;
040            List<PurchaseOrderVendorStipulation> stipulations = ((PurchaseOrderDocument)event.getDocument()).getPurchaseOrderVendorStipulations();
041            for (int i = 0; i < stipulations.size(); i++) {
042                PurchaseOrderVendorStipulation stipulation = stipulations.get(i);
043                if (StringUtils.isBlank(stipulation.getVendorStipulationDescription())) {
044                    GlobalVariables.getMessageMap().putError(KFSConstants.DOCUMENT_PROPERTY_NAME + "." + PurapPropertyConstants.VENDOR_STIPULATION + "[" + i + "]." + PurapPropertyConstants.VENDOR_STIPULATION_DESCRIPTION, PurapKeyConstants.ERROR_STIPULATION_DESCRIPTION);
045                    valid = false;
046                }
047            }
048    
049            return valid;
050        }
051    
052    }