1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.repository;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
23 import org.kuali.rice.krms.api.repository.agenda.AgendaItem;
24
25
26
27
28
29
30
31 public class AgendaItemBo extends PersistableBusinessObjectBase {
32
33 private String id;
34 private String agendaId;
35 private String ruleId;
36 private String subAgendaId;
37 private String whenTrueId;
38 private String whenFalseId;
39 private String alwaysId;
40
41 private RuleBo rule;
42
43 private AgendaItemBo whenTrue;
44 private AgendaItemBo whenFalse;
45 private AgendaItemBo always;
46
47 public String getUl(AgendaItemBo firstItem) {
48 return ("<ul>" + getUlHelper(firstItem) + "</ul>");
49 }
50
51 public String getUlHelper(AgendaItemBo item) {
52 StringBuilder sb = new StringBuilder();
53 sb.append("<li>" + ruleId + "</li>");
54 if (whenTrue != null) {
55 sb.append("<ul><li>when true</li><ul>");
56 sb.append(getUlHelper(whenTrue));
57 sb.append("</ul></ul>");
58 }
59 if (whenFalse != null) {
60 sb.append("<ul><li>when false</li><ul>");
61 sb.append(getUlHelper(whenFalse));
62 sb.append("</ul></ul>");
63 }
64 if (always != null) {
65 sb.append(getUlHelper(always));
66 }
67 return sb.toString();
68 }
69
70 public String getRuleText() {
71 StringBuilder resultBuilder = new StringBuilder();
72 if (getRule() != null) {
73 if (StringUtils.isBlank(getRule().getName())) {
74 resultBuilder.append("- unnamed rule -");
75 } else {
76 resultBuilder.append(getRule().getName());
77 }
78 if (!StringUtils.isBlank(getRule().getDescription())) {
79 resultBuilder.append(": ");
80 resultBuilder.append(getRule().getDescription());
81 }
82 } else {
83 throw new IllegalStateException();
84 }
85 return resultBuilder.toString();
86 }
87
88
89
90
91
92 public List<AgendaItemBo> getAlwaysList() {
93 List<AgendaItemBo> results = new ArrayList<AgendaItemBo>();
94
95 AgendaItemBo currentNode = this;
96 while (currentNode.always != null) {
97 results.add(currentNode.always);
98 currentNode = currentNode.always;
99 }
100
101 return results;
102 }
103
104
105
106
107 public String getId() {
108 return this.id;
109 }
110
111
112
113
114 public void setId(String id) {
115 this.id = id;
116 }
117
118
119
120
121 public String getAgendaId() {
122 return this.agendaId;
123 }
124
125
126
127
128 public void setAgendaId(String agendaId) {
129 this.agendaId = agendaId;
130 }
131
132
133
134
135 public String getRuleId() {
136 return this.ruleId;
137 }
138
139
140
141
142 public void setRuleId(String ruleId) {
143 this.ruleId = ruleId;
144 }
145
146
147
148
149 public String getSubAgendaId() {
150 return this.subAgendaId;
151 }
152
153
154
155
156 public void setSubAgendaId(String subAgendaId) {
157 this.subAgendaId = subAgendaId;
158 }
159
160
161
162
163
164 public String getWhenTrueId() {
165 return this.whenTrueId;
166 }
167
168
169
170
171 public void setWhenTrueId(String whenTrueId) {
172 this.whenTrueId = whenTrueId;
173 }
174
175
176
177
178 public String getWhenFalseId() {
179 return this.whenFalseId;
180 }
181
182
183
184
185 public void setWhenFalseId(String whenFalseId) {
186 this.whenFalseId = whenFalseId;
187 }
188
189
190
191
192 public String getAlwaysId() {
193 return this.alwaysId;
194 }
195
196
197
198
199 public void setAlwaysId(String alwaysId) {
200 this.alwaysId = alwaysId;
201 }
202
203
204
205
206 public AgendaItemBo getWhenTrue() {
207 return this.whenTrue;
208 }
209
210
211
212
213 public void setWhenTrue(AgendaItemBo whenTrue) {
214 this.whenTrue = whenTrue;
215 }
216
217
218
219
220 public AgendaItemBo getWhenFalse() {
221 return this.whenFalse;
222 }
223
224
225
226
227 public void setWhenFalse(AgendaItemBo whenFalse) {
228 this.whenFalse = whenFalse;
229 }
230
231
232
233
234 public AgendaItemBo getAlways() {
235 return this.always;
236 }
237
238
239
240
241 public void setAlways(AgendaItemBo always) {
242 this.always = always;
243 }
244
245
246
247
248 public RuleBo getRule() {
249 return this.rule;
250 }
251
252
253
254
255 public void setRule(RuleBo rule) {
256 this.rule = rule;
257 }
258
259
260
261
262
263
264
265 static AgendaItem to(AgendaItemBo bo) {
266 if (bo == null) { return null; }
267 org.kuali.rice.krms.api.repository.agenda.AgendaItem.Builder builder =
268 org.kuali.rice.krms.api.repository.agenda.AgendaItem.Builder.create(bo.getId(), bo.getAgendaId());
269 builder.setRuleId(bo.getRuleId());
270 builder.setSubAgendaId(bo.getSubAgendaId());
271 builder.setWhenTrueId(bo.getWhenTrueId());
272 builder.setWhenFalseId(bo.getWhenFalseId());
273 builder.setAlwaysId(bo.getAlwaysId());
274
275 return builder.build();
276 }
277
278
279
280
281
282
283 static AgendaItemBo from(AgendaItem im) {
284 if (im == null) { return null; }
285
286 AgendaItemBo bo = new AgendaItemBo();
287 bo.id = im.getId();
288 bo.agendaId = im.getAgendaId();
289 bo.ruleId = im.getRuleId();
290 bo.subAgendaId = im.getSubAgendaId();
291 bo.whenTrueId = im.getWhenTrueId();
292 bo.whenFalseId = im.getWhenFalseId();
293 bo.alwaysId = im.getAlwaysId();
294
295 return bo;
296 }
297 }