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.coa.document;
17  
18  import java.util.List;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.apache.log4j.Logger;
22  import org.kuali.ole.coa.businessobject.Account;
23  import org.kuali.ole.coa.businessobject.IndirectCostRecoveryRateDetail;
24  import org.kuali.ole.coa.service.AccountService;
25  import org.kuali.ole.gl.GeneralLedgerConstants;
26  import org.kuali.ole.sys.OLEConstants;
27  import org.kuali.ole.sys.OLEPropertyConstants;
28  import org.kuali.ole.sys.context.SpringContext;
29  import org.kuali.ole.sys.document.FinancialSystemMaintainable;
30  import org.kuali.rice.krad.bo.PersistableBusinessObject;
31  import org.kuali.rice.krad.util.ObjectUtils;
32  
33  public class IndirectCostRecoveryRateMaintainableImpl extends FinancialSystemMaintainable {
34      private static final Logger LOG = Logger.getLogger(IndirectCostRecoveryRateMaintainableImpl.class);  
35  
36      private Integer indirectCostRecoveryRateNextEntryNumber;
37  
38      /**
39       * Hook for quantity and setting asset numbers.
40       * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#addNewLineToCollection(java.lang.String)
41       */
42      @Override
43      public void addNewLineToCollection(String collectionName) {
44  
45          // create handle for the addline section of the doc
46          IndirectCostRecoveryRateDetail addLine = (IndirectCostRecoveryRateDetail) newCollectionLines.get(collectionName);
47          List<IndirectCostRecoveryRateDetail> maintCollection = (List<IndirectCostRecoveryRateDetail>) ObjectUtils.getPropertyValue(getBusinessObject(), collectionName);
48  
49          if(StringUtils.isBlank(addLine.getSubAccountNumber()) || StringUtils.containsOnly(addLine.getSubAccountNumber(), "-")) {
50              addLine.setSubAccountNumber(OLEConstants.getDashSubAccountNumber());
51          }
52          if(StringUtils.isBlank(addLine.getFinancialSubObjectCode()) || StringUtils.containsOnly(addLine.getFinancialSubObjectCode(), "-")) {
53              addLine.setFinancialSubObjectCode(OLEConstants.getDashFinancialSubObjectCode());
54          }
55  
56          Integer icrEntryNumberMax = 0;
57          for(IndirectCostRecoveryRateDetail item : maintCollection) {
58              if(icrEntryNumberMax < item.getAwardIndrCostRcvyEntryNbr()) {
59                  icrEntryNumberMax = item.getAwardIndrCostRcvyEntryNbr();
60              }
61          }
62  
63          // addLine.setActive(true); // TODO remove after active indicator fixes
64          addLine.setNewCollectionRecord(true);
65          addLine.setAwardIndrCostRcvyEntryNbr(icrEntryNumberMax + 1);
66          maintCollection.add(addLine);
67          initNewCollectionLine(collectionName);
68      }
69  
70      /**
71       * @see org.kuali.ole.sys.document.FinancialSystemMaintainable#populateChartOfAccountsCodeFields()
72       * 
73       * Special treatment is needed to populate the chart code from the account number field in IndirectCostRecoveryRateDetails, 
74       * as the potential reference account doesn't exist in the collection due to wild cards, which also needs special handling.  
75       */
76      @Override
77      protected void populateChartOfAccountsCodeFields() {
78          // calling super method in case there're reference accounts/collections other than ICR rates
79          super.populateChartOfAccountsCodeFields();
80          
81          PersistableBusinessObject bo = getBusinessObject();        
82          AccountService acctService = SpringContext.getBean(AccountService.class);    
83          PersistableBusinessObject newAccount = getNewCollectionLine(OLEPropertyConstants.INDIRECT_COST_RECOVERY_RATE_DETAILS);
84          String accountNumber = (String)ObjectUtils.getPropertyValue(newAccount, OLEPropertyConstants.ACCOUNT_NUMBER);
85          String coaCode = null;
86          
87          // if accountNumber is wild card, populate chart code with the same wild card
88          if (GeneralLedgerConstants.PosterService.SYMBOL_USE_EXPENDITURE_ENTRY.equals(accountNumber) || 
89              GeneralLedgerConstants.PosterService.SYMBOL_USE_ICR_FROM_ACCOUNT.equals(accountNumber)) {
90              coaCode = accountNumber;
91          }
92          // otherwise do the normal account lookup
93          else {
94              Account account = acctService.getUniqueAccountForAccountNumber(accountNumber);            
95              if (ObjectUtils.isNotNull(account)) {
96                  coaCode = account.getChartOfAccountsCode();
97              }
98          }
99           
100         // populate chart code field
101         try {
102             ObjectUtils.setObjectProperty(newAccount, OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, coaCode); 
103         }
104         catch (Exception e) {
105             LOG.error("Error in setting property value for " + OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
106         } 
107     }    
108     
109 }