001    /*
002     * Copyright 2011 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     */
016    package org.kuali.kfs.gl.businessobject.inquiry;
017    
018    import java.util.ArrayList;
019    import java.util.HashMap;
020    import java.util.List;
021    import java.util.Map;
022    import java.util.Properties;
023    
024    import org.kuali.kfs.gl.Constant;
025    import org.kuali.kfs.gl.GeneralLedgerConstants;
026    import org.kuali.kfs.gl.businessobject.AccountBalance;
027    import org.kuali.kfs.gl.businessobject.AccountBalanceByLevel;
028    import org.kuali.kfs.gl.businessobject.AccountBalanceByObject;
029    import org.kuali.kfs.sys.KFSConstants;
030    import org.kuali.kfs.sys.KFSPropertyConstants;
031    import org.kuali.rice.kns.service.BusinessObjectDictionaryService;
032    import org.kuali.rice.kns.service.LookupService;
033    
034    /**
035     * This class is used to generate the URL for the user-defined attributes for the account balace by level screen. It is entended the
036     * KualiInquirableImpl class, so it covers both the default implementation and customized implemetnation.
037     */
038    public class AccountBalanceByLevelInquirableImpl extends AbstractGeneralLedgerInquirableImpl {
039        private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountBalanceByLevelInquirableImpl.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.kfs.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#buildUserDefinedAttributeKeyList()
049         */
050        protected List buildUserDefinedAttributeKeyList() {
051            List keys = new ArrayList();
052    
053            keys.add(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
054            keys.add(KFSPropertyConstants.ACCOUNT_NUMBER);
055            keys.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
056            keys.add(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
057            keys.add(GeneralLedgerConstants.BalanceInquiryDrillDowns.OBJECT_LEVEL_CODE);
058            keys.add(GeneralLedgerConstants.BalanceInquiryDrillDowns.REPORTING_SORT_CODE);
059            keys.add(Constant.COST_SHARE_OPTION);
060            keys.add(Constant.CONSOLIDATION_OPTION);
061            keys.add(Constant.PENDING_ENTRY_OPTION);
062    
063            return keys;
064        }
065    
066        /**
067         * The addition of the link button
068         * @return a Map of user defined attributes
069         * @see org.kuali.kfs.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getUserDefinedAttributeMap()
070         */
071        protected Map getUserDefinedAttributeMap() {
072            Map userDefinedAttributeMap = new HashMap();
073            userDefinedAttributeMap.put(GeneralLedgerConstants.DummyBusinessObject.LINK_BUTTON_OPTION, "");
074            return userDefinedAttributeMap;
075        }
076    
077        /**
078         * Changes the name of attributes on the fly...in this case, turns the link button to display its name as object code
079         * @param attributeName the attribute to rename
080         * @return a String with the new attribute name
081         * @see org.kuali.kfs.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getAttributeName(java.lang.String)
082         */
083        protected String getAttributeName(String attributeName) {
084            if (attributeName.equals(GeneralLedgerConstants.DummyBusinessObject.LINK_BUTTON_OPTION)) {
085                attributeName = KFSPropertyConstants.OBJECT_CODE;
086            }
087            return attributeName;
088        }
089    
090        /**
091         * If the key name sent in represents an "exclusive field", returns "" as the key value
092         * @param keyName the name of the key that may be changed
093         * @param keyValue the value of the key that may be changed
094         * @return an Object with the perhaps modified value for the key
095         * @see org.kuali.kfs.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getKeyValue(java.lang.String, java.lang.Object)
096         */
097        protected Object getKeyValue(String keyName, Object keyValue) {
098            if (isExclusiveField(keyName, keyValue)) {
099                keyValue = "";
100            }
101            return keyValue;
102        }
103    
104        /**
105         * Justs returns the key name given
106         * @param keyName a key name
107         * @return the key name given
108         * @see org.kuali.kfs.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getKeyName(java.lang.String)
109         */
110        protected String getKeyName(String keyName) {
111            return keyName;
112        }
113    
114        /**
115         * Return a Spring bean for the lookup
116         * @return the name of the Spring bean of the lookup
117         * @see org.kuali.kfs.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getLookupableImplAttributeName()
118         */
119        protected String getLookupableImplAttributeName() {
120            return Constant.GL_LOOKUPABLE_ACCOUNT_BALANCE_BY_OBJECT;
121        }
122    
123        /**
124         * Return the page name of this lookup
125         * @return the page name for all GL lookups
126         * @see org.kuali.kfs.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getBaseUrl()
127         */
128        protected String getBaseUrl() {
129            return KFSConstants.GL_MODIFIED_INQUIRY_ACTION;
130        }
131    
132        /**
133         * Retrieves the business class to use as the basis of an inquiry for the given attribute
134         * @param attributeName the name to build the inquiry link to
135         * @return the Class of the business object that should be inquired on
136         * @see org.kuali.kfs.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#getInquiryBusinessObjectClass(String)
137         */
138        protected Class getInquiryBusinessObjectClass(String attributeName) {
139            Class c = null;
140            /*
141             * if("financialObject.financialObjectLevel.financialConsolidationObjectCode".equals(attributeName)) { c =
142             * AccountBalanceByConsolidation.class; } else
143             */if (GeneralLedgerConstants.BalanceInquiryDrillDowns.OBJECT_LEVEL_CODE.equals(attributeName)) {
144                c = AccountBalance.class;
145            }
146            else if (KFSPropertyConstants.OBJECT_CODE.equals(attributeName)) {
147                c = AccountBalanceByObject.class;
148            }
149            else {
150                c = AccountBalanceByLevel.class;
151            }
152    
153            return c;
154        }
155    
156        /**
157         * Addes the lookup impl attribute to the parameters
158         * @param parameter the parameters used in the lookup
159         * @param attributeName the attribute name that an inquiry URL is being built for
160         * @see org.kuali.kfs.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#addMoreParameters(java.util.Properties, java.lang.String)
161         */
162        protected void addMoreParameters(Properties parameter, String attributeName) {
163            parameter.put(KFSConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME, getLookupableImplAttributeName());
164        }
165    }