View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.fp.document.validation.impl;
17  
18  import org.kuali.ole.fp.document.InternalBillingDocument;
19  import org.kuali.ole.sys.OLEKeyConstants;
20  import org.kuali.ole.sys.OLEPropertyConstants;
21  import org.kuali.ole.sys.businessobject.AccountingLine;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.core.api.parameter.ParameterEvaluator;
26  import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
27  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
28  import org.kuali.rice.kns.service.DictionaryValidationService;
29  import org.kuali.rice.krad.util.GlobalVariables;
30  
31  /**
32   * Validates that an accounting line does not have a capital object object code 
33   */
34  public class BillingCapitalObjectValidation extends GenericValidation {
35      private ParameterService parameterService;
36      private AccountingLine accountingLineForValidation;
37  
38      /**
39       * Validates that an accounting line does not have a capital object object code
40       * <strong>Expects an accounting line as the first a parameter</strong>
41       * @see org.kuali.ole.sys.document.validation.Validation#validate(java.lang.Object[])
42       */
43      public boolean validate(AttributedDocumentEvent event) {
44          boolean result = true;
45          
46          // validate accounting line business object
47          SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(accountingLineForValidation);
48          
49          // Don't bother running other validations if the accounting line isn't valid
50          if(GlobalVariables.getMessageMap().getNumberOfPropertiesWithErrors() < 1) {
51              if (accountingLineForValidation.isSourceAccountingLine() && isCapitalObject(accountingLineForValidation)) {
52                  GlobalVariables.getMessageMap().putError(OLEPropertyConstants.FINANCIAL_OBJECT_CODE, OLEKeyConstants.ERROR_DOCUMENT_IB_CAPITAL_OBJECT_IN_INCOME_SECTION);
53                  result = false;
54              }
55              // TODO phase II
56              // int pendPurchaseCount = 0; 
57              // TODO need to do something with this but I have no idea what
58              // if (!SUB_FUND_GROUP_CODE.CODE_EXTAGY.equals(subFundGroupCode) && restrictedCapitalObjectCodes.contains(objectSubTypeCode)
59              // && (pendPurchaseCount <= 0))
60          }
61          return result;
62      }
63  
64      /**
65       * Checks whether the given AccountingLine's ObjectCode is a capital one.
66       * 
67       * @param accountingLine The accounting line the object code will be retrieved from.
68       * @return True if the given accounting line's object code is a capital code, false otherwise.
69       */
70      protected boolean isCapitalObject(AccountingLine accountingLine) {
71          ParameterEvaluator evaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(InternalBillingDocument.class, "CAPITAL_OBJECT_SUB_TYPE_CODES", accountingLine.getObjectCode().getFinancialObjectSubTypeCode());
72          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
73      }
74  
75      /**
76       * Gets the parameterService attribute. 
77       * @return Returns the parameterService.
78       */
79      public ParameterService getParameterService() {
80          return parameterService;
81      }
82  
83      /**
84       * Sets the parameterService attribute value.
85       * @param parameterService The parameterService to set.
86       */
87      public void setParameterService(ParameterService parameterService) {
88          this.parameterService = parameterService;
89      }
90  
91      /**
92       * Gets the accountingLineForValidation attribute. 
93       * @return Returns the accountingLineForValidation.
94       */
95      public AccountingLine getAccountingLineForValidation() {
96          return accountingLineForValidation;
97      }
98  
99      /**
100      * Sets the accountingLineForValidation attribute value.
101      * @param accountingLineForValidation The accountingLineForValidation to set.
102      */
103     public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
104         this.accountingLineForValidation = accountingLineForValidation;
105     }
106 }