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.api.repository.proposition.PropositionType;
22  import org.kuali.rice.krms.dto.PropositionEditor;
23  import org.kuali.rice.krms.dto.RuleEditor;
24  import org.kuali.rice.krms.tree.AbstractTreeBuilder;
25  import org.kuali.rice.krms.tree.RuleViewTreeBuilder;
26  import org.kuali.rice.krms.tree.node.TreeNode;
27  import org.kuali.rice.krms.util.NaturalLanguageHelper;
28  import org.kuali.rice.krms.util.PropositionTreeUtil;
29  import org.kuali.student.r1.common.rice.StudentIdentityConstants;
30  import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
31  
32  import java.util.List;
33  import java.util.Map;
34  
35  /**
36   * This is a helper class to build the view tree to be displayed on the manage requisites page on the ui to display
37   * a readonly tree of the rule.
38   *
39   * @author Kuali Student Team
40   */
41  public class KSRuleViewTreeBuilder extends RuleViewTreeBuilder {
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      @Override
68      public String getNaturalLanguageUsageKey() {
69          return KSKRMSServiceConstants.KRMS_NL_PREVIEW;
70      }
71  
72      public NaturalLanguageHelper getNlHelper() {
73          return nlHelper;
74      }
75  
76      public void setNlHelper(NaturalLanguageHelper nlHelper) {
77          this.nlHelper = nlHelper;
78      }
79  }