View Javadoc
1   /*
2    * Copyright 2010 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl1.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.document.service.impl;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.sys.businessobject.AccountingLine;
20  import org.kuali.ole.sys.document.service.DynamicNameLabelGenerator;
21  import org.kuali.rice.krad.util.ObjectUtils;
22  
23  public class SubObjectCodeDynamicNameLabelGeneratorImpl implements DynamicNameLabelGenerator {
24  
25      /**
26       * If the subObjectCode reference on the line is refreshable, returns the sub object code's name; otherwise returns null 
27       * @see org.kuali.ole.sys.document.service.DynamicNameLabelGenerator#getDynamicNameLabelFieldName(org.kuali.ole.sys.businessobject.AccountingLine, java.lang.String)
28       */
29      public String getDynamicNameLabelValue(AccountingLine line, String accountingLineProperty) {
30          if (line.getPostingYear() != null && !StringUtils.isBlank(line.getChartOfAccountsCode()) && !StringUtils.isBlank(line.getFinancialSubObjectCode())) {
31              line.refreshReferenceObject("subObjectCode");
32              if (!ObjectUtils.isNull(line.getSubObjectCode())) return line.getSubObjectCode().getFinancialSubObjectCodeName();
33          }
34          return null;
35      }
36  
37      /**
38       * Builds the proper call to loadSubObjectInfo
39       * @see org.kuali.ole.sys.document.service.DynamicNameLabelGenerator#getDynamicNameLabelOnBlur(org.kuali.ole.sys.businessobject.AccountingLine, java.lang.String)
40       */
41      public String getDynamicNameLabelOnBlur(AccountingLine line, String accountingLineProperty) {
42          StringBuilder onBlur = new StringBuilder();
43          onBlur.append("loadSubObjectInfo( '");
44          onBlur.append(line.getPostingYear());
45          onBlur.append("', ");
46          onBlur.append("this.name, '");
47          onBlur.append(getDynamicNameLabelFieldName(line, accountingLineProperty));
48          onBlur.append("' );");
49          return onBlur.toString();
50      }
51  
52      /**
53       * Always returns accountingLineProperty+".subObjectCode.financialSubObjectCodeName"
54       * @see org.kuali.ole.sys.document.service.DynamicNameLabelGenerator#getDynamicNameLabelName(org.kuali.ole.sys.businessobject.AccountingLine, java.lang.String)
55       */
56      public String getDynamicNameLabelFieldName(AccountingLine line, String accountingLineProperty) {
57          return accountingLineProperty+".subObjectCode.financialSubObjectCodeName";
58      }
59  
60  }