View Javadoc

1   package org.kuali.rice.krms.tree;
2   
3   import org.apache.commons.lang.StringEscapeUtils;
4   import org.apache.commons.lang.StringUtils;
5   import org.kuali.rice.krms.api.repository.NaturalLanguageTree;
6   import org.kuali.rice.krms.api.repository.RuleManagementService;
7   import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
8   import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
9   import org.kuali.rice.krms.api.repository.proposition.PropositionDefinitionContract;
10  import org.kuali.rice.krms.api.repository.rule.RuleDefinitionContract;
11  import org.kuali.rice.krms.dto.PropositionEditor;
12  import org.kuali.rice.krms.dto.RuleEditor;
13  import org.kuali.student.enrollment.class1.krms.dto.EnrolPropositionEditor;
14  import org.kuali.student.enrollment.class1.krms.dto.EnrolRuleEditor;
15  import org.kuali.student.enrollment.class2.courseoffering.service.decorators.PermissionServiceConstants;
16  import org.kuali.student.krms.naturallanguage.util.KsKrmsConstants;
17  
18  import java.io.Serializable;
19  import java.util.Iterator;
20  import java.util.LinkedList;
21  import java.util.Queue;
22  
23  /**
24   * Created with IntelliJ IDEA.
25   * User: SW
26   * Date: 2013/02/25
27   * Time: 2:12 PM
28   * To change this template use File | Settings | File Templates.
29   */
30  public abstract class AbstractTreeBuilder implements TreeBuilder {
31  
32      private RuleManagementService ruleManagementService;
33  
34      public RuleManagementService getRuleManagementService() {
35          return ruleManagementService;
36      }
37  
38      public void setRuleManagementService(RuleManagementService ruleManagementService) {
39          this.ruleManagementService = ruleManagementService;
40      }
41  
42      protected String buildNodeLabel(RuleDefinitionContract rule, PropositionDefinitionContract prop){
43          return StringEscapeUtils.escapeHtml(this.getDescription(prop));
44      }
45  
46      protected String getDescription(PropositionDefinitionContract proposition) {
47          if (proposition == null) {
48              return StringUtils.EMPTY;
49          }
50  
51          //Return translated nl if exist.
52          if (proposition instanceof PropositionEditor){
53              PropositionEditor editor = (PropositionEditor) proposition;
54              return editor.getNaturalLanguageForUsage(this.getNaturalLanguageUsageKey());
55          }
56  
57          //Return the description
58          if (proposition.getDescription() != null){
59              return proposition.getDescription();
60          }
61  
62          return StringUtils.EMPTY;
63      }
64  
65      protected String getPropositionPrefix(RuleEditor rule, PropositionEditor prop){
66          if (rule == null){
67              return StringUtils.EMPTY;
68          }
69  
70          //Add the proposition with alpha code in the map if it doesn't already exist.
71          if (null == prop.getKey()) {
72              prop.setKey((String) rule.getAlpha().next());
73          }
74  
75          //Build the prefix.
76          return "<b>" + prop.getKey() + ".</b> ";
77      }
78  
79      public String getNaturalLanguageUsageKey(){
80          return  KsKrmsConstants.KRMS_NL_PREVIEW;
81      }
82  
83  }