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.module.external.kc.businessobject.inquiry;
017    
018    import java.util.HashMap;
019    import java.util.Map;
020    import java.util.Properties;
021    
022    import org.apache.commons.lang.StringUtils;
023    import org.kuali.kfs.module.external.kc.KcConstants;
024    import org.kuali.kfs.module.external.kc.KcConstants.AccountCreationDefaults;
025    import org.kuali.kfs.module.external.kc.businessobject.AccountAutoCreateDefaults;
026    import org.kuali.kfs.sys.KFSConstants;
027    import org.kuali.kfs.sys.businessobject.inquiry.KfsInquirableImpl;
028    import org.kuali.rice.kns.bo.BusinessObject;
029    import org.kuali.rice.kns.lookup.HtmlData;
030    import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
031    import org.kuali.rice.kns.util.KNSConstants;
032    import org.kuali.rice.kns.util.ObjectUtils;
033    import org.kuali.rice.kns.util.UrlFactory;
034    
035    /**
036     * Inquirable class for {@link Account}
037     */
038    public class AccountAutoCreateDefInquirable extends KfsInquirableImpl {
039    
040        /**
041         * @see org.kuali.kfs.sys.businessobject.inquiry.KfsInquirableImpl#getInquiryUrl(org.kuali.rice.kns.bo.BusinessObject,
042         *      java.lang.String, boolean)
043         */
044        @Override
045        public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
046            if (KcConstants.ACCOUNT_CREATE_DEFAULT_IDENTIFIER.equals(attributeName)) {
047                String baseUrl = KNSConstants.INQUIRY_ACTION;
048    
049                Properties parameters = new Properties();
050                parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, KFSConstants.START_METHOD);
051                parameters.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, AccountAutoCreateDefaults.class.getName());
052                parameters.put(KFSConstants.DOC_FORM_KEY, "88888888");
053    
054                Map<String, String> inquiryFields = new HashMap<String, String>();
055                String acctIdentifier =  ObjectUtils.getPropertyValue(businessObject, attributeName).toString();
056                if (StringUtils.isBlank(acctIdentifier)) {
057                    return new AnchorHtmlData();
058                }
059                inquiryFields.put(KcConstants.ACCOUNT_CREATE_DEFAULT_IDENTIFIER, acctIdentifier);
060                parameters.put(KcConstants.ACCOUNT_CREATE_DEFAULT_IDENTIFIER, acctIdentifier);
061    
062                return getHyperLink(AccountAutoCreateDefaults.class, inquiryFields, UrlFactory.parameterizeUrl(baseUrl, parameters));
063            }
064    
065            return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
066        }
067    
068    }