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.sys.document.service.impl;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.kfs.sys.businessobject.AccountingLine;
020 import org.kuali.kfs.sys.document.service.DynamicNameLabelGenerator;
021 import org.kuali.rice.kns.util.ObjectUtils;
022
023 public class SubObjectCodeDynamicNameLabelGeneratorImpl implements DynamicNameLabelGenerator {
024
025 /**
026 * If the subObjectCode reference on the line is refreshable, returns the sub object code's name; otherwise returns null
027 * @see org.kuali.kfs.sys.document.service.DynamicNameLabelGenerator#getDynamicNameLabelFieldName(org.kuali.kfs.sys.businessobject.AccountingLine, java.lang.String)
028 */
029 public String getDynamicNameLabelValue(AccountingLine line, String accountingLineProperty) {
030 if (line.getPostingYear() != null && !StringUtils.isBlank(line.getChartOfAccountsCode()) && !StringUtils.isBlank(line.getFinancialSubObjectCode())) {
031 line.refreshReferenceObject("subObjectCode");
032 if (!ObjectUtils.isNull(line.getSubObjectCode())) return line.getSubObjectCode().getFinancialSubObjectCodeName();
033 }
034 return null;
035 }
036
037 /**
038 * Builds the proper call to loadSubObjectInfo
039 * @see org.kuali.kfs.sys.document.service.DynamicNameLabelGenerator#getDynamicNameLabelOnBlur(org.kuali.kfs.sys.businessobject.AccountingLine, java.lang.String)
040 */
041 public String getDynamicNameLabelOnBlur(AccountingLine line, String accountingLineProperty) {
042 StringBuilder onBlur = new StringBuilder();
043 onBlur.append("loadSubObjectInfo( '");
044 onBlur.append(line.getPostingYear());
045 onBlur.append("', ");
046 onBlur.append("this.name, '");
047 onBlur.append(getDynamicNameLabelFieldName(line, accountingLineProperty));
048 onBlur.append("' );");
049 return onBlur.toString();
050 }
051
052 /**
053 * Always returns accountingLineProperty+".subObjectCode.financialSubObjectCodeName"
054 * @see org.kuali.kfs.sys.document.service.DynamicNameLabelGenerator#getDynamicNameLabelName(org.kuali.kfs.sys.businessobject.AccountingLine, java.lang.String)
055 */
056 public String getDynamicNameLabelFieldName(AccountingLine line, String accountingLineProperty) {
057 return accountingLineProperty+".subObjectCode.financialSubObjectCodeName";
058 }
059
060 }