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.fp.document.validation.impl; 017 018 import org.kuali.kfs.fp.document.InternalBillingDocument; 019 import org.kuali.kfs.sys.KFSKeyConstants; 020 import org.kuali.kfs.sys.KFSPropertyConstants; 021 import org.kuali.kfs.sys.businessobject.AccountingLine; 022 import org.kuali.kfs.sys.context.SpringContext; 023 import org.kuali.kfs.sys.document.validation.GenericValidation; 024 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 025 import org.kuali.rice.kns.service.DictionaryValidationService; 026 import org.kuali.rice.kns.service.ParameterEvaluator; 027 import org.kuali.rice.kns.service.ParameterService; 028 import org.kuali.rice.kns.util.GlobalVariables; 029 030 /** 031 * Validates that an accounting line does not have a capital object object code 032 */ 033 public class BillingCapitalObjectValidation extends GenericValidation { 034 private ParameterService parameterService; 035 private AccountingLine accountingLineForValidation; 036 037 /** 038 * Validates that an accounting line does not have a capital object object code 039 * <strong>Expects an accounting line as the first a parameter</strong> 040 * @see org.kuali.kfs.sys.document.validation.Validation#validate(java.lang.Object[]) 041 */ 042 public boolean validate(AttributedDocumentEvent event) { 043 boolean result = true; 044 045 // validate accounting line business object 046 SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(accountingLineForValidation); 047 048 // Don't bother running other validations if the accounting line isn't valid 049 if(GlobalVariables.getMessageMap().size() < 1) { 050 if (accountingLineForValidation.isSourceAccountingLine() && isCapitalObject(accountingLineForValidation)) { 051 GlobalVariables.getMessageMap().putError(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, KFSKeyConstants.ERROR_DOCUMENT_IB_CAPITAL_OBJECT_IN_INCOME_SECTION); 052 result = false; 053 } 054 // TODO phase II 055 // int pendPurchaseCount = 0; 056 // TODO need to do something with this but I have no idea what 057 // if (!SUB_FUND_GROUP_CODE.CODE_EXTAGY.equals(subFundGroupCode) && restrictedCapitalObjectCodes.contains(objectSubTypeCode) 058 // && (pendPurchaseCount <= 0)) 059 } 060 return result; 061 } 062 063 /** 064 * Checks whether the given AccountingLine's ObjectCode is a capital one. 065 * 066 * @param accountingLine The accounting line the object code will be retrieved from. 067 * @return True if the given accounting line's object code is a capital code, false otherwise. 068 */ 069 protected boolean isCapitalObject(AccountingLine accountingLine) { 070 ParameterEvaluator evaluator = getParameterService().getParameterEvaluator(InternalBillingDocument.class, "CAPITAL_OBJECT_SUB_TYPE_CODES", accountingLine.getObjectCode().getFinancialObjectSubTypeCode()); 071 return evaluator != null ? evaluator.evaluationSucceeds() : false; // can't find the param? then I guess we don't care...just say that nothing is a capital object 072 } 073 074 /** 075 * Gets the parameterService attribute. 076 * @return Returns the parameterService. 077 */ 078 public ParameterService getParameterService() { 079 return parameterService; 080 } 081 082 /** 083 * Sets the parameterService attribute value. 084 * @param parameterService The parameterService to set. 085 */ 086 public void setParameterService(ParameterService parameterService) { 087 this.parameterService = parameterService; 088 } 089 090 /** 091 * Gets the accountingLineForValidation attribute. 092 * @return Returns the accountingLineForValidation. 093 */ 094 public AccountingLine getAccountingLineForValidation() { 095 return accountingLineForValidation; 096 } 097 098 /** 099 * Sets the accountingLineForValidation attribute value. 100 * @param accountingLineForValidation The accountingLineForValidation to set. 101 */ 102 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) { 103 this.accountingLineForValidation = accountingLineForValidation; 104 } 105 }