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