001/*
002 * Copyright 2006 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 */
016package org.kuali.ole.gl.businessobject.inquiry;
017
018import java.util.ArrayList;
019import java.util.HashMap;
020import java.util.List;
021import java.util.Map;
022import java.util.Properties;
023
024import org.kuali.ole.gl.Constant;
025import org.kuali.ole.gl.businessobject.Balance;
026import org.kuali.ole.sys.OLEConstants;
027import org.kuali.ole.sys.OLEPropertyConstants;
028import org.kuali.ole.sys.businessobject.SystemOptions;
029import org.kuali.ole.sys.context.SpringContext;
030import org.kuali.ole.sys.service.OptionsService;
031import org.kuali.rice.kns.service.BusinessObjectDictionaryService;
032import org.kuali.rice.krad.service.LookupService;
033
034/**
035 * This class is used to generate the URL for the user-defined attributes for available account balace screen. It is entended the
036 * AbstractGeneralLedgerInquirableImpl class, so it covers both the default implementation and customized implemetnation.
037 */
038public class AccountBalanceInquirableImpl extends AbstractGeneralLedgerInquirableImpl {
039    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountBalanceInquirableImpl.class);
040
041    private BusinessObjectDictionaryService dataDictionary;
042    private LookupService lookupService;
043    private Class businessObjectClass;
044
045    /**
046     * Builds the keys for this inquiry.
047     * @return a List of Strings, holding the keys of this inquiry
048     * @see org.kuali.ole.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#buildUserDefinedAttributeKeyList()
049     */
050    protected List buildUserDefinedAttributeKeyList() {
051        List keys = new ArrayList();
052
053        keys.add(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR);
054        keys.add(OLEPropertyConstants.ACCOUNT_NUMBER);
055        keys.add(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
056        keys.add(OLEPropertyConstants.SUB_ACCOUNT_NUMBER);
057        keys.add(OLEPropertyConstants.OBJECT_CODE);
058        keys.add(OLEPropertyConstants.SUB_OBJECT_CODE);
059        keys.add(Constant.CONSOLIDATION_OPTION);
060        keys.add(Constant.PENDING_ENTRY_OPTION);
061
062        return keys;
063    }
064
065    /**
066     * The addition of user attributes - current budget, actual budget, and encumbrance balance
067     * @return a Map of user defined attributes
068     * @see org.kuali.ole.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getUserDefinedAttributeMap()
069     */
070    protected Map getUserDefinedAttributeMap() {
071        Map userDefinedAttributeMap = new HashMap();
072
073        OptionsService os = SpringContext.getBean(OptionsService.class);
074        SystemOptions o = os.getCurrentYearOptions();
075
076        userDefinedAttributeMap.put(OLEPropertyConstants.CURRENT_BUDGET_LINE_BALANCE_AMOUNT, Constant.BALANCE_TYPE_CB);
077        userDefinedAttributeMap.put(OLEPropertyConstants.ACCOUNT_LINE_ACTUALS_BALANCE_AMOUNT, o.getActualFinancialBalanceTypeCd());
078        userDefinedAttributeMap.put(OLEPropertyConstants.ACCOUNT_LINE_ENCUMBRANCE_BALANCE_AMOUNT, OLEConstants.AGGREGATE_ENCUMBRANCE_BALANCE_TYPE_CODE);
079
080        return userDefinedAttributeMap;
081    }
082
083    /**
084     * Changes the name of attributes on the fly...in this case, doesn't do anything
085     * @param attributeName the attribute to rename
086     * @return a String with the new attribute name
087     * @see org.kuali.ole.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getAttributeName(java.lang.String)
088     */
089    protected String getAttributeName(String attributeName) {
090        return attributeName;
091    }
092
093    /**
094     * If the key name sent in represents an "exclusive field", returns "" as the key value
095     * @param keyName the name of the key that may be changed
096     * @param keyValue the value of the key that may be changed
097     * @return an Object with the perhaps modified value for the key
098     * @see org.kuali.ole.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getKeyValue(java.lang.String, java.lang.Object)
099     */
100    protected Object getKeyValue(String keyName, Object keyValue) {
101        if (isExclusiveField(keyName, keyValue)) {
102            keyValue = "";
103        }
104        return keyValue;
105    }
106
107    /**
108     * Justs returns the key name given
109     * @param keyName a key name
110     * @return the key name given
111     * @see org.kuali.ole.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getKeyName(java.lang.String)
112     */
113    protected String getKeyName(String keyName) {
114        return keyName;
115    }
116
117    /**
118     * Return a Spring bean for the drill up lookup, which is the balance lookup
119     * @return the name of the Spring bean of the lookup
120     * @see org.kuali.ole.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getLookupableImplAttributeName()
121     */
122    protected String getLookupableImplAttributeName() {
123        return Constant.GL_LOOKUPABLE_BALANCE;
124    }
125
126    /**
127     * Return the page name of this lookup
128     * @return the page name for inquiry options
129     * @see org.kuali.ole.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getBaseUrl()
130     */
131    protected String getBaseUrl() {
132        return OLEConstants.GL_BALANCE_INQUIRY_ACTION;
133    }
134
135    /**
136     * Retrieves the business class to use as the basis of an inquiry for the given attribute; in this case, it's always Balance
137     * @param attributeName the name to build the inquiry link to
138     * @return the Class of the business object that should be inquired on
139     * @see org.kuali.ole.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getInquiryBusinessObjectClass(String)
140     */
141    protected Class getInquiryBusinessObjectClass(String attributeName) {
142        return Balance.class;
143    }
144
145    /**
146     * Addes the lookup impl and balance type attributes to the parameters
147     * @param parameter the parameters used in the lookup
148     * @param attributeName the attribute name that an inquiry URL is being built for
149     * @see org.kuali.ole.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#addMoreParameters(java.util.Properties, java.lang.String)
150     */
151    protected void addMoreParameters(Properties parameter, String attributeName) {
152        parameter.put(OLEConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME, getLookupableImplAttributeName());
153        parameter.put(Constant.AMOUNT_VIEW_OPTION, Constant.MONTHLY);
154
155        String balanceTypeCode = (String) getUserDefinedAttributeMap().get(getAttributeName(attributeName));
156        parameter.put(OLEPropertyConstants.BALANCE_TYPE_CODE, balanceTypeCode);
157    }
158}