| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krms.impl.ui; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.core.api.util.tree.Node; |
| 20 | |
import org.kuali.rice.krad.document.MaintenanceDocument; |
| 21 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
| 22 | |
import org.kuali.rice.krad.service.SequenceAccessorService; |
| 23 | |
import org.kuali.rice.krad.uif.UifParameters; |
| 24 | |
import org.kuali.rice.krad.util.ObjectUtils; |
| 25 | |
import org.kuali.rice.krad.web.controller.MaintenanceDocumentController; |
| 26 | |
import org.kuali.rice.krad.web.form.MaintenanceForm; |
| 27 | |
import org.kuali.rice.krad.web.form.UifFormBase; |
| 28 | |
import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition; |
| 29 | |
import org.kuali.rice.krms.impl.repository.ActionAttributeBo; |
| 30 | |
import org.kuali.rice.krms.impl.repository.ActionBo; |
| 31 | |
import org.kuali.rice.krms.api.repository.LogicalOperator; |
| 32 | |
import org.kuali.rice.krms.api.repository.proposition.PropositionType; |
| 33 | |
import org.kuali.rice.krms.impl.repository.AgendaBo; |
| 34 | |
import org.kuali.rice.krms.impl.repository.AgendaItemBo; |
| 35 | |
import org.kuali.rice.krms.impl.repository.ContextBoService; |
| 36 | |
import org.kuali.rice.krms.impl.repository.KrmsAttributeDefinitionBo; |
| 37 | |
import org.kuali.rice.krms.impl.repository.KrmsAttributeDefinitionService; |
| 38 | |
import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator; |
| 39 | |
import org.kuali.rice.krms.impl.repository.PropositionBo; |
| 40 | |
import org.kuali.rice.krms.impl.repository.RuleBo; |
| 41 | |
import org.kuali.rice.krms.impl.rule.AgendaEditorBusRule; |
| 42 | |
import org.springframework.stereotype.Controller; |
| 43 | |
import org.springframework.validation.BindingResult; |
| 44 | |
import org.springframework.web.bind.annotation.ModelAttribute; |
| 45 | |
import org.springframework.web.bind.annotation.RequestMapping; |
| 46 | |
import org.springframework.web.servlet.ModelAndView; |
| 47 | |
|
| 48 | |
import javax.servlet.http.HttpServletRequest; |
| 49 | |
import javax.servlet.http.HttpServletResponse; |
| 50 | |
import java.util.ArrayList; |
| 51 | |
import java.util.HashMap; |
| 52 | |
import java.util.HashSet; |
| 53 | |
import java.util.List; |
| 54 | |
import java.util.Map; |
| 55 | |
import java.util.Set; |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
@Controller |
| 62 | |
@RequestMapping(value = org.kuali.rice.krms.impl.util.KrmsImplConstants.WebPaths.AGENDA_EDITOR_PATH) |
| 63 | 0 | public class AgendaEditorController extends MaintenanceDocumentController { |
| 64 | |
|
| 65 | |
private SequenceAccessorService sequenceAccessorService; |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
@RequestMapping(params = "methodToCall=" + "refresh") |
| 73 | |
@Override |
| 74 | |
public ModelAndView refresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 75 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 76 | 0 | ModelAndView modelAndView = super.refresh(form, result, request, response); |
| 77 | |
|
| 78 | |
|
| 79 | 0 | MaintenanceForm maintenanceForm = (MaintenanceForm) form; |
| 80 | 0 | AgendaEditor agendaEditor = ((AgendaEditor) maintenanceForm.getDocument().getNewMaintainableObject().getDataObject()); |
| 81 | 0 | if (!StringUtils.equals(agendaEditor.getOldContextId(), agendaEditor.getAgenda().getContextId())) { |
| 82 | 0 | agendaEditor.setOldContextId(agendaEditor.getAgenda().getContextId()); |
| 83 | |
|
| 84 | 0 | String namespace = ""; |
| 85 | 0 | if (!StringUtils.isBlank(agendaEditor.getAgenda().getContextId())) { |
| 86 | 0 | namespace = getContextBoService().getContextByContextId(agendaEditor.getAgenda().getContextId()).getNamespace(); |
| 87 | |
} |
| 88 | |
|
| 89 | 0 | for (AgendaItemBo agendaItem : agendaEditor.getAgenda().getItems()) { |
| 90 | 0 | agendaItem.getRule().setNamespace(namespace); |
| 91 | 0 | for (ActionBo action : agendaItem.getRule().getActions()) { |
| 92 | 0 | action.setNamespace(namespace); |
| 93 | |
} |
| 94 | |
} |
| 95 | |
} |
| 96 | 0 | return modelAndView; |
| 97 | |
} |
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
@RequestMapping(params = "methodToCall=" + "goToAddRule") |
| 103 | |
public ModelAndView goToAddRule(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 104 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 105 | 0 | setAgendaItemLine(form, null); |
| 106 | |
|
| 107 | 0 | form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, "AgendaEditorView-AddRule-Page"); |
| 108 | 0 | return super.navigate(form, result, request, response); |
| 109 | |
} |
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
private void setAgendaItemLine(UifFormBase form, AgendaItemBo agendaItem) { |
| 120 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 121 | 0 | if (agendaItem == null) { |
| 122 | 0 | RuleBo rule = new RuleBo(); |
| 123 | 0 | if (StringUtils.isBlank(agendaEditor.getAgenda().getContextId())) { |
| 124 | 0 | rule.setNamespace(""); |
| 125 | |
} else { |
| 126 | 0 | rule.setNamespace(getContextBoService().getContextByContextId(agendaEditor.getAgenda().getContextId()).getNamespace()); |
| 127 | |
} |
| 128 | 0 | agendaItem = new AgendaItemBo(); |
| 129 | 0 | agendaItem.setRule(rule); |
| 130 | 0 | agendaEditor.setAgendaItemLine(agendaItem); |
| 131 | 0 | } else { |
| 132 | |
|
| 133 | 0 | agendaEditor.setAgendaItemLine((AgendaItemBo) ObjectUtils.deepCopy(agendaItem)); |
| 134 | |
} |
| 135 | |
|
| 136 | |
|
| 137 | 0 | if (agendaItem.getRule().getActions().isEmpty()) { |
| 138 | 0 | ActionBo actionBo = new ActionBo(); |
| 139 | 0 | actionBo.setNamespace(agendaItem.getRule().getNamespace()); |
| 140 | 0 | actionBo.setRuleId(agendaItem.getRule().getId()); |
| 141 | 0 | actionBo.setSequenceNumber(1); |
| 142 | 0 | agendaEditor.setAgendaItemLineRuleAction(actionBo); |
| 143 | 0 | } else { |
| 144 | 0 | agendaEditor.setAgendaItemLineRuleAction(agendaItem.getRule().getActions().get(0)); |
| 145 | |
} |
| 146 | |
|
| 147 | 0 | agendaEditor.setCustomRuleActionAttributesMap(agendaEditor.getAgendaItemLineRuleAction().getAttributes()); |
| 148 | 0 | } |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
private AgendaItemBo getAgendaItemLine(UifFormBase form) { |
| 157 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 158 | 0 | return agendaEditor.getAgendaItemLine(); |
| 159 | |
} |
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
private String getSelectedAgendaItemId(UifFormBase form) { |
| 168 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 169 | 0 | return agendaEditor.getSelectedAgendaItemId(); |
| 170 | |
} |
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
private void setCutAgendaItemId(UifFormBase form, String cutAgendaItemId) { |
| 179 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 180 | 0 | agendaEditor.setCutAgendaItemId(cutAgendaItemId); |
| 181 | 0 | } |
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
private String getCutAgendaItemId(UifFormBase form) { |
| 190 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 191 | 0 | return agendaEditor.getCutAgendaItemId(); |
| 192 | |
} |
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
@RequestMapping(params = "methodToCall=" + "goToEditRule") |
| 198 | |
public ModelAndView goToEditRule(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 199 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 200 | |
|
| 201 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 202 | |
|
| 203 | 0 | AgendaItemBo firstItem = getFirstAgendaItem(agendaEditor.getAgenda()); |
| 204 | 0 | String selectedItemId = agendaEditor.getSelectedAgendaItemId(); |
| 205 | 0 | AgendaItemBo node = getAgendaItemById(firstItem, selectedItemId); |
| 206 | |
|
| 207 | 0 | setAgendaItemLine(form, node); |
| 208 | |
|
| 209 | 0 | form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, "AgendaEditorView-EditRule-Page"); |
| 210 | 0 | return super.navigate(form, result, request, response); |
| 211 | |
} |
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
@RequestMapping(params = "methodToCall=" + "addRule") |
| 217 | |
public ModelAndView addRule(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 218 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 219 | |
|
| 220 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 221 | 0 | AgendaBo agenda = agendaEditor.getAgenda(); |
| 222 | 0 | AgendaItemBo newAgendaItem = agendaEditor.getAgendaItemLine(); |
| 223 | |
|
| 224 | 0 | updateRuleAction(agendaEditor); |
| 225 | |
|
| 226 | 0 | if (agenda.getItems() == null) { |
| 227 | 0 | agenda.setItems(new ArrayList<AgendaItemBo>()); |
| 228 | |
} |
| 229 | |
|
| 230 | 0 | AgendaEditorBusRule rule = new AgendaEditorBusRule(); |
| 231 | 0 | MaintenanceForm maintenanceForm = (MaintenanceForm) form; |
| 232 | 0 | MaintenanceDocument document = maintenanceForm.getDocument(); |
| 233 | 0 | if (rule.processAgendaItemBusinessRules(document)) { |
| 234 | 0 | newAgendaItem.setId(getSequenceAccessorService().getNextAvailableSequenceNumber("KRMS_AGENDA_ITM_S") |
| 235 | |
.toString()); |
| 236 | 0 | newAgendaItem.setAgendaId(getCreateAgendaId(agenda)); |
| 237 | 0 | if (agenda.getFirstItemId() == null) { |
| 238 | 0 | agenda.setFirstItemId(newAgendaItem.getId()); |
| 239 | |
} else { |
| 240 | |
|
| 241 | 0 | String selectedAgendaItemId = getSelectedAgendaItemId(form); |
| 242 | 0 | if (StringUtils.isBlank(selectedAgendaItemId)) { |
| 243 | |
|
| 244 | 0 | AgendaItemBo node = getFirstAgendaItem(agenda); |
| 245 | 0 | while (node.getAlways() != null) { |
| 246 | 0 | node = node.getAlways(); |
| 247 | |
} |
| 248 | 0 | node.setAlwaysId(newAgendaItem.getId()); |
| 249 | 0 | node.setAlways(newAgendaItem); |
| 250 | 0 | } else { |
| 251 | |
|
| 252 | 0 | AgendaItemBo firstItem = getFirstAgendaItem(agenda); |
| 253 | 0 | AgendaItemBo node = getAgendaItemById(firstItem, selectedAgendaItemId); |
| 254 | 0 | newAgendaItem.setAlwaysId(node.getAlwaysId()); |
| 255 | 0 | newAgendaItem.setAlways(node.getAlways()); |
| 256 | 0 | node.setAlwaysId(newAgendaItem.getId()); |
| 257 | 0 | node.setAlways(newAgendaItem); |
| 258 | |
} |
| 259 | |
} |
| 260 | |
|
| 261 | 0 | agenda.getItems().add(newAgendaItem); |
| 262 | |
|
| 263 | 0 | form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, "AgendaEditorView-Agenda-Page"); |
| 264 | |
} else { |
| 265 | 0 | form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, "AgendaEditorView-AddRule-Page"); |
| 266 | |
} |
| 267 | 0 | return super.navigate(form, result, request, response); |
| 268 | |
} |
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
private String getCreateAgendaId(AgendaBo agenda) { |
| 274 | 0 | if (agenda.getId() == null) { |
| 275 | 0 | agenda.setId(getSequenceAccessorService().getNextAvailableSequenceNumber("KRMS_AGENDA_S").toString()); |
| 276 | |
} |
| 277 | 0 | return agenda.getId(); |
| 278 | |
} |
| 279 | |
|
| 280 | |
private void updateRuleAction(AgendaEditor agendaEditor) { |
| 281 | 0 | agendaEditor.getAgendaItemLine().getRule().setActions(new ArrayList<ActionBo>()); |
| 282 | 0 | if (StringUtils.isNotBlank(agendaEditor.getAgendaItemLineRuleAction().getTypeId())) { |
| 283 | 0 | updateRuleActionAttributes(agendaEditor.getCustomRuleActionAttributesMap(), agendaEditor.getAgendaItemLineRuleAction()); |
| 284 | 0 | agendaEditor.getAgendaItemLine().getRule().getActions().add(agendaEditor.getAgendaItemLineRuleAction()); |
| 285 | |
} |
| 286 | 0 | } |
| 287 | |
|
| 288 | |
private void updateRuleActionAttributes(Map<String, String> customRuleActionAttributeMap, ActionBo action) { |
| 289 | 0 | Set<ActionAttributeBo> attributes = new HashSet<ActionAttributeBo>(); |
| 290 | |
|
| 291 | 0 | Map<String, KrmsAttributeDefinition> attributeDefinitionMap = buildAttributeDefinitionMap(action.getTypeId()); |
| 292 | |
|
| 293 | 0 | for (Map.Entry<String, String> entry : customRuleActionAttributeMap.entrySet()) { |
| 294 | 0 | KrmsAttributeDefinition attrDef = attributeDefinitionMap.get(entry.getKey()); |
| 295 | |
|
| 296 | 0 | if (attrDef != null) { |
| 297 | 0 | ActionAttributeBo attributeBo = new ActionAttributeBo(); |
| 298 | 0 | attributeBo.setActionId(action.getId()); |
| 299 | 0 | attributeBo.setAttributeDefinitionId(attrDef.getId()); |
| 300 | 0 | attributeBo.setValue(entry.getValue()); |
| 301 | 0 | attributeBo.setAttributeDefinition(KrmsAttributeDefinitionBo.from(attrDef)); |
| 302 | 0 | attributes.add(attributeBo); |
| 303 | |
} |
| 304 | 0 | } |
| 305 | 0 | action.setAttributeBos(attributes); |
| 306 | 0 | } |
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
private Map<String, KrmsAttributeDefinition> buildAttributeDefinitionMap(String actionTypeId) { |
| 315 | 0 | KrmsAttributeDefinitionService attributeDefinitionService = |
| 316 | |
KrmsRepositoryServiceLocator.getKrmsAttributeDefinitionService(); |
| 317 | |
|
| 318 | |
|
| 319 | 0 | Map<String, KrmsAttributeDefinition> attributeDefinitionMap = new HashMap<String, KrmsAttributeDefinition>(); |
| 320 | |
|
| 321 | 0 | List<KrmsAttributeDefinition> attributeDefinitions = |
| 322 | |
attributeDefinitionService.findAttributeDefinitionsByType(actionTypeId); |
| 323 | |
|
| 324 | 0 | for (KrmsAttributeDefinition attributeDefinition : attributeDefinitions) { |
| 325 | 0 | attributeDefinitionMap.put(attributeDefinition.getName(), attributeDefinition); |
| 326 | |
} |
| 327 | 0 | return attributeDefinitionMap; |
| 328 | |
} |
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
@RequestMapping(params = "methodToCall=" + "editRule") |
| 334 | |
public ModelAndView editRule(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 335 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 336 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 337 | |
|
| 338 | 0 | AgendaItemBo firstItem = getFirstAgendaItem(agendaEditor.getAgenda()); |
| 339 | 0 | AgendaItemBo node = getAgendaItemById(firstItem, getSelectedAgendaItemId(form)); |
| 340 | 0 | AgendaItemBo agendaItemLine = getAgendaItemLine(form); |
| 341 | |
|
| 342 | 0 | updateRuleAction(agendaEditor); |
| 343 | |
|
| 344 | 0 | AgendaEditorBusRule rule = new AgendaEditorBusRule(); |
| 345 | 0 | MaintenanceForm maintenanceForm = (MaintenanceForm) form; |
| 346 | 0 | MaintenanceDocument document = maintenanceForm.getDocument(); |
| 347 | 0 | if (rule.processAgendaItemBusinessRules(document)) { |
| 348 | 0 | node.setRule(agendaItemLine.getRule()); |
| 349 | 0 | form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, "AgendaEditorView-Agenda-Page"); |
| 350 | |
} else { |
| 351 | 0 | form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, "AgendaEditorView-EditRule-Page"); |
| 352 | |
} |
| 353 | 0 | return super.navigate(form, result, request, response); |
| 354 | |
} |
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
|
| 361 | |
private AgendaItemInstanceChildAccessor getLastChildsAlwaysAccessor(AgendaItemInstanceChildAccessor instanceAccessor) { |
| 362 | 0 | AgendaItemBo next = instanceAccessor.getChild(); |
| 363 | 0 | if (next == null) return instanceAccessor; |
| 364 | 0 | while (next.getAlways() != null) { next = next.getAlways(); }; |
| 365 | 0 | return new AgendaItemInstanceChildAccessor(AgendaItemChildAccessor.always, next); |
| 366 | |
} |
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | |
|
| 372 | |
|
| 373 | |
private AgendaItemInstanceChildAccessor getInstanceAccessorToChild(AgendaItemBo parent, String agendaItemId) { |
| 374 | |
|
| 375 | |
|
| 376 | 0 | for (AgendaItemChildAccessor levelOrderChildAccessor : AgendaItemChildAccessor.children) { |
| 377 | |
|
| 378 | 0 | AgendaItemBo next = levelOrderChildAccessor.getChild(parent); |
| 379 | |
|
| 380 | |
|
| 381 | 0 | if (next != null && agendaItemId.equals(next.getId())) return new AgendaItemInstanceChildAccessor(levelOrderChildAccessor, parent); |
| 382 | |
|
| 383 | |
|
| 384 | 0 | while (next != null && next.getAlwaysId() != null) { |
| 385 | 0 | if (next.getAlwaysId().equals(agendaItemId)) return new AgendaItemInstanceChildAccessor(AgendaItemChildAccessor.always, next); |
| 386 | |
|
| 387 | 0 | next = next.getAlways(); |
| 388 | |
} |
| 389 | |
} |
| 390 | |
|
| 391 | 0 | return null; |
| 392 | |
} |
| 393 | |
|
| 394 | |
@RequestMapping(params = "methodToCall=" + "ajaxRefresh") |
| 395 | |
public ModelAndView ajaxRefresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 396 | |
HttpServletRequest request, HttpServletResponse response) |
| 397 | |
throws Exception { |
| 398 | |
|
| 399 | 0 | return super.updateComponent(form, result, request, response); |
| 400 | |
} |
| 401 | |
|
| 402 | |
@RequestMapping(params = "methodToCall=" + "moveUp") |
| 403 | |
public ModelAndView moveUp(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 404 | |
HttpServletRequest request, HttpServletResponse response) |
| 405 | |
throws Exception { |
| 406 | 0 | moveSelectedSubtreeUp(form); |
| 407 | |
|
| 408 | 0 | return super.refresh(form, result, request, response); |
| 409 | |
} |
| 410 | |
|
| 411 | |
@RequestMapping(params = "methodToCall=" + "ajaxMoveUp") |
| 412 | |
public ModelAndView ajaxMoveUp(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 413 | |
HttpServletRequest request, HttpServletResponse response) |
| 414 | |
throws Exception { |
| 415 | 0 | moveSelectedSubtreeUp(form); |
| 416 | |
|
| 417 | |
|
| 418 | 0 | return super.updateComponent(form, result, request, response); |
| 419 | |
} |
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
private void moveSelectedSubtreeUp(UifFormBase form) { |
| 427 | |
|
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
|
| 432 | |
|
| 433 | |
|
| 434 | |
|
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
|
| 444 | |
|
| 445 | |
|
| 446 | |
|
| 447 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 448 | |
|
| 449 | 0 | AgendaItemBo firstItem = getFirstAgendaItem(agendaEditor.getAgenda()); |
| 450 | |
|
| 451 | 0 | String selectedItemId = agendaEditor.getSelectedAgendaItemId(); |
| 452 | 0 | AgendaItemBo node = getAgendaItemById(firstItem, selectedItemId); |
| 453 | 0 | AgendaItemBo parent = getParent(firstItem, selectedItemId); |
| 454 | 0 | AgendaItemBo parentsOlderCousin = (parent == null) ? null : getNextOldestOfSameGeneration(firstItem, parent); |
| 455 | |
|
| 456 | 0 | AgendaItemChildAccessor childAccessor = getOldestChildAccessor(node, parent); |
| 457 | 0 | if (childAccessor != null) { |
| 458 | 0 | if (childAccessor == AgendaItemChildAccessor.whenFalse) { |
| 459 | |
|
| 460 | 0 | AgendaItemInstanceChildAccessor youngestWhenTrueSiblingInsertionPoint = |
| 461 | |
getLastChildsAlwaysAccessor(new AgendaItemInstanceChildAccessor(AgendaItemChildAccessor.whenTrue, parent)); |
| 462 | 0 | youngestWhenTrueSiblingInsertionPoint.setChild(node); |
| 463 | 0 | AgendaItemChildAccessor.whenFalse.setChild(parent, node.getAlways()); |
| 464 | 0 | AgendaItemChildAccessor.always.setChild(node, null); |
| 465 | |
|
| 466 | 0 | } else if (parentsOlderCousin != null) { |
| 467 | |
|
| 468 | 0 | AgendaItemInstanceChildAccessor youngestWhenFalseSiblingInsertionPoint = |
| 469 | |
getLastChildsAlwaysAccessor(new AgendaItemInstanceChildAccessor(AgendaItemChildAccessor.whenFalse, parentsOlderCousin)); |
| 470 | 0 | youngestWhenFalseSiblingInsertionPoint.setChild(node); |
| 471 | 0 | AgendaItemChildAccessor.whenTrue.setChild(parent, node.getAlways()); |
| 472 | 0 | AgendaItemChildAccessor.always.setChild(node, null); |
| 473 | 0 | } |
| 474 | 0 | } else if (!selectedItemId.equals(firstItem.getId())) { |
| 475 | |
|
| 476 | 0 | AgendaItemBo bogusRootNode = null; |
| 477 | 0 | if (parent == null) { |
| 478 | |
|
| 479 | 0 | bogusRootNode = new AgendaItemBo(); |
| 480 | 0 | AgendaItemChildAccessor.whenTrue.setChild(bogusRootNode, firstItem); |
| 481 | 0 | parent = bogusRootNode; |
| 482 | |
} |
| 483 | |
|
| 484 | |
|
| 485 | 0 | AgendaItemInstanceChildAccessor accessorToSelectedNode = getInstanceAccessorToChild(parent, node.getId()); |
| 486 | 0 | AgendaItemBo olderSibling = accessorToSelectedNode.getInstance(); |
| 487 | 0 | AgendaItemInstanceChildAccessor accessorToOlderSibling = getInstanceAccessorToChild(parent, olderSibling.getId()); |
| 488 | |
|
| 489 | 0 | accessorToOlderSibling.setChild(node); |
| 490 | 0 | accessorToSelectedNode.setChild(node.getAlways()); |
| 491 | 0 | AgendaItemChildAccessor.always.setChild(node, olderSibling); |
| 492 | |
|
| 493 | 0 | if (bogusRootNode != null) { |
| 494 | |
|
| 495 | 0 | agendaEditor.getAgenda().setFirstItemId(bogusRootNode.getWhenTrueId()); |
| 496 | |
} |
| 497 | |
} |
| 498 | 0 | } |
| 499 | |
|
| 500 | |
@RequestMapping(params = "methodToCall=" + "moveDown") |
| 501 | |
public ModelAndView moveDown(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 502 | |
HttpServletRequest request, HttpServletResponse response) |
| 503 | |
throws Exception { |
| 504 | 0 | moveSelectedSubtreeDown(form); |
| 505 | |
|
| 506 | 0 | return super.refresh(form, result, request, response); |
| 507 | |
} |
| 508 | |
|
| 509 | |
@RequestMapping(params = "methodToCall=" + "ajaxMoveDown") |
| 510 | |
public ModelAndView ajaxMoveDown(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 511 | |
HttpServletRequest request, HttpServletResponse response) |
| 512 | |
throws Exception { |
| 513 | 0 | moveSelectedSubtreeDown(form); |
| 514 | |
|
| 515 | |
|
| 516 | 0 | return super.updateComponent(form, result, request, response); |
| 517 | |
} |
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
|
| 522 | |
|
| 523 | |
|
| 524 | |
private void moveSelectedSubtreeDown(UifFormBase form) { |
| 525 | |
|
| 526 | |
|
| 527 | |
|
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
|
| 538 | |
|
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 546 | |
|
| 547 | 0 | AgendaItemBo firstItem = getFirstAgendaItem(agendaEditor.getAgenda()); |
| 548 | |
|
| 549 | 0 | String selectedItemId = agendaEditor.getSelectedAgendaItemId(); |
| 550 | 0 | AgendaItemBo node = getAgendaItemById(firstItem, selectedItemId); |
| 551 | 0 | AgendaItemBo parent = getParent(firstItem, selectedItemId); |
| 552 | 0 | AgendaItemBo parentsYoungerCousin = (parent == null) ? null : getNextYoungestOfSameGeneration(firstItem, parent); |
| 553 | |
|
| 554 | 0 | if (node.getAlways() == null && parent != null) { |
| 555 | |
|
| 556 | 0 | if (parent.getWhenTrue() != null && isSiblings(parent.getWhenTrue(), node)) { |
| 557 | |
|
| 558 | |
|
| 559 | 0 | AgendaItemInstanceChildAccessor accessorToSelectedNode = getInstanceAccessorToChild(parent, node.getId()); |
| 560 | 0 | accessorToSelectedNode.setChild(null); |
| 561 | |
|
| 562 | 0 | AgendaItemBo parentsFirstChild = parent.getWhenFalse(); |
| 563 | 0 | AgendaItemChildAccessor.whenFalse.setChild(parent, node); |
| 564 | 0 | AgendaItemChildAccessor.always.setChild(node, parentsFirstChild); |
| 565 | 0 | } else if (parentsYoungerCousin != null) { |
| 566 | |
|
| 567 | |
|
| 568 | 0 | AgendaItemInstanceChildAccessor accessorToSelectedNode = getInstanceAccessorToChild(parent, node.getId()); |
| 569 | 0 | accessorToSelectedNode.setChild(null); |
| 570 | |
|
| 571 | 0 | AgendaItemBo parentsYoungerCousinsFirstChild = parentsYoungerCousin.getWhenTrue(); |
| 572 | 0 | AgendaItemChildAccessor.whenTrue.setChild(parentsYoungerCousin, node); |
| 573 | 0 | AgendaItemChildAccessor.always.setChild(node, parentsYoungerCousinsFirstChild); |
| 574 | 0 | } |
| 575 | 0 | } else if (node.getAlways() != null) { |
| 576 | |
|
| 577 | 0 | AgendaItemBo bogusRootNode = null; |
| 578 | 0 | if (parent == null) { |
| 579 | |
|
| 580 | 0 | bogusRootNode = new AgendaItemBo(); |
| 581 | 0 | AgendaItemChildAccessor.whenFalse.setChild(bogusRootNode, firstItem); |
| 582 | 0 | parent = bogusRootNode; |
| 583 | |
} |
| 584 | |
|
| 585 | |
|
| 586 | 0 | AgendaItemInstanceChildAccessor accessorToSelectedNode = getInstanceAccessorToChild(parent, node.getId()); |
| 587 | 0 | AgendaItemBo youngerSibling = node.getAlways(); |
| 588 | 0 | accessorToSelectedNode.setChild(youngerSibling); |
| 589 | 0 | AgendaItemChildAccessor.always.setChild(node, youngerSibling.getAlways()); |
| 590 | 0 | AgendaItemChildAccessor.always.setChild(youngerSibling, node); |
| 591 | |
|
| 592 | 0 | if (bogusRootNode != null) { |
| 593 | |
|
| 594 | 0 | agendaEditor.getAgenda().setFirstItemId(bogusRootNode.getWhenFalseId()); |
| 595 | |
} |
| 596 | |
} |
| 597 | 0 | } |
| 598 | |
|
| 599 | |
@RequestMapping(params = "methodToCall=" + "moveLeft") |
| 600 | |
public ModelAndView moveLeft(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 601 | |
HttpServletRequest request, HttpServletResponse response) |
| 602 | |
throws Exception { |
| 603 | 0 | moveSelectedSubtreeLeft(form); |
| 604 | |
|
| 605 | 0 | return super.refresh(form, result, request, response); |
| 606 | |
} |
| 607 | |
|
| 608 | |
@RequestMapping(params = "methodToCall=" + "ajaxMoveLeft") |
| 609 | |
public ModelAndView ajaxMoveLeft(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 610 | |
HttpServletRequest request, HttpServletResponse response) |
| 611 | |
throws Exception { |
| 612 | |
|
| 613 | 0 | moveSelectedSubtreeLeft(form); |
| 614 | |
|
| 615 | |
|
| 616 | 0 | return super.updateComponent(form, result, request, response); |
| 617 | |
} |
| 618 | |
|
| 619 | |
|
| 620 | |
|
| 621 | |
|
| 622 | |
|
| 623 | |
|
| 624 | |
private void moveSelectedSubtreeLeft(UifFormBase form) { |
| 625 | |
|
| 626 | |
|
| 627 | |
|
| 628 | |
|
| 629 | |
|
| 630 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 631 | |
|
| 632 | 0 | AgendaItemBo firstItem = getFirstAgendaItem(agendaEditor.getAgenda()); |
| 633 | |
|
| 634 | 0 | String selectedItemId = agendaEditor.getSelectedAgendaItemId(); |
| 635 | 0 | AgendaItemBo node = getAgendaItemById(firstItem, selectedItemId); |
| 636 | 0 | AgendaItemBo parent = getParent(firstItem, selectedItemId); |
| 637 | |
|
| 638 | 0 | if (parent != null) { |
| 639 | 0 | AgendaItemInstanceChildAccessor accessorToSelectedNode = getInstanceAccessorToChild(parent, node.getId()); |
| 640 | 0 | accessorToSelectedNode.setChild(node.getAlways()); |
| 641 | |
|
| 642 | 0 | AgendaItemChildAccessor.always.setChild(node, parent.getAlways()); |
| 643 | 0 | AgendaItemChildAccessor.always.setChild(parent, node); |
| 644 | |
} |
| 645 | 0 | } |
| 646 | |
|
| 647 | |
|
| 648 | |
@RequestMapping(params = "methodToCall=" + "moveRight") |
| 649 | |
public ModelAndView moveRight(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 650 | |
HttpServletRequest request, HttpServletResponse response) |
| 651 | |
throws Exception { |
| 652 | |
|
| 653 | 0 | moveSelectedSubtreeRight(form); |
| 654 | |
|
| 655 | 0 | return super.refresh(form, result, request, response); |
| 656 | |
} |
| 657 | |
|
| 658 | |
@RequestMapping(params = "methodToCall=" + "ajaxMoveRight") |
| 659 | |
public ModelAndView ajaxMoveRight(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 660 | |
HttpServletRequest request, HttpServletResponse response) |
| 661 | |
throws Exception { |
| 662 | |
|
| 663 | 0 | moveSelectedSubtreeRight(form); |
| 664 | |
|
| 665 | |
|
| 666 | 0 | return super.updateComponent(form, result, request, response); |
| 667 | |
} |
| 668 | |
|
| 669 | |
|
| 670 | |
|
| 671 | |
|
| 672 | |
|
| 673 | |
|
| 674 | |
private void moveSelectedSubtreeRight(UifFormBase form) { |
| 675 | |
|
| 676 | |
|
| 677 | |
|
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | |
|
| 682 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 683 | |
|
| 684 | 0 | AgendaItemBo firstItem = getFirstAgendaItem(agendaEditor.getAgenda()); |
| 685 | |
|
| 686 | 0 | String selectedItemId = agendaEditor.getSelectedAgendaItemId(); |
| 687 | 0 | AgendaItemBo node = getAgendaItemById(firstItem, selectedItemId); |
| 688 | 0 | AgendaItemBo parent = getParent(firstItem, selectedItemId); |
| 689 | |
|
| 690 | 0 | AgendaItemBo bogusRootNode = null; |
| 691 | 0 | if (parent == null) { |
| 692 | |
|
| 693 | 0 | bogusRootNode = new AgendaItemBo(); |
| 694 | 0 | AgendaItemChildAccessor.whenFalse.setChild(bogusRootNode, firstItem); |
| 695 | 0 | parent = bogusRootNode; |
| 696 | |
} |
| 697 | |
|
| 698 | 0 | AgendaItemInstanceChildAccessor accessorToSelectedNode = getInstanceAccessorToChild(parent, node.getId()); |
| 699 | 0 | AgendaItemBo olderSibling = (accessorToSelectedNode.getInstance() == parent) ? null : accessorToSelectedNode.getInstance(); |
| 700 | |
|
| 701 | 0 | if (olderSibling != null) { |
| 702 | 0 | accessorToSelectedNode.setChild(node.getAlways()); |
| 703 | 0 | AgendaItemInstanceChildAccessor yougestWhenFalseSiblingInsertionPoint = |
| 704 | |
getLastChildsAlwaysAccessor(new AgendaItemInstanceChildAccessor(AgendaItemChildAccessor.whenFalse, olderSibling)); |
| 705 | 0 | yougestWhenFalseSiblingInsertionPoint.setChild(node); |
| 706 | 0 | AgendaItemChildAccessor.always.setChild(node, null); |
| 707 | 0 | } else if (node.getAlways() != null) { |
| 708 | 0 | accessorToSelectedNode.setChild(node.getAlways()); |
| 709 | 0 | AgendaItemBo childsWhenTrue = node.getAlways().getWhenTrue(); |
| 710 | 0 | AgendaItemChildAccessor.whenTrue.setChild(node.getAlways(), node); |
| 711 | 0 | AgendaItemChildAccessor.always.setChild(node, childsWhenTrue); |
| 712 | |
} |
| 713 | |
|
| 714 | 0 | if (bogusRootNode != null) { |
| 715 | |
|
| 716 | 0 | agendaEditor.getAgenda().setFirstItemId(bogusRootNode.getWhenFalseId()); |
| 717 | |
} |
| 718 | 0 | } |
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | |
|
| 725 | |
|
| 726 | |
|
| 727 | |
private boolean isSiblings(AgendaItemBo cousin1, AgendaItemBo cousin2) { |
| 728 | 0 | if (cousin1.equals(cousin2)) return true; |
| 729 | |
|
| 730 | |
|
| 731 | 0 | AgendaItemBo candidate = cousin2; |
| 732 | 0 | while (null != (candidate = candidate.getAlways())) { |
| 733 | 0 | if (candidate.equals(cousin1)) return true; |
| 734 | |
} |
| 735 | |
|
| 736 | 0 | candidate = cousin1; |
| 737 | 0 | while (null != (candidate = candidate.getAlways())) { |
| 738 | 0 | if (candidate.equals(cousin2)) return true; |
| 739 | |
} |
| 740 | 0 | return false; |
| 741 | |
} |
| 742 | |
|
| 743 | |
|
| 744 | |
|
| 745 | |
|
| 746 | |
|
| 747 | |
|
| 748 | |
|
| 749 | |
private AgendaItemChildAccessor getOldestChildAccessor( |
| 750 | |
AgendaItemBo child, AgendaItemBo parent) { |
| 751 | 0 | AgendaItemChildAccessor levelOrderChildAccessor = null; |
| 752 | |
|
| 753 | 0 | if (parent != null) { |
| 754 | 0 | for (AgendaItemChildAccessor childAccessor : AgendaItemChildAccessor.children) { |
| 755 | 0 | if (child.equals(childAccessor.getChild(parent))) { |
| 756 | 0 | levelOrderChildAccessor = childAccessor; |
| 757 | 0 | break; |
| 758 | |
} |
| 759 | |
} |
| 760 | |
} |
| 761 | 0 | return levelOrderChildAccessor; |
| 762 | |
} |
| 763 | |
|
| 764 | |
|
| 765 | |
|
| 766 | |
|
| 767 | |
|
| 768 | |
|
| 769 | |
|
| 770 | |
private AgendaItemBo getFirstAgendaItem(AgendaBo agenda) { |
| 771 | 0 | AgendaItemBo firstItem = null; |
| 772 | 0 | if (agenda != null && agenda.getItems() != null) for (AgendaItemBo agendaItem : agenda.getItems()) { |
| 773 | 0 | if (agenda.getFirstItemId().equals(agendaItem.getId())) { |
| 774 | 0 | firstItem = agendaItem; |
| 775 | 0 | break; |
| 776 | |
} |
| 777 | |
} |
| 778 | 0 | return firstItem; |
| 779 | |
} |
| 780 | |
|
| 781 | |
|
| 782 | |
|
| 783 | |
|
| 784 | |
|
| 785 | |
|
| 786 | |
private AgendaItemBo getNextYoungestOfSameGeneration(AgendaItemBo root, AgendaItemBo agendaItem) { |
| 787 | |
|
| 788 | 0 | int genNumber = getAgendaItemGenerationNumber(0, root, agendaItem.getId()); |
| 789 | 0 | List<AgendaItemBo> genList = new ArrayList<AgendaItemBo>(); |
| 790 | 0 | buildAgendaItemGenerationList(genList, root, 0, genNumber); |
| 791 | |
|
| 792 | 0 | int itemIndex = genList.indexOf(agendaItem); |
| 793 | 0 | if (genList.size() > itemIndex + 1) return genList.get(itemIndex + 1); |
| 794 | |
|
| 795 | 0 | return null; |
| 796 | |
} |
| 797 | |
|
| 798 | |
|
| 799 | |
|
| 800 | |
|
| 801 | |
|
| 802 | |
|
| 803 | |
|
| 804 | |
|
| 805 | |
|
| 806 | |
private int getAgendaItemGenerationNumber(int currentLevel, AgendaItemBo node, String agendaItemId) { |
| 807 | 0 | int result = -1; |
| 808 | 0 | if (agendaItemId.equals(node.getId())) { |
| 809 | 0 | result = currentLevel; |
| 810 | |
} else { |
| 811 | 0 | for (AgendaItemChildAccessor childAccessor : AgendaItemChildAccessor.linkedNodes) { |
| 812 | 0 | AgendaItemBo child = childAccessor.getChild(node); |
| 813 | 0 | if (child != null) { |
| 814 | 0 | int nextLevel = currentLevel; |
| 815 | |
|
| 816 | 0 | if (childAccessor != AgendaItemChildAccessor.always) { |
| 817 | 0 | nextLevel = currentLevel +1; |
| 818 | |
} |
| 819 | 0 | result = getAgendaItemGenerationNumber(nextLevel, child, agendaItemId); |
| 820 | 0 | if (result != -1) break; |
| 821 | |
} |
| 822 | |
} |
| 823 | |
} |
| 824 | 0 | return result; |
| 825 | |
} |
| 826 | |
|
| 827 | |
|
| 828 | |
|
| 829 | |
|
| 830 | |
|
| 831 | |
|
| 832 | |
|
| 833 | |
|
| 834 | |
|
| 835 | |
private void buildAgendaItemGenerationList(List<AgendaItemBo> genList, AgendaItemBo node, int currentLevel, int generation) { |
| 836 | 0 | if (currentLevel == generation) { |
| 837 | 0 | genList.add(node); |
| 838 | |
} |
| 839 | |
|
| 840 | 0 | if (currentLevel > generation) return; |
| 841 | |
|
| 842 | 0 | for (AgendaItemChildAccessor childAccessor : AgendaItemChildAccessor.linkedNodes) { |
| 843 | 0 | AgendaItemBo child = childAccessor.getChild(node); |
| 844 | 0 | if (child != null) { |
| 845 | 0 | int nextLevel = currentLevel; |
| 846 | |
|
| 847 | 0 | if (childAccessor != AgendaItemChildAccessor.always) { |
| 848 | 0 | nextLevel = currentLevel +1; |
| 849 | |
} |
| 850 | 0 | buildAgendaItemGenerationList(genList, child, nextLevel, generation); |
| 851 | |
} |
| 852 | |
} |
| 853 | 0 | } |
| 854 | |
|
| 855 | |
|
| 856 | |
|
| 857 | |
|
| 858 | |
|
| 859 | |
|
| 860 | |
private AgendaItemBo getNextOldestOfSameGeneration(AgendaItemBo root, AgendaItemBo agendaItem) { |
| 861 | |
|
| 862 | 0 | int genNumber = getAgendaItemGenerationNumber(0, root, agendaItem.getId()); |
| 863 | 0 | List<AgendaItemBo> genList = new ArrayList<AgendaItemBo>(); |
| 864 | 0 | buildAgendaItemGenerationList(genList, root, 0, genNumber); |
| 865 | |
|
| 866 | 0 | int itemIndex = genList.indexOf(agendaItem); |
| 867 | 0 | if (itemIndex >= 1) return genList.get(itemIndex - 1); |
| 868 | |
|
| 869 | 0 | return null; |
| 870 | |
} |
| 871 | |
|
| 872 | |
|
| 873 | |
|
| 874 | |
|
| 875 | |
|
| 876 | |
|
| 877 | |
private AgendaItemBo getParent(AgendaItemBo root, String agendaItemId) { |
| 878 | 0 | return getParentHelper(root, null, agendaItemId); |
| 879 | |
} |
| 880 | |
|
| 881 | |
|
| 882 | |
|
| 883 | |
|
| 884 | |
|
| 885 | |
|
| 886 | |
|
| 887 | |
|
| 888 | |
|
| 889 | |
private AgendaItemBo getParentHelper(AgendaItemBo node, AgendaItemBo levelOrderParent, String agendaItemId) { |
| 890 | 0 | AgendaItemBo result = null; |
| 891 | 0 | if (agendaItemId.equals(node.getId())) { |
| 892 | 0 | result = levelOrderParent; |
| 893 | |
} else { |
| 894 | 0 | for (AgendaItemChildAccessor childAccessor : AgendaItemChildAccessor.linkedNodes) { |
| 895 | 0 | AgendaItemBo child = childAccessor.getChild(node); |
| 896 | 0 | if (child != null) { |
| 897 | |
|
| 898 | 0 | AgendaItemBo lop = (childAccessor == AgendaItemChildAccessor.always) ? levelOrderParent : node; |
| 899 | 0 | result = getParentHelper(child, lop, agendaItemId); |
| 900 | 0 | if (result != null) break; |
| 901 | |
} |
| 902 | |
} |
| 903 | |
} |
| 904 | 0 | return result; |
| 905 | |
} |
| 906 | |
|
| 907 | |
|
| 908 | |
|
| 909 | |
|
| 910 | |
private AgendaItemBo getAgendaItemById(AgendaItemBo node, String agendaItemId) { |
| 911 | 0 | if (node == null) throw new IllegalArgumentException("node must be non-null"); |
| 912 | |
|
| 913 | 0 | AgendaItemBo result = null; |
| 914 | |
|
| 915 | 0 | if (agendaItemId.equals(node.getId())) { |
| 916 | 0 | result = node; |
| 917 | |
} else { |
| 918 | 0 | for (AgendaItemChildAccessor childAccessor : AgendaItemChildAccessor.linkedNodes) { |
| 919 | 0 | AgendaItemBo child = childAccessor.getChild(node); |
| 920 | 0 | if (child != null) { |
| 921 | 0 | result = getAgendaItemById(child, agendaItemId); |
| 922 | 0 | if (result != null) break; |
| 923 | |
} |
| 924 | |
} |
| 925 | |
} |
| 926 | 0 | return result; |
| 927 | |
} |
| 928 | |
|
| 929 | |
|
| 930 | |
|
| 931 | |
|
| 932 | |
|
| 933 | |
private AgendaEditor getAgendaEditor(UifFormBase form) { |
| 934 | 0 | MaintenanceForm maintenanceForm = (MaintenanceForm) form; |
| 935 | 0 | return ((AgendaEditor)maintenanceForm.getDocument().getDocumentDataObject()); |
| 936 | |
} |
| 937 | |
|
| 938 | |
private void treeToInOrderList(AgendaItemBo agendaItem, List<AgendaItemBo> listToBuild) { |
| 939 | 0 | listToBuild.add(agendaItem); |
| 940 | 0 | for (AgendaItemChildAccessor childAccessor : AgendaItemChildAccessor.linkedNodes) { |
| 941 | 0 | AgendaItemBo child = childAccessor.getChild(agendaItem); |
| 942 | 0 | if (child != null) treeToInOrderList(child, listToBuild); |
| 943 | |
} |
| 944 | 0 | } |
| 945 | |
|
| 946 | |
|
| 947 | |
@RequestMapping(params = "methodToCall=" + "delete") |
| 948 | |
public ModelAndView delete(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 949 | |
HttpServletRequest request, HttpServletResponse response) |
| 950 | |
throws Exception { |
| 951 | |
|
| 952 | 0 | deleteSelectedSubtree(form); |
| 953 | |
|
| 954 | 0 | return super.refresh(form, result, request, response); |
| 955 | |
} |
| 956 | |
|
| 957 | |
@RequestMapping(params = "methodToCall=" + "ajaxDelete") |
| 958 | |
public ModelAndView ajaxDelete(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 959 | |
HttpServletRequest request, HttpServletResponse response) |
| 960 | |
throws Exception { |
| 961 | |
|
| 962 | 0 | deleteSelectedSubtree(form); |
| 963 | |
|
| 964 | |
|
| 965 | 0 | return super.updateComponent(form, result, request, response); |
| 966 | |
} |
| 967 | |
|
| 968 | |
|
| 969 | |
private void deleteSelectedSubtree(UifFormBase form) { |
| 970 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 971 | 0 | AgendaItemBo firstItem = getFirstAgendaItem(agendaEditor.getAgenda()); |
| 972 | 0 | String agendaItemSelected = agendaEditor.getSelectedAgendaItemId(); |
| 973 | |
|
| 974 | 0 | if (firstItem != null) { |
| 975 | |
|
| 976 | 0 | if (agendaItemSelected.equals(firstItem.getId())) { |
| 977 | 0 | agendaEditor.getAgenda().setFirstItemId(firstItem.getAlwaysId()); |
| 978 | |
} else { |
| 979 | 0 | deleteAgendaItem(firstItem, agendaItemSelected); |
| 980 | |
} |
| 981 | |
} |
| 982 | 0 | } |
| 983 | |
|
| 984 | |
private void deleteAgendaItem(AgendaItemBo root, String agendaItemIdToDelete) { |
| 985 | 0 | if (deleteAgendaItem(root, AgendaItemChildAccessor.whenTrue, agendaItemIdToDelete) || |
| 986 | |
deleteAgendaItem(root, AgendaItemChildAccessor.whenFalse, agendaItemIdToDelete) || |
| 987 | |
deleteAgendaItem(root, AgendaItemChildAccessor.always, agendaItemIdToDelete)); |
| 988 | 0 | } |
| 989 | |
|
| 990 | |
private boolean deleteAgendaItem(AgendaItemBo agendaItem, AgendaItemChildAccessor childAccessor, String agendaItemIdToDelete) { |
| 991 | 0 | if (agendaItem == null || childAccessor.getChild(agendaItem) == null) return false; |
| 992 | 0 | if (agendaItemIdToDelete.equals(childAccessor.getChild(agendaItem).getId())) { |
| 993 | |
|
| 994 | 0 | AgendaItemBo grandchildToKeep = childAccessor.getChild(agendaItem).getAlways(); |
| 995 | 0 | childAccessor.setChild(agendaItem, grandchildToKeep); |
| 996 | 0 | return true; |
| 997 | |
} else { |
| 998 | 0 | AgendaItemBo child = childAccessor.getChild(agendaItem); |
| 999 | |
|
| 1000 | 0 | for (AgendaItemChildAccessor nextChildAccessor : AgendaItemChildAccessor.linkedNodes) { |
| 1001 | 0 | if (deleteAgendaItem(child, nextChildAccessor, agendaItemIdToDelete)) return true; |
| 1002 | |
} |
| 1003 | |
} |
| 1004 | 0 | return false; |
| 1005 | |
} |
| 1006 | |
|
| 1007 | |
@RequestMapping(params = "methodToCall=" + "ajaxCut") |
| 1008 | |
public ModelAndView ajaxCut(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1009 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 1010 | |
|
| 1011 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 1012 | |
|
| 1013 | 0 | AgendaItemBo firstItem = getFirstAgendaItem(agendaEditor.getAgenda()); |
| 1014 | 0 | String selectedItemId = agendaEditor.getSelectedAgendaItemId(); |
| 1015 | |
|
| 1016 | 0 | setCutAgendaItemId(form, selectedItemId); |
| 1017 | |
|
| 1018 | |
|
| 1019 | 0 | return super.updateComponent(form, result, request, response); |
| 1020 | |
} |
| 1021 | |
|
| 1022 | |
@RequestMapping(params = "methodToCall=" + "ajaxPaste") |
| 1023 | |
public ModelAndView ajaxPaste(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1024 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 1025 | |
|
| 1026 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 1027 | |
|
| 1028 | 0 | AgendaItemBo firstItem = getFirstAgendaItem(agendaEditor.getAgenda()); |
| 1029 | 0 | String selectedItemId = agendaEditor.getSelectedAgendaItemId(); |
| 1030 | |
|
| 1031 | 0 | String agendaItemId = getCutAgendaItemId(form); |
| 1032 | |
|
| 1033 | 0 | if (StringUtils.isNotBlank(selectedItemId) && StringUtils.isNotBlank(agendaItemId)) { |
| 1034 | 0 | AgendaItemBo node = getAgendaItemById(firstItem, agendaItemId); |
| 1035 | 0 | AgendaItemBo orgRefNode = getReferringNode(firstItem, agendaItemId); |
| 1036 | 0 | AgendaItemBo newRefNode = getAgendaItemById(firstItem, selectedItemId); |
| 1037 | |
|
| 1038 | 0 | if (isSameOrChildNode(node, newRefNode)) { |
| 1039 | |
|
| 1040 | |
} else { |
| 1041 | |
|
| 1042 | 0 | if (orgRefNode == null) { |
| 1043 | 0 | agendaEditor.getAgenda().setFirstItemId(node.getAlwaysId()); |
| 1044 | |
} else { |
| 1045 | |
|
| 1046 | |
|
| 1047 | 0 | if (node.getId().equals(orgRefNode.getWhenTrueId())) { |
| 1048 | 0 | orgRefNode.setWhenTrueId(node.getAlwaysId()); |
| 1049 | 0 | orgRefNode.setWhenTrue(node.getAlways()); |
| 1050 | 0 | } else if(node.getId().equals(orgRefNode.getWhenFalseId())) { |
| 1051 | 0 | orgRefNode.setWhenFalseId(node.getAlwaysId()); |
| 1052 | 0 | orgRefNode.setWhenFalse(node.getAlways()); |
| 1053 | |
} else { |
| 1054 | 0 | orgRefNode.setAlwaysId(node.getAlwaysId()); |
| 1055 | 0 | orgRefNode.setAlways(node.getAlways()); |
| 1056 | |
} |
| 1057 | |
} |
| 1058 | |
|
| 1059 | |
|
| 1060 | 0 | node.setAlwaysId(newRefNode.getAlwaysId()); |
| 1061 | 0 | node.setAlways(newRefNode.getAlways()); |
| 1062 | 0 | newRefNode.setAlwaysId(node.getId()); |
| 1063 | 0 | newRefNode.setAlways(node); |
| 1064 | |
} |
| 1065 | |
} |
| 1066 | |
|
| 1067 | 0 | setCutAgendaItemId(form, null); |
| 1068 | |
|
| 1069 | |
|
| 1070 | 0 | return super.updateComponent(form, result, request, response); |
| 1071 | |
} |
| 1072 | |
|
| 1073 | |
|
| 1074 | |
|
| 1075 | |
|
| 1076 | |
|
| 1077 | |
|
| 1078 | |
|
| 1079 | |
|
| 1080 | |
|
| 1081 | |
|
| 1082 | |
private boolean isSameOrChildNode(AgendaItemBo node, AgendaItemBo newParent) { |
| 1083 | 0 | return isSameOrChildNodeHelper(node, newParent, AgendaItemChildAccessor.children); |
| 1084 | |
} |
| 1085 | |
|
| 1086 | |
private boolean isSameOrChildNodeHelper(AgendaItemBo node, AgendaItemBo newParent, AgendaItemChildAccessor[] childAccessors) { |
| 1087 | 0 | boolean result = false; |
| 1088 | 0 | if (StringUtils.equals(node.getId(), newParent.getId())) { |
| 1089 | 0 | result = true; |
| 1090 | |
} else { |
| 1091 | 0 | for (AgendaItemChildAccessor childAccessor : childAccessors) { |
| 1092 | 0 | AgendaItemBo child = childAccessor.getChild(node); |
| 1093 | 0 | if (child != null) { |
| 1094 | 0 | result = isSameOrChildNodeHelper(child, newParent, AgendaItemChildAccessor.linkedNodes); |
| 1095 | 0 | if (result == true) break; |
| 1096 | |
} |
| 1097 | |
} |
| 1098 | |
} |
| 1099 | 0 | return result; |
| 1100 | |
} |
| 1101 | |
|
| 1102 | |
|
| 1103 | |
|
| 1104 | |
|
| 1105 | |
|
| 1106 | |
|
| 1107 | |
|
| 1108 | |
|
| 1109 | |
|
| 1110 | |
|
| 1111 | |
private AgendaItemBo getReferringNode(AgendaItemBo root, String agendaItemId) { |
| 1112 | 0 | return getReferringNodeHelper(root, null, agendaItemId); |
| 1113 | |
} |
| 1114 | |
|
| 1115 | |
private AgendaItemBo getReferringNodeHelper(AgendaItemBo node, AgendaItemBo referringNode, String agendaItemId) { |
| 1116 | 0 | AgendaItemBo result = null; |
| 1117 | 0 | if (agendaItemId.equals(node.getId())) { |
| 1118 | 0 | result = referringNode; |
| 1119 | |
} else { |
| 1120 | 0 | for (AgendaItemChildAccessor childAccessor : AgendaItemChildAccessor.linkedNodes) { |
| 1121 | 0 | AgendaItemBo child = childAccessor.getChild(node); |
| 1122 | 0 | if (child != null) { |
| 1123 | 0 | result = getReferringNodeHelper(child, node, agendaItemId); |
| 1124 | 0 | if (result != null) break; |
| 1125 | |
} |
| 1126 | |
} |
| 1127 | |
} |
| 1128 | 0 | return result; |
| 1129 | |
} |
| 1130 | |
|
| 1131 | |
|
| 1132 | |
|
| 1133 | |
|
| 1134 | |
private SequenceAccessorService getSequenceAccessorService() { |
| 1135 | 0 | if ( sequenceAccessorService == null ) { |
| 1136 | 0 | sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService(); |
| 1137 | |
} |
| 1138 | 0 | return sequenceAccessorService; |
| 1139 | |
} |
| 1140 | |
|
| 1141 | |
|
| 1142 | |
|
| 1143 | |
|
| 1144 | |
private ContextBoService getContextBoService() { |
| 1145 | 0 | return KrmsRepositoryServiceLocator.getContextBoService(); |
| 1146 | |
} |
| 1147 | |
|
| 1148 | |
|
| 1149 | |
|
| 1150 | |
|
| 1151 | |
|
| 1152 | |
private static class AgendaItemInstanceChildAccessor { |
| 1153 | |
|
| 1154 | |
private final AgendaItemChildAccessor accessor; |
| 1155 | |
private final AgendaItemBo instance; |
| 1156 | |
|
| 1157 | 0 | public AgendaItemInstanceChildAccessor(AgendaItemChildAccessor accessor, AgendaItemBo instance) { |
| 1158 | 0 | this.accessor = accessor; |
| 1159 | 0 | this.instance = instance; |
| 1160 | 0 | } |
| 1161 | |
|
| 1162 | |
public void setChild(AgendaItemBo child) { |
| 1163 | 0 | accessor.setChild(instance, child); |
| 1164 | 0 | } |
| 1165 | |
|
| 1166 | |
public AgendaItemBo getChild() { |
| 1167 | 0 | return accessor.getChild(instance); |
| 1168 | |
} |
| 1169 | |
|
| 1170 | 0 | public AgendaItemBo getInstance() { return instance; } |
| 1171 | |
} |
| 1172 | |
|
| 1173 | |
|
| 1174 | |
|
| 1175 | |
|
| 1176 | |
|
| 1177 | |
|
| 1178 | |
|
| 1179 | |
|
| 1180 | |
|
| 1181 | |
|
| 1182 | |
|
| 1183 | |
|
| 1184 | |
|
| 1185 | |
|
| 1186 | |
|
| 1187 | |
|
| 1188 | |
|
| 1189 | |
|
| 1190 | |
|
| 1191 | |
|
| 1192 | |
|
| 1193 | |
|
| 1194 | |
|
| 1195 | |
|
| 1196 | |
|
| 1197 | |
|
| 1198 | |
|
| 1199 | |
|
| 1200 | |
|
| 1201 | 0 | protected static class AgendaItemChildAccessor { |
| 1202 | |
|
| 1203 | 0 | private enum Child { WHEN_TRUE, WHEN_FALSE, ALWAYS }; |
| 1204 | |
|
| 1205 | 0 | private static final AgendaItemChildAccessor whenTrue = new AgendaItemChildAccessor(Child.WHEN_TRUE); |
| 1206 | 0 | private static final AgendaItemChildAccessor whenFalse = new AgendaItemChildAccessor(Child.WHEN_FALSE); |
| 1207 | 0 | private static final AgendaItemChildAccessor always = new AgendaItemChildAccessor(Child.ALWAYS); |
| 1208 | |
|
| 1209 | |
|
| 1210 | |
|
| 1211 | |
|
| 1212 | 0 | private static final AgendaItemChildAccessor [] linkedNodes = { whenTrue, whenFalse, always }; |
| 1213 | |
|
| 1214 | |
|
| 1215 | |
|
| 1216 | |
|
| 1217 | 0 | private static final AgendaItemChildAccessor [] children = { whenTrue, whenFalse }; |
| 1218 | |
|
| 1219 | |
private final Child whichChild; |
| 1220 | |
|
| 1221 | 0 | private AgendaItemChildAccessor(Child whichChild) { |
| 1222 | 0 | if (whichChild == null) throw new IllegalArgumentException("whichChild must be non-null"); |
| 1223 | 0 | this.whichChild = whichChild; |
| 1224 | 0 | } |
| 1225 | |
|
| 1226 | |
|
| 1227 | |
|
| 1228 | |
|
| 1229 | |
public AgendaItemBo getChild(AgendaItemBo parent) { |
| 1230 | 0 | switch (whichChild) { |
| 1231 | 0 | case WHEN_TRUE: return parent.getWhenTrue(); |
| 1232 | 0 | case WHEN_FALSE: return parent.getWhenFalse(); |
| 1233 | 0 | case ALWAYS: return parent.getAlways(); |
| 1234 | 0 | default: throw new IllegalStateException(); |
| 1235 | |
} |
| 1236 | |
} |
| 1237 | |
|
| 1238 | |
|
| 1239 | |
|
| 1240 | |
|
| 1241 | |
public void setChild(AgendaItemBo parent, AgendaItemBo child) { |
| 1242 | 0 | switch (whichChild) { |
| 1243 | |
case WHEN_TRUE: |
| 1244 | 0 | parent.setWhenTrue(child); |
| 1245 | 0 | parent.setWhenTrueId(child == null ? null : child.getId()); |
| 1246 | 0 | break; |
| 1247 | |
case WHEN_FALSE: |
| 1248 | 0 | parent.setWhenFalse(child); |
| 1249 | 0 | parent.setWhenFalseId(child == null ? null : child.getId()); |
| 1250 | 0 | break; |
| 1251 | |
case ALWAYS: |
| 1252 | 0 | parent.setAlways(child); |
| 1253 | 0 | parent.setAlwaysId(child == null ? null : child.getId()); |
| 1254 | 0 | break; |
| 1255 | 0 | default: throw new IllegalStateException(); |
| 1256 | |
} |
| 1257 | 0 | } |
| 1258 | |
} |
| 1259 | |
|
| 1260 | |
|
| 1261 | |
|
| 1262 | |
|
| 1263 | |
|
| 1264 | |
|
| 1265 | |
@RequestMapping(params = "methodToCall=" + "goToEditProposition") |
| 1266 | |
public ModelAndView goToEditProposition(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1267 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 1268 | |
|
| 1269 | |
|
| 1270 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 1271 | 0 | RuleBo rule = agendaEditor.getAgendaItemLine().getRule(); |
| 1272 | 0 | String selectedPropId = agendaEditor.getSelectedPropositionId(); |
| 1273 | |
|
| 1274 | |
|
| 1275 | 0 | Node<RuleTreeNode,String> root = rule.getPropositionTree().getRootElement(); |
| 1276 | 0 | Node<RuleTreeNode,String> parent = findParentPropositionNode( root, selectedPropId); |
| 1277 | 0 | if (parent != null){ |
| 1278 | 0 | List<Node<RuleTreeNode,String>> children = parent.getChildren(); |
| 1279 | 0 | for( int index=0; index< children.size(); index++){ |
| 1280 | 0 | Node<RuleTreeNode,String> child = children.get(index); |
| 1281 | 0 | if (propIdMatches(child, selectedPropId)){ |
| 1282 | 0 | PropositionBo prop = child.getData().getProposition(); |
| 1283 | 0 | boolean editMode = !prop.getEditMode(); |
| 1284 | 0 | prop.setEditMode(editMode); |
| 1285 | |
|
| 1286 | 0 | if (PropositionType.COMPOUND.getCode().equalsIgnoreCase(prop.getPropositionTypeCode())){ |
| 1287 | 0 | for ( PropositionBo compoundComponent : prop.getCompoundComponents() ){ |
| 1288 | 0 | compoundComponent.setEditMode(editMode); |
| 1289 | |
} |
| 1290 | |
} |
| 1291 | |
|
| 1292 | 0 | rule.refreshPropositionTree(null); |
| 1293 | 0 | break; |
| 1294 | |
} |
| 1295 | |
} |
| 1296 | |
} |
| 1297 | 0 | return super.updateComponent(form, result, request, response); |
| 1298 | |
} |
| 1299 | |
|
| 1300 | |
@RequestMapping(params = "methodToCall=" + "addProposition") |
| 1301 | |
public ModelAndView addProposition(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1302 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 1303 | |
|
| 1304 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 1305 | 0 | RuleBo rule = agendaEditor.getAgendaItemLine().getRule(); |
| 1306 | 0 | String selectedPropId = agendaEditor.getSelectedPropositionId(); |
| 1307 | |
|
| 1308 | |
|
| 1309 | 0 | Node<RuleTreeNode,String> root = agendaEditor.getAgendaItemLine().getRule().getPropositionTree().getRootElement(); |
| 1310 | 0 | Node<RuleTreeNode,String> parent = findParentPropositionNode( root, selectedPropId); |
| 1311 | |
|
| 1312 | |
|
| 1313 | 0 | if (parent != null){ |
| 1314 | 0 | List<Node<RuleTreeNode,String>> children = parent.getChildren(); |
| 1315 | 0 | for( int index=0; index< children.size(); index++){ |
| 1316 | 0 | Node<RuleTreeNode,String> child = children.get(index); |
| 1317 | |
|
| 1318 | |
|
| 1319 | 0 | if (propIdMatches(child, selectedPropId)){ |
| 1320 | |
|
| 1321 | |
|
| 1322 | |
|
| 1323 | |
|
| 1324 | 0 | if (parent == root && |
| 1325 | |
(SimplePropositionNode.NODE_TYPE.equalsIgnoreCase(child.getNodeType()) || |
| 1326 | |
SimplePropositionEditNode.NODE_TYPE.equalsIgnoreCase(child.getNodeType()))){ |
| 1327 | |
|
| 1328 | |
|
| 1329 | 0 | PropositionBo compound = PropositionBo.createCompoundPropositionBoStub(child.getData().getProposition()); |
| 1330 | 0 | compound.setEditMode(true); |
| 1331 | 0 | rule.setProposition(compound); |
| 1332 | 0 | rule.refreshPropositionTree(null); |
| 1333 | 0 | } |
| 1334 | |
|
| 1335 | 0 | else if(SimplePropositionNode.NODE_TYPE.equalsIgnoreCase(child.getNodeType()) || |
| 1336 | |
SimplePropositionEditNode.NODE_TYPE.equalsIgnoreCase(child.getNodeType())){ |
| 1337 | |
|
| 1338 | |
|
| 1339 | 0 | PropositionBo blank = PropositionBo.createSimplePropositionBoStub(child.getData().getProposition(),PropositionType.SIMPLE.getCode()); |
| 1340 | |
|
| 1341 | 0 | PropositionBo parentProp = parent.getData().getProposition(); |
| 1342 | 0 | parentProp.getCompoundComponents().add(((index/2)+1), blank); |
| 1343 | |
|
| 1344 | 0 | rule.refreshPropositionTree(true); |
| 1345 | 0 | } |
| 1346 | |
|
| 1347 | |
break; |
| 1348 | |
} |
| 1349 | |
} |
| 1350 | 0 | } else { |
| 1351 | |
|
| 1352 | |
|
| 1353 | 0 | if (root.getChildren().isEmpty()){ |
| 1354 | 0 | PropositionBo blank = PropositionBo.createSimplePropositionBoStub(null,PropositionType.SIMPLE.getCode()); |
| 1355 | 0 | blank.setRuleId(rule.getId()); |
| 1356 | 0 | blank.setTypeId(rule.getTypeId()); |
| 1357 | 0 | rule.setPropId(blank.getId()); |
| 1358 | 0 | rule.setProposition(blank); |
| 1359 | 0 | rule.refreshPropositionTree(true); |
| 1360 | |
} |
| 1361 | |
} |
| 1362 | 0 | return super.updateComponent(form, result, request, response); |
| 1363 | |
} |
| 1364 | |
|
| 1365 | |
|
| 1366 | |
|
| 1367 | |
|
| 1368 | |
|
| 1369 | |
|
| 1370 | |
|
| 1371 | |
|
| 1372 | |
|
| 1373 | |
private void addOpCodeNode(Node currentNode, PropositionBo prop, int index){ |
| 1374 | 0 | String opCodeLabel = ""; |
| 1375 | |
|
| 1376 | 0 | if (LogicalOperator.AND.getCode().equalsIgnoreCase(prop.getCompoundOpCode())){ |
| 1377 | 0 | opCodeLabel = "AND"; |
| 1378 | 0 | } else if (LogicalOperator.OR.getCode().equalsIgnoreCase(prop.getCompoundOpCode())){ |
| 1379 | 0 | opCodeLabel = "OR"; |
| 1380 | |
} |
| 1381 | 0 | Node<RuleTreeNode, String> aNode = new Node<RuleTreeNode, String>(); |
| 1382 | 0 | aNode.setNodeLabel(""); |
| 1383 | 0 | aNode.setNodeType("ruleTreeNode compoundOpCodeNode"); |
| 1384 | 0 | aNode.setData(new CompoundOpCodeNode(prop)); |
| 1385 | 0 | currentNode.insertChildAt(index, aNode); |
| 1386 | 0 | } |
| 1387 | |
|
| 1388 | |
|
| 1389 | |
private boolean propIdMatches(Node<RuleTreeNode, String> node, String propId){ |
| 1390 | 0 | if (propId!=null && node != null && node.getData() != null && propId.equalsIgnoreCase(node.getData().getProposition().getId())) { |
| 1391 | 0 | return true; |
| 1392 | |
} |
| 1393 | 0 | return false; |
| 1394 | |
} |
| 1395 | |
|
| 1396 | |
private Node<RuleTreeNode, String> findPropositionTreeNode(Node<RuleTreeNode, String> currentNode, String selectedPropId){ |
| 1397 | 0 | Node<RuleTreeNode,String> bingo = null; |
| 1398 | 0 | if (currentNode.getData() != null){ |
| 1399 | 0 | RuleTreeNode dataNode = currentNode.getData(); |
| 1400 | 0 | if (selectedPropId.equalsIgnoreCase(dataNode.getProposition().getId())){ |
| 1401 | 0 | return currentNode; |
| 1402 | |
} |
| 1403 | |
} |
| 1404 | 0 | List<Node<RuleTreeNode,String>> children = currentNode.getChildren(); |
| 1405 | 0 | for( Node<RuleTreeNode,String> child : children){ |
| 1406 | 0 | bingo = findPropositionTreeNode(child, selectedPropId); |
| 1407 | 0 | if (bingo != null) break; |
| 1408 | |
} |
| 1409 | 0 | return bingo; |
| 1410 | |
} |
| 1411 | |
|
| 1412 | |
private Node<RuleTreeNode, String> findParentPropositionNode(Node<RuleTreeNode, String> currentNode, String selectedPropId){ |
| 1413 | 0 | Node<RuleTreeNode,String> bingo = null; |
| 1414 | 0 | if (selectedPropId != null) { |
| 1415 | |
|
| 1416 | 0 | List<Node<RuleTreeNode,String>> children = currentNode.getChildren(); |
| 1417 | 0 | for( Node<RuleTreeNode,String> child : children){ |
| 1418 | 0 | RuleTreeNode dataNode = child.getData(); |
| 1419 | 0 | if (selectedPropId.equalsIgnoreCase(dataNode.getProposition().getId())) |
| 1420 | 0 | return currentNode; |
| 1421 | 0 | } |
| 1422 | |
|
| 1423 | |
|
| 1424 | 0 | for( Node<RuleTreeNode,String> kid : children){ |
| 1425 | 0 | bingo = findParentPropositionNode(kid, selectedPropId); |
| 1426 | 0 | if (bingo != null) break; |
| 1427 | |
} |
| 1428 | |
} |
| 1429 | 0 | return bingo; |
| 1430 | |
} |
| 1431 | |
|
| 1432 | |
|
| 1433 | |
|
| 1434 | |
|
| 1435 | |
|
| 1436 | |
|
| 1437 | |
|
| 1438 | |
private int findChildIndex(Node<RuleTreeNode,String> parent, String propId){ |
| 1439 | |
int index; |
| 1440 | 0 | List<Node<RuleTreeNode,String>> children = parent.getChildren(); |
| 1441 | 0 | for(index=0; index< children.size(); index++){ |
| 1442 | 0 | Node<RuleTreeNode,String> child = children.get(index); |
| 1443 | |
|
| 1444 | 0 | if (propIdMatches(child, propId)){ |
| 1445 | 0 | return index; |
| 1446 | |
} |
| 1447 | |
} |
| 1448 | 0 | return -1; |
| 1449 | |
} |
| 1450 | |
|
| 1451 | |
@RequestMapping(params = "methodToCall=" + "movePropositionUp") |
| 1452 | |
public ModelAndView movePropositionUp(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1453 | |
HttpServletRequest request, HttpServletResponse response) |
| 1454 | |
throws Exception { |
| 1455 | 0 | moveSelectedProposition(form, true); |
| 1456 | |
|
| 1457 | 0 | return super.updateComponent(form, result, request, response); |
| 1458 | |
} |
| 1459 | |
|
| 1460 | |
@RequestMapping(params = "methodToCall=" + "movePropositionDown") |
| 1461 | |
public ModelAndView movePropositionDown(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1462 | |
HttpServletRequest request, HttpServletResponse response) |
| 1463 | |
throws Exception { |
| 1464 | 0 | moveSelectedProposition(form, false); |
| 1465 | |
|
| 1466 | 0 | return super.updateComponent(form, result, request, response); |
| 1467 | |
} |
| 1468 | |
|
| 1469 | |
private void moveSelectedProposition(UifFormBase form, boolean up) { |
| 1470 | |
|
| 1471 | |
|
| 1472 | |
|
| 1473 | |
|
| 1474 | |
|
| 1475 | |
|
| 1476 | |
|
| 1477 | |
|
| 1478 | |
|
| 1479 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 1480 | 0 | RuleBo rule = agendaEditor.getAgendaItemLine().getRule(); |
| 1481 | 0 | String selectedPropId = agendaEditor.getSelectedPropositionId(); |
| 1482 | |
|
| 1483 | |
|
| 1484 | 0 | Node<RuleTreeNode,String> parent = findParentPropositionNode(rule.getPropositionTree().getRootElement(), selectedPropId); |
| 1485 | |
|
| 1486 | |
|
| 1487 | 0 | if (parent != null){ |
| 1488 | 0 | List<Node<RuleTreeNode,String>> children = parent.getChildren(); |
| 1489 | 0 | for( int index=0; index< children.size(); index++){ |
| 1490 | 0 | Node<RuleTreeNode,String> child = children.get(index); |
| 1491 | |
|
| 1492 | 0 | if (propIdMatches(child, selectedPropId)){ |
| 1493 | 0 | if(SimplePropositionNode.NODE_TYPE.equalsIgnoreCase(child.getNodeType()) || |
| 1494 | |
SimplePropositionEditNode.NODE_TYPE.equalsIgnoreCase(child.getNodeType()) || |
| 1495 | |
RuleTreeNode.COMPOUND_NODE_TYPE.equalsIgnoreCase(child.getNodeType()) ){ |
| 1496 | |
|
| 1497 | 0 | if (((index > 0) && up) || ((index <(children.size() - 1)&& !up))){ |
| 1498 | |
|
| 1499 | 0 | PropositionBo parentProp = parent.getData().getProposition(); |
| 1500 | 0 | PropositionBo workingProp = parentProp.getCompoundComponents().remove(index/2); |
| 1501 | 0 | if (up){ |
| 1502 | 0 | parentProp.getCompoundComponents().add((index/2)-1, workingProp); |
| 1503 | |
}else{ |
| 1504 | 0 | parentProp.getCompoundComponents().add((index/2)+1, workingProp); |
| 1505 | |
} |
| 1506 | |
|
| 1507 | |
|
| 1508 | |
|
| 1509 | 0 | boolean editMode = (SimplePropositionEditNode.NODE_TYPE.equalsIgnoreCase(child.getNodeType())); |
| 1510 | 0 | rule.refreshPropositionTree(editMode); |
| 1511 | 0 | } |
| 1512 | |
} |
| 1513 | |
|
| 1514 | |
break; |
| 1515 | |
} |
| 1516 | |
} |
| 1517 | |
} |
| 1518 | 0 | } |
| 1519 | |
@RequestMapping(params = "methodToCall=" + "movePropositionLeft") |
| 1520 | |
public ModelAndView movePropositionLeft(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1521 | |
HttpServletRequest request, HttpServletResponse response) |
| 1522 | |
throws Exception { |
| 1523 | |
|
| 1524 | |
|
| 1525 | |
|
| 1526 | |
|
| 1527 | |
|
| 1528 | |
|
| 1529 | |
|
| 1530 | |
|
| 1531 | |
|
| 1532 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 1533 | 0 | RuleBo rule = agendaEditor.getAgendaItemLine().getRule(); |
| 1534 | 0 | String selectedPropId = agendaEditor.getSelectedPropositionId(); |
| 1535 | |
|
| 1536 | |
|
| 1537 | 0 | Node<RuleTreeNode,String> root = rule.getPropositionTree().getRootElement(); |
| 1538 | 0 | Node<RuleTreeNode,String> parent = findParentPropositionNode(root, selectedPropId); |
| 1539 | 0 | if ((parent != null) && (RuleTreeNode.COMPOUND_NODE_TYPE.equalsIgnoreCase(parent.getNodeType()))){ |
| 1540 | 0 | Node<RuleTreeNode,String> granny = findParentPropositionNode(root,parent.getData().getProposition().getId()); |
| 1541 | 0 | if (granny != root){ |
| 1542 | 0 | int oldIndex = findChildIndex(parent, selectedPropId); |
| 1543 | 0 | int newIndex = findChildIndex(granny, parent.getData().getProposition().getId()); |
| 1544 | 0 | if (oldIndex >= 0 && newIndex >= 0){ |
| 1545 | 0 | PropositionBo prop = parent.getData().getProposition().getCompoundComponents().remove(oldIndex/2); |
| 1546 | 0 | granny.getData().getProposition().getCompoundComponents().add((newIndex/2)+1, prop); |
| 1547 | 0 | rule.refreshPropositionTree(false); |
| 1548 | |
} |
| 1549 | |
} else { |
| 1550 | |
|
| 1551 | |
|
| 1552 | |
|
| 1553 | |
} |
| 1554 | |
} |
| 1555 | 0 | return super.updateComponent(form, result, request, response); |
| 1556 | |
} |
| 1557 | |
|
| 1558 | |
@RequestMapping(params = "methodToCall=" + "movePropositionRight") |
| 1559 | |
public ModelAndView movePropositionRight(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1560 | |
HttpServletRequest request, HttpServletResponse response) |
| 1561 | |
throws Exception { |
| 1562 | |
|
| 1563 | |
|
| 1564 | |
|
| 1565 | |
|
| 1566 | |
|
| 1567 | |
|
| 1568 | |
|
| 1569 | |
|
| 1570 | |
|
| 1571 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 1572 | 0 | RuleBo rule = agendaEditor.getAgendaItemLine().getRule(); |
| 1573 | 0 | String selectedPropId = agendaEditor.getSelectedPropositionId(); |
| 1574 | |
|
| 1575 | |
|
| 1576 | 0 | Node<RuleTreeNode,String> parent = findParentPropositionNode( |
| 1577 | |
rule.getPropositionTree().getRootElement(), selectedPropId); |
| 1578 | 0 | if (parent != null){ |
| 1579 | 0 | int index = findChildIndex(parent, selectedPropId); |
| 1580 | |
|
| 1581 | 0 | if (index >= 0 && index+1 < parent.getChildren().size()){ |
| 1582 | 0 | Node<RuleTreeNode,String> child = parent.getChildren().get(index); |
| 1583 | 0 | Node<RuleTreeNode,String> nextSibling = parent.getChildren().get(index+2); |
| 1584 | |
|
| 1585 | 0 | if(RuleTreeNode.COMPOUND_NODE_TYPE.equalsIgnoreCase(nextSibling.getNodeType()) ){ |
| 1586 | |
|
| 1587 | 0 | PropositionBo prop = parent.getData().getProposition().getCompoundComponents().remove(index/2); |
| 1588 | |
|
| 1589 | 0 | nextSibling.getData().getProposition().getCompoundComponents().add(0, prop); |
| 1590 | 0 | rule.refreshPropositionTree(false); |
| 1591 | |
} |
| 1592 | |
} |
| 1593 | |
} |
| 1594 | 0 | return super.updateComponent(form, result, request, response); |
| 1595 | |
} |
| 1596 | |
|
| 1597 | |
|
| 1598 | |
@RequestMapping(params = "methodToCall=" + "cutProposition") |
| 1599 | |
public ModelAndView cutProposition(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1600 | |
HttpServletRequest request, HttpServletResponse response) |
| 1601 | |
throws Exception { |
| 1602 | |
|
| 1603 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 1604 | 0 | String selectedPropId = agendaEditor.getSelectedPropositionId(); |
| 1605 | 0 | agendaEditor.setCutPropositionId(selectedPropId); |
| 1606 | |
|
| 1607 | 0 | return super.updateComponent(form, result, request, response); |
| 1608 | |
} |
| 1609 | |
|
| 1610 | |
@RequestMapping(params = "methodToCall=" + "pasteProposition") |
| 1611 | |
public ModelAndView pasteProposition(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1612 | |
HttpServletRequest request, HttpServletResponse response) |
| 1613 | |
throws Exception { |
| 1614 | |
|
| 1615 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 1616 | 0 | RuleBo rule = agendaEditor.getAgendaItemLine().getRule(); |
| 1617 | |
|
| 1618 | |
|
| 1619 | 0 | String cutPropId = agendaEditor.getCutPropositionId(); |
| 1620 | 0 | String selectedPropId = agendaEditor.getSelectedPropositionId(); |
| 1621 | |
|
| 1622 | 0 | if (selectedPropId == cutPropId) { |
| 1623 | |
|
| 1624 | |
} else { |
| 1625 | |
|
| 1626 | |
|
| 1627 | 0 | Node<RuleTreeNode, String> root = rule.getPropositionTree().getRootElement(); |
| 1628 | |
|
| 1629 | 0 | if (StringUtils.isNotBlank(selectedPropId) && StringUtils.isNotBlank(cutPropId)) { |
| 1630 | 0 | Node<RuleTreeNode,String> parentNode = findParentPropositionNode(root, selectedPropId); |
| 1631 | |
PropositionBo newParent; |
| 1632 | 0 | if (parentNode == root){ |
| 1633 | |
|
| 1634 | |
|
| 1635 | |
|
| 1636 | |
|
| 1637 | 0 | newParent = PropositionBo.createCompoundPropositionBoStub2( |
| 1638 | |
root.getChildren().get(0).getData().getProposition()); |
| 1639 | 0 | newParent.setEditMode(true); |
| 1640 | 0 | rule.setProposition(newParent); |
| 1641 | |
} else { |
| 1642 | 0 | newParent = parentNode.getData().getProposition(); |
| 1643 | |
} |
| 1644 | 0 | PropositionBo oldParent = findParentPropositionNode(root, cutPropId).getData().getProposition(); |
| 1645 | |
|
| 1646 | 0 | PropositionBo workingProp = null; |
| 1647 | |
|
| 1648 | 0 | if (oldParent != null){ |
| 1649 | 0 | List <PropositionBo> children = oldParent.getCompoundComponents(); |
| 1650 | 0 | for( int index=0; index< children.size(); index++){ |
| 1651 | 0 | if (cutPropId.equalsIgnoreCase(children.get(index).getId())){ |
| 1652 | 0 | workingProp = oldParent.getCompoundComponents().remove(index); |
| 1653 | 0 | break; |
| 1654 | |
} |
| 1655 | |
} |
| 1656 | |
} |
| 1657 | |
|
| 1658 | |
|
| 1659 | 0 | if (newParent != null && workingProp != null){ |
| 1660 | 0 | List <PropositionBo> children = newParent.getCompoundComponents(); |
| 1661 | 0 | for( int index=0; index< children.size(); index++){ |
| 1662 | 0 | if (selectedPropId.equalsIgnoreCase(children.get(index).getId())){ |
| 1663 | 0 | children.add(index+1, workingProp); |
| 1664 | 0 | break; |
| 1665 | |
} |
| 1666 | |
} |
| 1667 | |
} |
| 1668 | |
|
| 1669 | |
|
| 1670 | 0 | rule.refreshPropositionTree(false); |
| 1671 | |
} |
| 1672 | |
} |
| 1673 | 0 | agendaEditor.setCutPropositionId(null); |
| 1674 | |
|
| 1675 | 0 | return super.updateComponent(form, result, request, response); |
| 1676 | |
} |
| 1677 | |
|
| 1678 | |
@RequestMapping(params = "methodToCall=" + "deleteProposition") |
| 1679 | |
public ModelAndView deleteProposition(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1680 | |
HttpServletRequest request, HttpServletResponse response) |
| 1681 | |
throws Exception { |
| 1682 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 1683 | 0 | String selectedPropId = agendaEditor.getSelectedPropositionId(); |
| 1684 | 0 | Node<RuleTreeNode, String> root = agendaEditor.getAgendaItemLine().getRule().getPropositionTree().getRootElement(); |
| 1685 | |
|
| 1686 | 0 | PropositionBo parent = findParentPropositionNode(root, selectedPropId).getData().getProposition(); |
| 1687 | 0 | if (parent != null){ |
| 1688 | 0 | List <PropositionBo> children = parent.getCompoundComponents(); |
| 1689 | 0 | for( int index=0; index< children.size(); index++){ |
| 1690 | 0 | if (selectedPropId.equalsIgnoreCase(children.get(index).getId())){ |
| 1691 | 0 | parent.getCompoundComponents().remove(index); |
| 1692 | 0 | break; |
| 1693 | |
} |
| 1694 | |
} |
| 1695 | |
} |
| 1696 | |
|
| 1697 | 0 | agendaEditor.getAgendaItemLine().getRule().refreshPropositionTree(false); |
| 1698 | 0 | return super.updateComponent(form, result, request, response); |
| 1699 | |
} |
| 1700 | |
|
| 1701 | |
@RequestMapping(params = "methodToCall=" + "updateCompoundOperator") |
| 1702 | |
public ModelAndView updateCompoundOperator(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 1703 | |
HttpServletRequest request, HttpServletResponse response) |
| 1704 | |
throws Exception { |
| 1705 | |
|
| 1706 | 0 | AgendaEditor agendaEditor = getAgendaEditor(form); |
| 1707 | 0 | RuleBo rule = agendaEditor.getAgendaItemLine().getRule(); |
| 1708 | 0 | rule.refreshPropositionTree(false); |
| 1709 | |
|
| 1710 | 0 | return super.updateComponent(form, result, request, response); |
| 1711 | |
} |
| 1712 | |
} |