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.cam.document.validation.impl;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.kfs.module.cam.CamsPropertyConstants;
020    import org.kuali.kfs.module.cam.businessobject.AssetPaymentDetail;
021    import org.kuali.kfs.module.cam.document.AssetPaymentDocument;
022    import org.kuali.kfs.sys.KFSKeyConstants;
023    import org.kuali.kfs.sys.KFSPropertyConstants;
024    import org.kuali.kfs.sys.businessobject.AccountingLine;
025    import org.kuali.kfs.sys.businessobject.OriginationCode;
026    import org.kuali.kfs.sys.document.validation.GenericValidation;
027    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
028    import org.kuali.kfs.sys.service.OriginationCodeService;
029    import org.kuali.rice.kns.service.DataDictionaryService;
030    import org.kuali.rice.kns.util.GlobalVariables;
031    
032    /**
033     * This class validates asset payment document origin code
034     */
035    public class AssetPaymentOriginCodeValidation extends GenericValidation {
036    
037        private OriginationCodeService originationCodeService;
038        private DataDictionaryService dataDictionaryService;
039        private AccountingLine accountingLineForValidation;
040    
041        /**
042         * Validates origin code
043         * 
044         * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
045         */
046        public boolean validate(AttributedDocumentEvent event) {
047            // skip check if accounting line is from CAB
048            AssetPaymentDocument assetPaymentDocument = (AssetPaymentDocument) event.getDocument();
049            if (assetPaymentDocument.isCapitalAssetBuilderOriginIndicator()) {
050                return true;
051            }
052            
053            AssetPaymentDetail assetPaymentDetail = (AssetPaymentDetail) getAccountingLineForValidation();
054            boolean result = true;
055            if (!StringUtils.isBlank(assetPaymentDetail.getExpenditureFinancialSystemOriginationCode())) {
056                if (originationCodeService.getByPrimaryKey(assetPaymentDetail.getExpenditureFinancialSystemOriginationCode()) == null) {
057                    String label = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(OriginationCode.class.getName()).getAttributeDefinition(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE).getLabel();
058                    GlobalVariables.getMessageMap().putError(CamsPropertyConstants.AssetPaymentDetail.ORIGINATION_CODE, KFSKeyConstants.ERROR_EXISTENCE, label);
059                    result = false;
060                }
061            }
062            return result;
063        }
064    
065        public AccountingLine getAccountingLineForValidation() {
066            return accountingLineForValidation;
067        }
068    
069        public void setAccountingLineForValidation(AccountingLine accountingLine) {
070            this.accountingLineForValidation = accountingLine;
071        }
072    
073        public OriginationCodeService getOriginationCodeService() {
074            return originationCodeService;
075        }
076    
077        public void setOriginationCodeService(OriginationCodeService originationCodeService) {
078            this.originationCodeService = originationCodeService;
079        }
080    
081        public DataDictionaryService getDataDictionaryService() {
082            return dataDictionaryService;
083        }
084    
085        public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
086            this.dataDictionaryService = dataDictionaryService;
087        }
088    
089    
090    }