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