| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AgendaItemBo |
|
| 1.3076923076923077;1.308 |
| 1 | /* | |
| 2 | * Copyright 2011 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 1.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.opensource.org/licenses/ecl1.php | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.kuali.rice.krms.impl.repository; | |
| 17 | ||
| 18 | import java.util.ArrayList; | |
| 19 | import java.util.List; | |
| 20 | ||
| 21 | import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; | |
| 22 | import org.kuali.rice.krms.api.repository.agenda.AgendaItem; | |
| 23 | ||
| 24 | /** | |
| 25 | * Agenda Item business object | |
| 26 | * | |
| 27 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 28 | * | |
| 29 | */ | |
| 30 | 0 | public class AgendaItemBo extends PersistableBusinessObjectBase { |
| 31 | ||
| 32 | private String id; | |
| 33 | private String agendaId; | |
| 34 | private String ruleId; | |
| 35 | private String subAgendaId; | |
| 36 | private String whenTrueId; | |
| 37 | private String whenFalseId; | |
| 38 | private String alwaysId; | |
| 39 | ||
| 40 | private AgendaItemBo whenTrue; | |
| 41 | private AgendaItemBo whenFalse; | |
| 42 | private AgendaItemBo always; | |
| 43 | ||
| 44 | public String getUl(AgendaItemBo firstItem) { | |
| 45 | 0 | return ("<ul>" + getUlHelper(firstItem) + "</ul>"); |
| 46 | } | |
| 47 | ||
| 48 | public String getUlHelper(AgendaItemBo item) { | |
| 49 | 0 | StringBuilder sb = new StringBuilder(); |
| 50 | 0 | sb.append("<li>" + ruleId + "</li>"); |
| 51 | 0 | if (whenTrue != null) { |
| 52 | 0 | sb.append("<ul><li>when true</li><ul>"); |
| 53 | 0 | sb.append(getUlHelper(whenTrue)); |
| 54 | 0 | sb.append("</ul></ul>"); |
| 55 | } | |
| 56 | 0 | if (whenFalse != null) { |
| 57 | 0 | sb.append("<ul><li>when false</li><ul>"); |
| 58 | 0 | sb.append(getUlHelper(whenFalse)); |
| 59 | 0 | sb.append("</ul></ul>"); |
| 60 | } | |
| 61 | 0 | if (always != null) { |
| 62 | 0 | sb.append(getUlHelper(always)); |
| 63 | } | |
| 64 | 0 | return sb.toString(); |
| 65 | } | |
| 66 | ||
| 67 | public String getRuleText() { | |
| 68 | 0 | return "Build up rule text string"; |
| 69 | } | |
| 70 | ||
| 71 | // def List<AgendaItemBo> alwaysList | |
| 72 | // def List<AgendaItemBo> whenTrueList | |
| 73 | // def List<AgendaItemBo> whenFalseList | |
| 74 | ||
| 75 | public List<AgendaItemBo> getAlwaysList() { | |
| 76 | 0 | List<AgendaItemBo> results = new ArrayList<AgendaItemBo>(); |
| 77 | ||
| 78 | 0 | AgendaItemBo currentNode = this; |
| 79 | 0 | while (currentNode.always != null) { |
| 80 | 0 | results.add(currentNode.always); |
| 81 | 0 | currentNode = currentNode.always; |
| 82 | } | |
| 83 | ||
| 84 | 0 | return results; |
| 85 | } | |
| 86 | ||
| 87 | /** | |
| 88 | * @return the id | |
| 89 | */ | |
| 90 | public String getId() { | |
| 91 | 0 | return this.id; |
| 92 | } | |
| 93 | ||
| 94 | /** | |
| 95 | * @param id the id to set | |
| 96 | */ | |
| 97 | public void setId(String id) { | |
| 98 | 0 | this.id = id; |
| 99 | 0 | } |
| 100 | ||
| 101 | /** | |
| 102 | * @return the agendaId | |
| 103 | */ | |
| 104 | public String getAgendaId() { | |
| 105 | 0 | return this.agendaId; |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * @param agendaId the agendaId to set | |
| 110 | */ | |
| 111 | public void setAgendaId(String agendaId) { | |
| 112 | 0 | this.agendaId = agendaId; |
| 113 | 0 | } |
| 114 | ||
| 115 | /** | |
| 116 | * @return the ruleId | |
| 117 | */ | |
| 118 | public String getRuleId() { | |
| 119 | 0 | return this.ruleId; |
| 120 | } | |
| 121 | ||
| 122 | /** | |
| 123 | * @param ruleId the ruleId to set | |
| 124 | */ | |
| 125 | public void setRuleId(String ruleId) { | |
| 126 | 0 | this.ruleId = ruleId; |
| 127 | 0 | } |
| 128 | ||
| 129 | /** | |
| 130 | * @return the subAgendaId | |
| 131 | */ | |
| 132 | public String getSubAgendaId() { | |
| 133 | 0 | return this.subAgendaId; |
| 134 | } | |
| 135 | ||
| 136 | /** | |
| 137 | * @param subAgendaId the subAgendaId to set | |
| 138 | */ | |
| 139 | public void setSubAgendaId(String subAgendaId) { | |
| 140 | 0 | this.subAgendaId = subAgendaId; |
| 141 | 0 | } |
| 142 | ||
| 143 | ||
| 144 | /** | |
| 145 | * @return the whenTrueId | |
| 146 | */ | |
| 147 | public String getWhenTrueId() { | |
| 148 | 0 | return this.whenTrueId; |
| 149 | } | |
| 150 | ||
| 151 | /** | |
| 152 | * @param whenTrueId the whenTrueId to set | |
| 153 | */ | |
| 154 | public void setWhenTrueId(String whenTrueId) { | |
| 155 | 0 | this.whenTrueId = whenTrueId; |
| 156 | 0 | } |
| 157 | ||
| 158 | /** | |
| 159 | * @return the whenFalseId | |
| 160 | */ | |
| 161 | public String getWhenFalseId() { | |
| 162 | 0 | return this.whenFalseId; |
| 163 | } | |
| 164 | ||
| 165 | /** | |
| 166 | * @param whenFalseId the whenFalseId to set | |
| 167 | */ | |
| 168 | public void setWhenFalseId(String whenFalseId) { | |
| 169 | 0 | this.whenFalseId = whenFalseId; |
| 170 | 0 | } |
| 171 | ||
| 172 | /** | |
| 173 | * @return the alwaysId | |
| 174 | */ | |
| 175 | public String getAlwaysId() { | |
| 176 | 0 | return this.alwaysId; |
| 177 | } | |
| 178 | ||
| 179 | /** | |
| 180 | * @param alwaysId the alwaysId to set | |
| 181 | */ | |
| 182 | public void setAlwaysId(String alwaysId) { | |
| 183 | 0 | this.alwaysId = alwaysId; |
| 184 | 0 | } |
| 185 | ||
| 186 | /** | |
| 187 | * @return the whenTrue | |
| 188 | */ | |
| 189 | public AgendaItemBo getWhenTrue() { | |
| 190 | 0 | return this.whenTrue; |
| 191 | } | |
| 192 | ||
| 193 | /** | |
| 194 | * @param whenTrue the whenTrue to set | |
| 195 | */ | |
| 196 | public void setWhenTrue(AgendaItemBo whenTrue) { | |
| 197 | 0 | this.whenTrue = whenTrue; |
| 198 | 0 | } |
| 199 | ||
| 200 | /** | |
| 201 | * @return the whenFalse | |
| 202 | */ | |
| 203 | public AgendaItemBo getWhenFalse() { | |
| 204 | 0 | return this.whenFalse; |
| 205 | } | |
| 206 | ||
| 207 | /** | |
| 208 | * @param whenFalse the whenFalse to set | |
| 209 | */ | |
| 210 | public void setWhenFalse(AgendaItemBo whenFalse) { | |
| 211 | 0 | this.whenFalse = whenFalse; |
| 212 | 0 | } |
| 213 | ||
| 214 | /** | |
| 215 | * @return the always | |
| 216 | */ | |
| 217 | public AgendaItemBo getAlways() { | |
| 218 | 0 | return this.always; |
| 219 | } | |
| 220 | ||
| 221 | /** | |
| 222 | * @param always the always to set | |
| 223 | */ | |
| 224 | public void setAlways(AgendaItemBo always) { | |
| 225 | 0 | this.always = always; |
| 226 | 0 | } |
| 227 | ||
| 228 | // public List<AgendaItemBo> getWhenTrueList() { | |
| 229 | // List<AgendaItemBo> results = new ArrayList<AgendaItemBo>(); | |
| 230 | // | |
| 231 | // AgendaItemBo currentNode = this; | |
| 232 | // if (currentNode.whenTrue != null) { | |
| 233 | // results.add(currentNode.whenTrue); | |
| 234 | // currentNode = currentNode.whenTrue; | |
| 235 | // } | |
| 236 | // while (currentNode.always != null) { | |
| 237 | // results.add(currentNode.always); | |
| 238 | // currentNode = currentNode.always; | |
| 239 | // } | |
| 240 | // | |
| 241 | // return results; | |
| 242 | // } | |
| 243 | // | |
| 244 | // public List<AgendaItemBo> getWhenFalseList() { | |
| 245 | // List<AgendaItemBo> results = new ArrayList<AgendaItemBo>(); | |
| 246 | // | |
| 247 | // AgendaItemBo currentNode = this; | |
| 248 | // if (currentNode.whenFalse != null) { | |
| 249 | // results.add(currentNode.whenFalse); | |
| 250 | // currentNode = currentNode.whenFalse; | |
| 251 | // } | |
| 252 | // while (currentNode.always != null) { | |
| 253 | // results.add(currentNode.always); | |
| 254 | // currentNode = currentNode.always; | |
| 255 | // } | |
| 256 | // | |
| 257 | // return results; | |
| 258 | // } | |
| 259 | ||
| 260 | // Would make life in KNS easier to map to related AgendaItemBos, and RuleBos | |
| 261 | ||
| 262 | /** | |
| 263 | * Converts a mutable bo to it's immutable counterpart | |
| 264 | * @param bo the mutable business object | |
| 265 | * @return the immutable object | |
| 266 | */ | |
| 267 | static AgendaItem to(AgendaItemBo bo) { | |
| 268 | 0 | if (bo == null) { return null; } |
| 269 | 0 | org.kuali.rice.krms.api.repository.agenda.AgendaItem.Builder builder = |
| 270 | org.kuali.rice.krms.api.repository.agenda.AgendaItem.Builder.create(bo.getId(), bo.getAgendaId()); | |
| 271 | 0 | builder.setRuleId(bo.getRuleId()); |
| 272 | 0 | builder.setSubAgendaId(bo.getSubAgendaId()); |
| 273 | 0 | builder.setWhenTrueId(bo.getWhenTrueId()); |
| 274 | 0 | builder.setWhenFalseId(bo.getWhenFalseId()); |
| 275 | 0 | builder.setAlwaysId(bo.getAlwaysId()); |
| 276 | ||
| 277 | 0 | return builder.build(); |
| 278 | } | |
| 279 | ||
| 280 | /** | |
| 281 | * Converts a immutable object to it's mutable bo counterpart | |
| 282 | * @param im immutable object | |
| 283 | * @return the mutable bo | |
| 284 | */ | |
| 285 | static AgendaItemBo from(AgendaItem im) { | |
| 286 | 0 | if (im == null) { return null; } |
| 287 | ||
| 288 | 0 | AgendaItemBo bo = new AgendaItemBo(); |
| 289 | 0 | bo.id = im.getId(); |
| 290 | 0 | bo.agendaId = im.getAgendaId(); |
| 291 | 0 | bo.ruleId = im.getRuleId(); |
| 292 | 0 | bo.subAgendaId = im.getSubAgendaId(); |
| 293 | 0 | bo.whenTrueId = im.getWhenTrueId(); |
| 294 | 0 | bo.whenFalseId = im.getWhenFalseId(); |
| 295 | 0 | bo.alwaysId = im.getAlwaysId(); |
| 296 | ||
| 297 | 0 | return bo; |
| 298 | } | |
| 299 | } |