View Javadoc
1   /*
2    * Copyright 2009 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.module.purap.service.impl;
17  
18  import org.kuali.ole.coa.businessobject.Account;
19  import org.kuali.ole.coa.businessobject.ObjectCode;
20  import org.kuali.ole.coa.businessobject.SubObjectCode;
21  import org.kuali.ole.coa.service.ObjectCodeService;
22  import org.kuali.ole.coa.service.SubObjectCodeService;
23  import org.kuali.ole.module.purap.PurapKeyConstants;
24  import org.kuali.ole.sys.OLEConstants;
25  import org.kuali.ole.sys.OLEKeyConstants;
26  import org.kuali.ole.sys.businessobject.AccountingLine;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.rice.krad.datadictionary.DataDictionary;
29  import org.kuali.rice.krad.util.GlobalVariables;
30  import org.kuali.rice.krad.util.ObjectUtils;
31  
32  public class PurchasingAccountingLineRuleHelperServiceImpl extends PurapAccountingLineRuleHelperServiceImpl {
33  
34      /**
35       * @see org.kuali.ole.module.purap.service.impl.PurapAccountingLineRuleHelperServiceImpl#hasRequiredOverrides(org.kuali.ole.sys.businessobject.AccountingLine, java.lang.String)
36       *      override the default implementation and throw our own error message for accounts that are expired.
37       */
38      @Override
39      public boolean hasRequiredOverrides(AccountingLine line, String overrideCode) {
40          boolean retVal = true;
41          Account account = line.getAccount();
42          if (!ObjectUtils.isNull(account) && account.isExpired()) {
43              GlobalVariables.getMessageMap().putError(OLEConstants.ACCOUNT_NUMBER_PROPERTY_NAME, PurapKeyConstants.ERROR_ITEM_ACCOUNT_EXPIRED, account.getAccountNumber());
44              retVal = false;
45          }
46          return retVal;
47      }
48  
49      public boolean isValidObjectCode(ObjectCode objectCode, DataDictionary dataDictionary, String errorPropertyName) {
50          String label = getObjectCodeLabel();
51  
52          // make sure it exists
53          if (ObjectUtils.isNull(objectCode)) {
54              GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_EXISTENCE, label);
55              return false;
56          }
57  
58          Integer universityFiscalYear = getDocument().getPostingYearNextOrCurrent();
59          ObjectCode objectCodeForValidation = (SpringContext.getBean(ObjectCodeService.class).getByPrimaryId(universityFiscalYear, objectCode.getChartOfAccountsCode(), objectCode.getFinancialObjectCode()));
60  
61          // check active status
62          if (objectCodeForValidation == null || !objectCodeForValidation.isFinancialObjectActiveCode()) {
63              GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_INACTIVE, label);
64              return false;
65          }
66  
67          return true;
68      }
69  
70      public boolean isValidSubObjectCode(SubObjectCode subObjectCode, DataDictionary dataDictionary, String errorPropertyName) {
71          String label = getSubObjectCodeLabel();
72  
73          // make sure it exists
74          if (ObjectUtils.isNull(subObjectCode)) {
75              GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_EXISTENCE, label);
76              return false;
77          }
78  
79          Integer universityFiscalYear = getDocument().getPostingYearNextOrCurrent();
80          SubObjectCode subObjectCodeForValidation = (SpringContext.getBean(SubObjectCodeService.class).getByPrimaryId(universityFiscalYear, subObjectCode.getChartOfAccountsCode(), subObjectCode.getAccountNumber(), subObjectCode.getFinancialObjectCode(), subObjectCode.getFinancialSubObjectCode()));
81  
82  
83          // check active flag
84          if (!subObjectCodeForValidation.isActive()) {
85              GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_INACTIVE, label);
86              return false;
87          }
88          return true;
89      }
90  
91  }