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.ar.document.validation.impl;
017    
018    import static org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
019    
020    import org.kuali.kfs.module.ar.ArConstants;
021    import org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail;
022    import org.kuali.kfs.module.ar.document.CustomerInvoiceDocument;
023    import org.kuali.kfs.module.ar.document.CustomerInvoiceWriteoffDocument;
024    import org.kuali.kfs.sys.context.SpringContext;
025    import org.kuali.kfs.sys.document.validation.BranchingValidation;
026    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
027    import org.kuali.rice.kns.service.ParameterService;
028    
029    public class CustomerInvoiceWriteoffGLPEGenerationBranchingValidation extends BranchingValidation {
030        
031        public static final String IS_CHART_CODE_WRITEOFF_GLPE_VALIDATION = "isChartCodeWriteoffGLPEValidation";
032        public static final String IS_ORG_ACCOUNTING_DEFAULT_WRITEOFF_GLPE_VALIDATION = "isOrgAccountingDefaultWriteoffGLPEValidation";
033        
034        private ParameterService parameterService;
035        
036        @Override
037        protected String determineBranch(AttributedDocumentEvent event) {
038            
039            String writeoffGLPEGenerationOption = SpringContext.getBean(ParameterService.class).getParameterValue(CustomerInvoiceWriteoffDocument.class, ArConstants.GLPE_WRITEOFF_GENERATION_METHOD);
040            
041            if (ArConstants.GLPE_WRITEOFF_GENERATION_METHOD_CHART.equals( writeoffGLPEGenerationOption ) ){
042                return IS_CHART_CODE_WRITEOFF_GLPE_VALIDATION;
043            } else if (ArConstants.GLPE_WRITEOFF_GENERATION_METHOD_ORG_ACCT_DEFAULT.equals(writeoffGLPEGenerationOption)){
044                return IS_ORG_ACCOUNTING_DEFAULT_WRITEOFF_GLPE_VALIDATION;
045            }        
046            return null;
047        }
048    
049        public ParameterService getParameterService() {
050            return parameterService;
051        }
052    
053        public void setParameterService(ParameterService parameterService) {
054            this.parameterService = parameterService;
055        }
056    
057    }