View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.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/ecl2.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 ObjectCodeDynamicNameLabelGeneratorImpl implements DynamicNameLabelGenerator {
24  
25      /**
26       * If the objectCode reference on the line is refreshable, returns the 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.getFinancialObjectCode())) {
31              line.refreshReferenceObject("objectCode");
32              if (!ObjectUtils.isNull(line.getObjectCode())) return line.getObjectCode().getFinancialObjectCodeName();
33          }
34          return null;
35      }
36  
37      /**
38       * Builds the proper call to loadObjectInfo
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("loadObjectInfo( '");
44          onBlur.append(line.getPostingYear());
45          onBlur.append("', '");
46          onBlur.append(accountingLineProperty+".objectType.name");
47          onBlur.append("', '");
48          onBlur.append(accountingLineProperty+".objectTypeCode");
49          onBlur.append("', ");
50          onBlur.append("this.name, '");
51          onBlur.append(getDynamicNameLabelFieldName(line, accountingLineProperty));
52          onBlur.append("' );");
53          return onBlur.toString();
54      }
55  
56      /**
57       * Always returns accountingLineProperty+".objectCode.financialObjectCodeName"
58       * @see org.kuali.ole.sys.document.service.DynamicNameLabelGenerator#getDynamicNameLabelName(org.kuali.ole.sys.businessobject.AccountingLine, java.lang.String)
59       */
60      public String getDynamicNameLabelFieldName(AccountingLine line, String accountingLineProperty) {
61          return accountingLineProperty+".objectCode.financialObjectCodeName";
62      }
63  
64  }