1 package org.kuali.rice.krms.tree;
2
3 import org.apache.commons.lang.StringEscapeUtils;
4 import org.kuali.rice.core.api.util.tree.Node;
5 import org.kuali.rice.core.api.util.tree.Tree;
6 import org.kuali.rice.krms.api.repository.LogicalOperator;
7 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinitionContract;
8 import org.kuali.rice.krms.api.repository.proposition.PropositionType;
9 import org.kuali.rice.krms.api.repository.rule.RuleDefinitionContract;
10 import org.kuali.rice.krms.dto.PropositionEditor;
11 import org.kuali.rice.krms.dto.RuleEditor;
12 import org.kuali.rice.krms.tree.node.TreeNode;
13 import org.kuali.student.enrollment.class1.krms.dto.EnrolPropositionEditor;
14 import org.kuali.student.enrollment.class1.krms.dto.EnrolRuleEditor;
15
16 import java.util.List;
17
18
19
20
21
22
23
24
25 public class RulePreviewTreeBuilder extends AbstractTreeBuilder{
26
27 @Override
28 protected String buildNodeLabel(RuleDefinitionContract rule, PropositionDefinitionContract prop){
29
30 String prefix = this.getPropositionPrefix((RuleEditor)rule, (PropositionEditor)prop);
31 return prefix + StringEscapeUtils.escapeHtml(this.getDescription(prop));
32 }
33
34 public Tree<TreeNode, String> buildTree(RuleEditor rule) {
35
36 Tree myTree = new Tree<TreeNode, String>();
37
38 Node<TreeNode, String> rootNode = new Node<TreeNode, String>();
39 rootNode.setNodeLabel("root");
40 rootNode.setNodeType("rootNode");
41 rootNode.setData(new TreeNode("Rule:"));
42 myTree.setRootElement(rootNode);
43
44 if (rule == null) {
45 return myTree;
46 }
47
48 PropositionEditor prop = (PropositionEditor) rule.getProposition();
49 buildPreviewTree(rule, rootNode, prop);
50
51
52 if ((rootNode.getChildren() != null) && (rootNode.getChildren().size() > 0)) {
53 Node<TreeNode, String> firstNode = rootNode.getChildren().get(0);
54 if ((firstNode.getChildren() != null) && (firstNode.getChildren().size() > 0)) {
55 firstNode.setNodeType("subruleHeader subruleElement");
56 TreeNode treeNode = firstNode.getData();
57 treeNode.setData("<u>" + treeNode.getData() + ":</u>");
58 }
59 }
60
61 return myTree;
62 }
63
64 private void buildPreviewTree(RuleEditor rule, Node<TreeNode, String> currentNode, PropositionEditor prop) {
65 if (prop != null) {
66
67 Node<TreeNode, String> newNode = new Node<TreeNode, String>();
68 newNode.setNodeLabel(null);
69 newNode.setNodeType("subruleElement");
70
71 TreeNode tNode = new TreeNode(this.buildNodeLabel(rule, prop));
72 tNode.setListItems(this.getListItems(prop));
73 newNode.setData(tNode);
74 tNode.setKey(prop.getKey());
75 currentNode.getChildren().add(newNode);
76
77 if (PropositionType.COMPOUND.getCode().equalsIgnoreCase(prop.getPropositionTypeCode())) {
78
79 boolean first = true;
80 for (PropositionEditor child : prop.getCompoundEditors()) {
81
82 if (!first) {
83
84 Node<TreeNode, String> opNode = new Node<TreeNode, String>();
85 if (LogicalOperator.AND.getCode().equalsIgnoreCase(prop.getCompoundOpCode())) {
86 opNode.setNodeLabel("AND");
87 } else if (LogicalOperator.OR.getCode().equalsIgnoreCase(prop.getCompoundOpCode())) {
88 opNode.setNodeLabel("OR");
89 }
90 opNode.setData(new TreeNode(null));
91 newNode.getChildren().add(opNode);
92
93 }
94 first = false;
95
96 buildPreviewTree(rule, newNode, child);
97 }
98 }
99
100 }
101 }
102
103 public List<String> getListItems(PropositionEditor propositionEditor) {
104 return null;
105 }
106 }