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