View Javadoc
1   /*
2    * Copyright 2006 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.gl.businessobject.lookup;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.kuali.ole.gl.Constant;
23  import org.kuali.ole.gl.GeneralLedgerConstants;
24  import org.kuali.ole.gl.businessobject.AccountBalance;
25  import org.kuali.ole.gl.businessobject.TransientBalanceInquiryAttributes;
26  import org.kuali.ole.gl.businessobject.inquiry.AccountBalanceByObjectInquirableImpl;
27  import org.kuali.ole.gl.businessobject.inquiry.AccountBalanceInquirableImpl;
28  import org.kuali.ole.gl.service.AccountBalanceService;
29  import org.kuali.ole.sys.OLEConstants;
30  import org.kuali.ole.sys.OLEPropertyConstants;
31  import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl;
32  import org.kuali.rice.kns.lookup.HtmlData;
33  import org.kuali.rice.krad.bo.BusinessObject;
34  import org.kuali.rice.krad.lookup.CollectionIncomplete;
35  
36  /**
37   * An extension of KualiLookupableImpl to support the account balance by object inquiry screen
38   */
39  public class AccountBalanceByObjectLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
40      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountBalanceByObjectLookupableHelperServiceImpl.class);
41  
42      private AccountBalanceService accountBalanceService;
43  
44      public void setAccountBalanceService(AccountBalanceService abs) {
45          accountBalanceService = abs;
46      }
47  
48      /**
49       * Returns the inquiry url for a result field.
50       * 
51       * @param bo the business object instance to build the urls for
52       * @param propertyName the property which links to an inquirable
53       * @return String url to inquiry
54       */
55      @Override
56      public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) {
57          if (GeneralLedgerConstants.DummyBusinessObject.LINK_BUTTON_OPTION.equals(propertyName)) {
58              return (new AccountBalanceByObjectInquirableImpl()).getInquiryUrl(bo, propertyName);
59          }
60          return (new AccountBalanceInquirableImpl()).getInquiryUrl(bo, propertyName);
61      }
62  
63      /**
64       * Uses Lookup Service to provide a basic search.
65       * 
66       * @param fieldValues - Map containing prop name keys and search values
67       * @return List found business objects
68       */
69      public List getSearchResults(Map fieldValues) {
70          LOG.debug("getSearchResults() started");
71  
72          setBackLocation((String) fieldValues.get(OLEConstants.BACK_LOCATION));
73          setDocFormKey((String) fieldValues.get(OLEConstants.DOC_FORM_KEY));
74  
75          BusinessObjectFieldConverter.escapeSingleQuote(fieldValues);
76  
77          String costShareOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.COST_SHARE_OPTION);
78          String pendingEntryOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.PENDING_ENTRY_OPTION);
79          String consolidationOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.CONSOLIDATION_OPTION);
80          boolean isCostShareExcluded = Constant.COST_SHARE_EXCLUDE.equals(costShareOption);
81          int pendingEntryCode = AccountBalanceService.PENDING_NONE;
82          if (GeneralLedgerConstants.PendingEntryOptions.APPROVED.equals(pendingEntryOption)) {
83              pendingEntryCode = AccountBalanceService.PENDING_APPROVED;
84          }
85          else if (GeneralLedgerConstants.PendingEntryOptions.ALL.equals(pendingEntryOption)) {
86              pendingEntryCode = AccountBalanceService.PENDING_ALL;
87          }
88          boolean isConsolidated = Constant.CONSOLIDATION.equals(consolidationOption);
89  
90          String chartOfAccountsCode = (String) fieldValues.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
91          String accountNumber = (String) fieldValues.get(OLEPropertyConstants.ACCOUNT_NUMBER);
92          String subAccountNumber = (String) fieldValues.get(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
93          String financialObjectLevelCode = (String) fieldValues.get(GeneralLedgerConstants.BalanceInquiryDrillDowns.OBJECT_LEVEL_CODE);
94          String financialReportingSortCode = (String) fieldValues.get(GeneralLedgerConstants.BalanceInquiryDrillDowns.REPORTING_SORT_CODE);
95  
96          // Dashes means no sub account number
97          if (OLEConstants.getDashSubAccountNumber().equals(subAccountNumber)) {
98              subAccountNumber = "";
99          }
100 
101         String ufy = (String) fieldValues.get(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR);
102 
103         // TODO Deal with invalid numbers
104         Integer universityFiscalYear = new Integer(Integer.parseInt(ufy));
105 
106         List results = accountBalanceService.findAccountBalanceByObject(universityFiscalYear, chartOfAccountsCode, accountNumber, subAccountNumber, financialObjectLevelCode, financialReportingSortCode, isCostShareExcluded, isConsolidated, pendingEntryCode);
107 
108         // Put the search related stuff in the objects
109         for (Iterator iter = results.iterator(); iter.hasNext();) {
110             AccountBalance ab = (AccountBalance) iter.next();
111 
112             TransientBalanceInquiryAttributes dbo = ab.getDummyBusinessObject();
113             dbo.setConsolidationOption(consolidationOption);
114             dbo.setCostShareOption(costShareOption);
115             dbo.setPendingEntryOption(pendingEntryOption);
116             dbo.setLinkButtonOption(Constant.LOOKUP_BUTTON_VALUE);
117         }
118         return new CollectionIncomplete(results, new Long(results.size()));
119     }
120 }