View Javadoc

1   /**
2    * Copyright 2005-2013 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.student.core.krms.tree;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.util.tree.Node;
20  import org.kuali.rice.core.api.util.tree.Tree;
21  import org.kuali.rice.krms.dto.PropositionEditor;
22  import org.kuali.rice.krms.dto.RuleEditor;
23  import org.kuali.rice.krms.tree.AbstractTreeBuilder;
24  import org.kuali.rice.krms.tree.RuleCompareTreeBuilder;
25  import org.kuali.rice.krms.tree.node.CompareTreeNode;
26  import org.kuali.rice.krms.util.NaturalLanguageHelper;
27  import org.kuali.rice.krms.util.PropositionTreeUtil;
28  import org.kuali.student.r1.common.rice.StudentIdentityConstants;
29  import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
30  
31  import java.util.List;
32  import java.util.Map;
33  
34  /**
35   * Build a tree to display to different rules next to each other.
36   *
37   * Used on the compare lightbox in KRMS.
38   *
39   * @author Kuali Student Team
40   */
41  public class KSRuleCompareTreeBuilder extends RuleCompareTreeBuilder {
42  
43      private static final long serialVersionUID = 1L;
44  
45      private NaturalLanguageHelper nlHelper;
46  
47      protected String getDescription(PropositionEditor proposition) {
48          if (proposition == null) {
49              return StringUtils.EMPTY;
50          }
51  
52          //Get the natural language for the usage key.
53          Map<String, String> nlMap = proposition.getNaturalLanguage();
54          if(!nlMap.containsKey(this.getNaturalLanguageUsageKey())){
55              this.getNlHelper().setNaturalLanguageForUsage(proposition, this.getNaturalLanguageUsageKey(), StudentIdentityConstants.KS_NAMESPACE_CD);
56          }
57  
58          //Return empty string if nl does is null.
59          String description = nlMap.get(this.getNaturalLanguageUsageKey());
60          if (description==null){
61              return StringUtils.EMPTY;
62          }
63  
64          return description;
65      }
66  
67      public String getNaturalLanguageUsageKey(){
68          return KSKRMSServiceConstants.KRMS_NL_RULE_EDIT;
69      }
70  
71      public NaturalLanguageHelper getNlHelper() {
72          return nlHelper;
73      }
74  
75      public void setNlHelper(NaturalLanguageHelper nlHelper) {
76          this.nlHelper = nlHelper;
77      }
78  
79  }