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.endow.businessobject.inquiry;
017
018 import java.util.HashMap;
019 import java.util.Map;
020 import java.util.Properties;
021
022 import org.kuali.kfs.module.endow.EndowPropertyConstants;
023 import org.kuali.kfs.module.endow.businessobject.KEMIDCurrentBalance;
024 import org.kuali.kfs.module.endow.businessobject.KEMIDCurrentBalanceDetail;
025 import org.kuali.kfs.sys.KFSConstants;
026 import org.kuali.kfs.sys.businessobject.inquiry.KfsInquirableImpl;
027 import org.kuali.kfs.sys.context.SpringContext;
028 import org.kuali.rice.kns.bo.BusinessObject;
029 import org.kuali.rice.kns.lookup.HtmlData;
030 import org.kuali.rice.kns.service.DateTimeService;
031 import org.kuali.rice.kns.service.KualiConfigurationService;
032 import org.kuali.rice.kns.util.KNSConstants;
033 import org.kuali.rice.kns.util.ObjectUtils;
034 import org.kuali.rice.kns.util.UrlFactory;
035
036 public class KEMIDCurrentBalanceInquirable extends KfsInquirableImpl {
037
038 /**
039 * @see org.kuali.kfs.sys.businessobject.inquiry.KfsInquirableImpl#getInquiryUrl(org.kuali.rice.kns.bo.BusinessObject,
040 * java.lang.String, boolean)
041 */
042 @Override
043 public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
044 KEMIDCurrentBalance currentBalance = (KEMIDCurrentBalance) businessObject;
045 if (EndowPropertyConstants.CURRENT_BAL_TOTAL_MARKET_VALUE.equals(attributeName) && ObjectUtils.isNotNull(currentBalance.getTotalMarketValue())) {
046
047 Properties params = new Properties();
048 params.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, KFSConstants.SEARCH_METHOD);
049 params.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, KEMIDCurrentBalanceDetail.class.getName());
050 params.put(KNSConstants.DOC_FORM_KEY, "88888888");
051 params.put(KFSConstants.HIDE_LOOKUP_RETURN_LINK, "true");
052 params.put(KFSConstants.BACK_LOCATION, SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KNSConstants.APPLICATION_URL_KEY) + "/" + KFSConstants.MAPPING_PORTAL + ".do");
053 params.put(KFSConstants.LOOKUP_READ_ONLY_FIELDS, EndowPropertyConstants.KEMID + "," + EndowPropertyConstants.CURRENT_BAL_PURPOSE_CD + "," + EndowPropertyConstants.CURRENT_BAL_KEMID_BALANCE_DATE + "," + EndowPropertyConstants.CURRENT_BAL_CLOSED_INDICATOR + "," + EndowPropertyConstants.KEMID_CRNT_BAL_KEMID_SHORT_TTL + "," + EndowPropertyConstants.KEMID_CRNT_BAL_PURPOSE_DESC);
054 params.put(EndowPropertyConstants.KEMID, UrlFactory.encode(String.valueOf(currentBalance.getKemid())));
055 params.put(EndowPropertyConstants.CURRENT_BAL_PURPOSE_CD, UrlFactory.encode(currentBalance.getKemidObj().getPurposeCode()));
056 DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
057 params.put(EndowPropertyConstants.CURRENT_BAL_KEMID_BALANCE_DATE, dateTimeService.toDateString(currentBalance.getBalanceDate()));
058 params.put(EndowPropertyConstants.CURRENT_BAL_CLOSED_INDICATOR, currentBalance.getKemidObj().isClose() ? "Yes" : "No");
059 params.put(EndowPropertyConstants.KEMID_CRNT_BAL_KEMID_SHORT_TTL, currentBalance.getKemidObj().getShortTitle());
060
061 if (ObjectUtils.isNotNull(currentBalance.getKemidObj().getPurpose())) {
062 params.put(EndowPropertyConstants.KEMID_CRNT_BAL_PURPOSE_DESC, currentBalance.getKemidObj().getPurpose().getName());
063 }
064
065 String url = UrlFactory.parameterizeUrl(KNSConstants.LOOKUP_ACTION, params);
066
067 Map<String, String> fieldList = new HashMap<String, String>();
068 fieldList.put(EndowPropertyConstants.KEMID, currentBalance.getKemid().toString());
069 fieldList.put(EndowPropertyConstants.CURRENT_BAL_PURPOSE_CD, currentBalance.getKemidObj().getPurposeCode());
070 fieldList.put(EndowPropertyConstants.CURRENT_BAL_KEMID_BALANCE_DATE, dateTimeService.toDateString(currentBalance.getBalanceDate()));
071 fieldList.put(EndowPropertyConstants.CURRENT_BAL_CLOSED_INDICATOR, currentBalance.getKemidObj().isClose() ? "Yes" : "No");
072 fieldList.put(EndowPropertyConstants.KEMID_CRNT_BAL_KEMID_SHORT_TTL, currentBalance.getKemidObj().getShortTitle());
073
074 if (ObjectUtils.isNotNull(currentBalance.getKemidObj().getPurpose())) {
075 fieldList.put(EndowPropertyConstants.KEMID_CRNT_BAL_PURPOSE_DESC, currentBalance.getKemidObj().getPurpose().getName());
076 }
077
078 return getHyperLink(KEMIDCurrentBalanceDetail.class, fieldList, url);
079 }
080 return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
081 }
082
083 }