001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.krms.impl.repository; 017 018 import org.kuali.rice.core.api.criteria.GenericQueryResults; 019 import org.kuali.rice.core.api.criteria.Predicate; 020 import org.kuali.rice.core.api.criteria.QueryByCriteria; 021 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; 022 import org.kuali.rice.krms.api.repository.RuleManagementService; 023 import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition; 024 import org.kuali.rice.krms.api.repository.agenda.AgendaItemDefinition; 025 import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplate; 026 import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage; 027 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition; 028 import org.kuali.rice.krms.api.repository.reference.ReferenceObjectBinding; 029 import org.kuali.rice.krms.api.repository.rule.RuleDefinition; 030 031 import java.util.ArrayList; 032 import java.util.Collections; 033 import java.util.LinkedHashSet; 034 import java.util.LinkedList; 035 import java.util.List; 036 import java.util.Set; 037 038 import static org.kuali.rice.core.api.criteria.PredicateFactory.in; 039 import org.kuali.rice.krad.service.BusinessObjectService; 040 import org.kuali.rice.krms.api.repository.NaturalLanguageTree; 041 import org.kuali.rice.krms.api.repository.action.ActionDefinition; 042 import org.kuali.rice.krms.api.repository.context.ContextDefinition; 043 import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplaterContract; 044 import org.kuali.rice.krms.api.repository.proposition.PropositionParameter; 045 import org.kuali.rice.krms.api.repository.proposition.PropositionParameterType; 046 import org.kuali.rice.krms.api.repository.proposition.PropositionType; 047 import org.kuali.rice.krms.api.repository.term.TermDefinition; 048 import org.kuali.rice.krms.api.repository.term.TermRepositoryService; 049 import org.kuali.rice.krms.impl.repository.language.SimpleNaturalLanguageTemplater; 050 051 /** 052 * The implementation of {@link RuleManagementService} operations facilitate management of rules and 053 * associated information. 054 * 055 * @author Kuali Rice Team (rice.collab@kuali.org) 056 */ 057 public class RuleManagementServiceImpl extends RuleRepositoryServiceImpl implements RuleManagementService { 058 059 private ReferenceObjectBindingBoService referenceObjectBindingBoService = new ReferenceObjectBindingBoServiceImpl(); 060 private AgendaBoService agendaBoService = new AgendaBoServiceImpl(); 061 private RuleBoService ruleBoService = new RuleBoServiceImpl(); 062 private ActionBoService actionBoService = new ActionBoServiceImpl(); 063 private PropositionBoService propositionBoService = new PropositionBoServiceImpl(); 064 private NaturalLanguageUsageBoService naturalLanguageUsageBoService = new NaturalLanguageUsageBoServiceImpl(); 065 private NaturalLanguageTemplateBoService naturalLanguageTemplateBoService = new NaturalLanguageTemplateBoServiceImpl(); 066 private ContextBoService contextBoService = new ContextBoServiceImpl(); 067 private NaturalLanguageTemplaterContract templater = new SimpleNaturalLanguageTemplater (); 068 private TermRepositoryService termRepositoryService = new TermBoServiceImpl (); 069 070 071 public ReferenceObjectBindingBoService getReferenceObjectBindingBoService() { 072 return referenceObjectBindingBoService; 073 } 074 075 public void setReferenceObjectBindingBoService(ReferenceObjectBindingBoService referenceObjectBindingBoService) { 076 this.referenceObjectBindingBoService = referenceObjectBindingBoService; 077 } 078 079 public AgendaBoService getAgendaBoService() { 080 return agendaBoService; 081 } 082 083 public void setAgendaBoService(AgendaBoService agendaBoService) { 084 this.agendaBoService = agendaBoService; 085 } 086 087 public RuleBoService getRuleBoService() { 088 return ruleBoService; 089 } 090 091 public void setRuleBoService(RuleBoService ruleBoService) { 092 this.ruleBoService = ruleBoService; 093 } 094 095 public PropositionBoService getPropositionBoService() { 096 return propositionBoService; 097 } 098 099 public void setPropositionBoService(PropositionBoService propositionBoService) { 100 this.propositionBoService = propositionBoService; 101 } 102 103 public NaturalLanguageUsageBoService getNaturalLanguageUsageBoService() { 104 return naturalLanguageUsageBoService; 105 } 106 107 public void setNaturalLanguageUsageBoService(NaturalLanguageUsageBoService naturalLanguageUsageBoService) { 108 this.naturalLanguageUsageBoService = naturalLanguageUsageBoService; 109 } 110 111 public NaturalLanguageTemplateBoService getNaturalLanguageTemplateBoService() { 112 return naturalLanguageTemplateBoService; 113 } 114 115 public void setNaturalLanguageTemplateBoService(NaturalLanguageTemplateBoService naturalLanguageTemplateBoService) { 116 this.naturalLanguageTemplateBoService = naturalLanguageTemplateBoService; 117 } 118 119 public ContextBoService getContextBoService() { 120 return contextBoService; 121 } 122 123 public void setContextBoService(ContextBoService contextBoService) { 124 this.contextBoService = contextBoService; 125 } 126 127 public ActionBoService getActionBoService() { 128 return actionBoService; 129 } 130 131 public void setActionBoService(ActionBoService actionBoService) { 132 this.actionBoService = actionBoService; 133 } 134 135 public NaturalLanguageTemplaterContract getTemplater() { 136 return templater; 137 } 138 139 public void setTemplater(NaturalLanguageTemplaterContract templater) { 140 this.templater = templater; 141 } 142 143 public TermRepositoryService getTermRepositoryService() { 144 return termRepositoryService; 145 } 146 147 public void setTermRepositoryService(TermRepositoryService termRepositoryService) { 148 this.termRepositoryService = termRepositoryService; 149 } 150 151 //// 152 //// reference object binding methods 153 //// 154 @Override 155 public ReferenceObjectBinding createReferenceObjectBinding(ReferenceObjectBinding referenceObjectDefinition) 156 throws RiceIllegalArgumentException { 157 return referenceObjectBindingBoService.createReferenceObjectBinding(referenceObjectDefinition); 158 } 159 160 @Override 161 public ReferenceObjectBinding getReferenceObjectBinding(String id) throws RiceIllegalArgumentException { 162 return referenceObjectBindingBoService.getReferenceObjectBinding(id); 163 } 164 165 @Override 166 public List<ReferenceObjectBinding> getReferenceObjectBindings(List<String> ids) throws RiceIllegalArgumentException { 167 if (ids == null) { 168 throw new IllegalArgumentException("reference binding object ids must not be null"); 169 } 170 171 // Fetch BOs 172 List<ReferenceObjectBindingBo> bos = null; 173 if (ids.size() == 0) { 174 bos = Collections.emptyList(); 175 } else { 176 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create(); 177 List<Predicate> pList = new ArrayList<Predicate>(); 178 qBuilder.setPredicates(in("id", ids.toArray())); 179 GenericQueryResults<ReferenceObjectBindingBo> results = getCriteriaLookupService().lookup(ReferenceObjectBindingBo.class, qBuilder.build()); 180 181 bos = results.getResults(); 182 } 183 184 // Translate BOs 185 List<ReferenceObjectBinding> bindings = new LinkedList<ReferenceObjectBinding>(); 186 for (ReferenceObjectBindingBo bo : bos) { 187 ReferenceObjectBinding binding = ReferenceObjectBindingBo.to(bo); 188 bindings.add(binding); 189 } 190 return Collections.unmodifiableList(bindings); 191 } 192 193 @Override 194 public List<ReferenceObjectBinding> findReferenceObjectBindingsByReferenceObject(String referenceObjectReferenceDiscriminatorType, 195 String referenceObjectId) 196 throws RiceIllegalArgumentException { 197 if (referenceObjectReferenceDiscriminatorType == null) { 198 throw new RiceIllegalArgumentException("reference binding object discriminator type must not be null"); 199 } 200 if (referenceObjectId == null) { 201 throw new RiceIllegalArgumentException("reference object id must not be null"); 202 } 203 List<ReferenceObjectBinding> list = new ArrayList<ReferenceObjectBinding>(); 204 for (ReferenceObjectBinding binding : this.referenceObjectBindingBoService.findReferenceObjectBindingsByReferenceObject(referenceObjectId)) { 205 if (binding.getReferenceDiscriminatorType().equals(referenceObjectReferenceDiscriminatorType)) { 206 list.add(binding); 207 } 208 } 209 return list; 210 } 211 212 @Override 213 public List<ReferenceObjectBinding> findReferenceObjectBindingsByReferenceDiscriminatorType(String referenceObjectReferenceDiscriminatorType) throws RiceIllegalArgumentException { 214 return referenceObjectBindingBoService.findReferenceObjectBindingsByReferenceDiscriminatorType(referenceObjectReferenceDiscriminatorType); 215 } 216 217 @Override 218 public List<ReferenceObjectBinding> findReferenceObjectBindingsByKrmsDiscriminatorType(String referenceObjectKrmsDiscriminatorType) throws RiceIllegalArgumentException { 219 return referenceObjectBindingBoService.findReferenceObjectBindingsByKrmsDiscriminatorType(referenceObjectKrmsDiscriminatorType); 220 } 221 222 @Override 223 public List<ReferenceObjectBinding> findReferenceObjectBindingsByKrmsObject(String krmsObjectId) throws RiceIllegalArgumentException { 224 return referenceObjectBindingBoService.findReferenceObjectBindingsByKrmsObject(krmsObjectId); 225 } 226 227 @Override 228 public void updateReferenceObjectBinding(ReferenceObjectBinding referenceObjectBindingDefinition) 229 throws RiceIllegalArgumentException { 230 referenceObjectBindingBoService.updateReferenceObjectBinding(referenceObjectBindingDefinition); 231 } 232 233 @Override 234 public void deleteReferenceObjectBinding(String id) throws RiceIllegalArgumentException { 235 referenceObjectBindingBoService.deleteReferenceObjectBinding(id); 236 } 237 238 @Override 239 public List<String> findReferenceObjectBindingIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException { 240 return referenceObjectBindingBoService.findReferenceObjectBindingIds(queryByCriteria); 241 } 242 243 //// 244 //// agenda 245 //// 246 @Override 247 public AgendaDefinition createAgenda(AgendaDefinition agendaDefinition) throws RiceIllegalArgumentException { 248 return agendaBoService.createAgenda(agendaDefinition); 249 } 250 251 @Override 252 public AgendaDefinition getAgenda(String id) throws RiceIllegalArgumentException { 253 return agendaBoService.getAgendaByAgendaId(id); 254 } 255 256 @Override 257 public List<AgendaDefinition> getAgendasByContext(String contextId) throws RiceIllegalArgumentException { 258 return agendaBoService.getAgendasByContextId(contextId); 259 } 260 261 @Override 262 public void updateAgenda(AgendaDefinition agendaDefinition) throws RiceIllegalArgumentException { 263 agendaBoService.updateAgenda(agendaDefinition); 264 } 265 266 @Override 267 public void deleteAgenda(String id) throws RiceIllegalArgumentException { 268 agendaBoService.deleteAgenda(id); 269 } 270 271 @Override 272 public List<AgendaDefinition> getAgendasByType(String typeId) throws RiceIllegalArgumentException { 273 return agendaBoService.getAgendasByType(typeId); 274 } 275 276 @Override 277 public List<AgendaDefinition> getAgendasByTypeAndContext(String typeId, String contextId) 278 throws RiceIllegalArgumentException { 279 return agendaBoService.getAgendasByTypeAndContext(typeId, contextId); 280 } 281 282 //// 283 //// agenda item methods 284 //// 285 @Override 286 public AgendaItemDefinition createAgendaItem(AgendaItemDefinition agendaItemDefinition) throws RiceIllegalArgumentException { 287 return agendaBoService.createAgendaItem(agendaItemDefinition); 288 } 289 290 @Override 291 public AgendaItemDefinition getAgendaItem(String id) throws RiceIllegalArgumentException { 292 return agendaBoService.getAgendaItemById(id); 293 } 294 295 @Override 296 public List<AgendaItemDefinition> getAgendaItemsByType(String typeId) 297 throws RiceIllegalArgumentException { 298 return agendaBoService.getAgendaItemsByType(typeId); 299 } 300 301 @Override 302 public List<AgendaItemDefinition> getAgendaItemsByContext(String contextId) throws RiceIllegalArgumentException { 303 return agendaBoService.getAgendaItemsByContext(contextId); 304 } 305 306 @Override 307 public List<AgendaItemDefinition> getAgendaItemsByTypeAndContext(String typeId, String contextId) 308 throws RiceIllegalArgumentException { 309 return agendaBoService.getAgendaItemsByTypeAndContext(typeId, contextId); 310 } 311 312 @Override 313 public void deleteAgendaItem(String id) throws RiceIllegalArgumentException { 314 agendaBoService.deleteAgendaItem(id); 315 } 316 317 @Override 318 public void updateAgendaItem(AgendaItemDefinition agendaItemDefinition) throws RiceIllegalArgumentException { 319 agendaBoService.updateAgendaItem(agendaItemDefinition); 320 } 321 322 private void crossCheckPropId(RuleDefinition ruleDefinition) 323 throws RiceIllegalArgumentException { 324 // if both are set they better match 325 if (ruleDefinition.getPropId() != null && ruleDefinition.getProposition() != null) { 326 if (!ruleDefinition.getPropId().equals(ruleDefinition.getProposition().getId())) { 327 throw new RiceIllegalArgumentException("propId does not proposition.getId" + ruleDefinition.getPropId() + " " + ruleDefinition.getProposition().getId()); 328 } 329 } 330 } 331 332 333 //// 334 //// rule methods 335 //// 336 @Override 337 public RuleDefinition createRule(RuleDefinition ruleDefinition) throws RiceIllegalArgumentException { 338 // CREATE 339 if (ruleDefinition.getId() != null) { 340 RuleDefinition orig = this.getRule(ruleDefinition.getId()); 341 if (orig != null) { 342 throw new RiceIllegalArgumentException(ruleDefinition.getId()); 343 } 344 } 345 // if both are set they better match 346 crossCheckPropId (ruleDefinition); 347 RuleDefinition rule = ruleBoService.createRule(ruleDefinition); 348 return this.createPropositionIfNeeded(rule); 349 } 350 351 private RuleDefinition createPropositionIfNeeded(RuleDefinition rule) { 352 // no prop to create 353 if (rule.getProposition() == null) { 354 return rule; 355 } 356 // ojb will take care of props that have already been created 357 if (rule.getProposition().getId() != null) { 358 return rule; 359 } 360 // create the proposition 361 RuleDefinition.Builder ruleBldr = RuleDefinition.Builder.create(rule); 362 PropositionDefinition.Builder propBldr = ruleBldr.getProposition(); 363 propBldr.setRule(ruleBldr); 364 PropositionDefinition prop = this.createProposition(propBldr.build()); 365 // now update the rule so it holds the proposition id 366 propBldr = PropositionDefinition.Builder.create(prop); 367 ruleBldr.setProposition(propBldr); 368 this.ruleBoService.updateRule(ruleBldr.build()); 369 return this.getRule(ruleBldr.getId()); 370 } 371 372 373 374 @Override 375 public void updateRule(RuleDefinition ruleDefinition) throws RiceIllegalArgumentException { 376 crossCheckPropId (ruleDefinition); 377 ruleBoService.updateRule(ruleDefinition); 378 this.createPropositionIfNeeded(ruleDefinition); 379 } 380 381 @Override 382 public void deleteRule(String id) throws RiceIllegalArgumentException { 383 ruleBoService.deleteRule(id); 384 } 385 386 387 //// 388 //// action methods 389 //// 390 @Override 391 public ActionDefinition createAction(ActionDefinition actionDefinition) throws RiceIllegalArgumentException { 392 return actionBoService.createAction(actionDefinition); 393 } 394 395 @Override 396 public void updateAction(ActionDefinition actionDefinition) throws RiceIllegalArgumentException { 397 actionBoService.updateAction(actionDefinition); 398 } 399 400 @Override 401 public void deleteAction(String id) throws RiceIllegalArgumentException { 402 throw new RiceIllegalArgumentException ("not implemented yet because not supported by the bo service"); 403 // actionBoService.deleteAction(id); 404 } 405 406 @Override 407 public ActionDefinition getAction(String actionId) { 408 return actionBoService.getActionByActionId(actionId); 409 } 410 411 @Override 412 public List<ActionDefinition> getActions(List<String> actionIds) { 413 // TODO: implement this more efficiently by adding the builk op to the bo service and calling it 414 List<ActionDefinition> list = new ArrayList<ActionDefinition>(); 415 for (String id : actionIds) { 416 list.add(this.getAction(id)); 417 } 418 return list; 419 } 420 421 private void crossCheckPropositionParameters (PropositionDefinition propositionDefinition) { 422 // check that if the value and termValue are both supplied that they match 423 for (PropositionParameter param : propositionDefinition.getParameters()) { 424 if (param.getValue() != null && param.getTermValue() != null) { 425 if (!param.getValue().equals(param.getTermValue().getId())) { 426 throw new RiceIllegalArgumentException("value does not match termValue.id on param " 427 + param.getSequenceNumber() + " " + param.getValue() + " " + param.getTermValue().getId()); 428 } 429 } 430 } 431 } 432 433 434 //// 435 //// proposition methods 436 //// 437 @Override 438 public PropositionDefinition createProposition(PropositionDefinition propositionDefinition) throws RiceIllegalArgumentException { 439 // CREATE 440 if (propositionDefinition.getId() != null) { 441 PropositionDefinition orig = this.getProposition(propositionDefinition.getId()); 442 if (orig != null) { 443 throw new RiceIllegalArgumentException(propositionDefinition.getId()); 444 } 445 } 446 crossCheckPropositionParameters(propositionDefinition); 447 PropositionDefinition prop = propositionBoService.createProposition(propositionDefinition); 448 prop = createTermValuesIfNeeded(prop); 449 prop = createCompoundPropsIfNeeded (prop); 450 return prop; 451 } 452 453 private PropositionDefinition createTermValuesIfNeeded(PropositionDefinition prop) { 454 if (prop.getParameters() == null) { 455 return prop; 456 } 457 if (prop.getParameters().isEmpty ()) { 458 return prop; 459 } 460 boolean updated = false; 461 PropositionDefinition.Builder propBldr = PropositionDefinition.Builder.create(prop); 462 List<PropositionParameter.Builder> paramBldrs = new ArrayList<PropositionParameter.Builder> (); 463 for (PropositionParameter.Builder paramBldr : propBldr.getParameters()) { 464 paramBldrs.add(paramBldr); 465 // link the param the proposition's id 466 // not sure we need to do this but... 467 if (paramBldr.getPropId() == null) { 468 paramBldr.setPropId(propBldr.getId()); 469 updated = true; 470 } 471 // create the termvalue if it was specified 472 if (paramBldr.getTermValue() != null) { 473 TermDefinition termValue = paramBldr.getTermValue(); 474 // no id means it does not exist yet 475 if (termValue.getId() == null) { 476 termValue = this.termRepositoryService.createTerm(termValue); 477 paramBldr.setTermValue(termValue); 478 updated = true; 479 } 480 if (paramBldr.getValue() == null) { 481 paramBldr.setValue(termValue.getId()); 482 updated = true; 483 } 484 // TODO: do we have to worry about updates to Terms? 485 } 486 } 487 if (!updated) { 488 return prop; 489 } 490 propBldr.setParameters(paramBldrs); 491 this.propositionBoService.updateProposition(propBldr.build()); 492 prop = this.getProposition(propBldr.getId()); 493 return prop; 494 } 495 496 private PropositionDefinition createCompoundPropsIfNeeded(PropositionDefinition prop) { 497 if (prop.getCompoundComponents() == null) { 498 return prop; 499 } 500 if (prop.getCompoundComponents().isEmpty ()) { 501 return prop; 502 } 503 boolean updated = false; 504 PropositionDefinition.Builder propBldr = PropositionDefinition.Builder.create(prop); 505 List<PropositionDefinition.Builder> compPropBldrs = new ArrayList<PropositionDefinition.Builder>(); 506 for (PropositionDefinition.Builder compPropBldr : propBldr.getCompoundComponents()) { 507 if (compPropBldr.getId() == null) { 508 PropositionDefinition compProp = this.createProposition(compPropBldr.build()); 509 compPropBldrs.add(PropositionDefinition.Builder.create(compProp)); 510 updated = true; 511 } else { 512 compPropBldrs.add (compPropBldr); 513 } 514 if (compPropBldr.getRuleId() == null) { 515 compPropBldr.setRuleId(prop.getRuleId()); 516 updated = true; 517 } 518 } 519 if (!updated) { 520 return prop; 521 } 522 propBldr.setCompoundComponents(compPropBldrs); 523 this.propositionBoService.updateProposition(propBldr.build()); 524 prop = this.getProposition(propBldr.getId()); 525 return prop; 526 } 527 528 @Override 529 public PropositionDefinition getProposition(String id) throws RiceIllegalArgumentException { 530 PropositionDefinition proposition = propositionBoService.getPropositionById(id); 531 if (proposition == null) { 532 throw new RiceIllegalArgumentException (id); 533 } 534 proposition = this.replaceTermValues (proposition); 535 return proposition; 536 } 537 538 private PropositionDefinition replaceTermValues(PropositionDefinition proposition) { 539 // only do this for simple props 540 if (!PropositionType.SIMPLE.getCode ().equalsIgnoreCase (proposition.getPropositionTypeCode())) { 541 return proposition; 542 } 543 // that have parameters 544 if (proposition.getParameters() == null) { 545 return proposition; 546 } 547 if (proposition.getParameters().isEmpty()) { 548 return proposition; 549 } 550 boolean found = false; 551 List<PropositionParameter.Builder> params = new ArrayList<PropositionParameter.Builder> (proposition.getParameters().size()); 552 for (PropositionParameter param : proposition.getParameters()) { 553 if (!PropositionParameterType.TERM.getCode().equalsIgnoreCase (param.getParameterType())) { 554 params.add(PropositionParameter.Builder.create(param)); 555 continue; 556 } 557 // inflate the termValue 558 found = true; 559 TermDefinition termValue = this.termRepositoryService.getTerm(param.getValue()); 560 PropositionParameter.Builder bldr = PropositionParameter.Builder.create(param); 561 bldr.setTermValue(termValue); 562 params.add(bldr); 563 } 564 if (!found) { 565 return proposition; 566 } 567 PropositionDefinition.Builder bldr = PropositionDefinition.Builder.create(proposition); 568 bldr.setParameters(params); 569 return bldr.build(); 570 } 571 572 573 private Set<PropositionDefinition> replaceTermValuesInSet(Set<PropositionDefinition> propositions) { 574 if (propositions == null) { 575 return null; 576 } 577 if (propositions.isEmpty()) { 578 return propositions; 579 } 580 Set<PropositionDefinition> set = new LinkedHashSet<PropositionDefinition>(propositions.size()); 581 for (PropositionDefinition proposition : propositions) { 582 proposition = this.replaceTermValues(proposition); 583 set.add(proposition); 584 } 585 return set; 586 } 587 588 @Override 589 public Set<PropositionDefinition> getPropositionsByType(String typeId) throws RiceIllegalArgumentException { 590 return replaceTermValuesInSet (propositionBoService.getPropositionsByType(typeId)); 591 } 592 593 @Override 594 public Set<PropositionDefinition> getPropositionsByRule(String ruleId) throws RiceIllegalArgumentException { 595 return replaceTermValuesInSet (propositionBoService.getPropositionsByRule(ruleId)); 596 } 597 598 @Override 599 public void updateProposition(PropositionDefinition propositionDefinition) throws RiceIllegalArgumentException { 600 this.crossCheckPropositionParameters(propositionDefinition); 601 propositionBoService.updateProposition(propositionDefinition); 602 PropositionDefinition prop = this.getProposition(propositionDefinition.getId()); 603 prop = createTermValuesIfNeeded(prop); 604 createCompoundPropsIfNeeded (prop); 605 } 606 607 @Override 608 public void deleteProposition(String id) throws RiceIllegalArgumentException { 609 propositionBoService.deleteProposition(id); 610 } 611 612 //// 613 //// natural language usage methods 614 //// 615 @Override 616 public NaturalLanguageUsage createNaturalLanguageUsage(NaturalLanguageUsage naturalLanguageUsage) throws RiceIllegalArgumentException { 617 return naturalLanguageUsageBoService.createNaturalLanguageUsage(naturalLanguageUsage); 618 } 619 620 @Override 621 public NaturalLanguageUsage getNaturalLanguageUsage(String id) throws RiceIllegalArgumentException { 622 return naturalLanguageUsageBoService.getNaturalLanguageUsage(id); 623 } 624 625 @Override 626 public void updateNaturalLanguageUsage(NaturalLanguageUsage naturalLanguageUsage) throws RiceIllegalArgumentException { 627 naturalLanguageUsageBoService.updateNaturalLanguageUsage(naturalLanguageUsage); 628 } 629 630 @Override 631 public void deleteNaturalLanguageUsage(String naturalLanguageUsageId) throws RiceIllegalArgumentException { 632 naturalLanguageUsageBoService.deleteNaturalLanguageUsage(naturalLanguageUsageId); 633 } 634 635 @Override 636 public List<NaturalLanguageUsage> getNaturalLanguageUsagesByNamespace(String namespace) 637 throws RiceIllegalArgumentException { 638 return this.naturalLanguageUsageBoService.findNaturalLanguageUsagesByNamespace(namespace); 639 } 640 641 @Override 642 public NaturalLanguageUsage getNaturalLanguageUsageByNameAndNamespace(String name, String namespace) 643 throws RiceIllegalArgumentException { 644 return this.naturalLanguageUsageBoService.getNaturalLanguageUsageByName(namespace, name); 645 } 646 647 648 //// 649 //// natural language translations 650 //// 651 @Override 652 public String translateNaturalLanguageForObject(String naturalLanguageUsageId, 653 String typeId, 654 String krmsObjectId, 655 String languageCode) 656 throws RiceIllegalArgumentException { 657 TranslationUtility util = new TranslationUtility (this, this.templater); 658 return util.translateNaturalLanguageForObject(naturalLanguageUsageId, typeId, krmsObjectId, languageCode); 659 } 660 661 @Override 662 public String translateNaturalLanguageForProposition(String naturalLanguageUsageId, 663 PropositionDefinition proposition, String languageCode) 664 throws RiceIllegalArgumentException { 665 TranslationUtility util = new TranslationUtility (this, this.templater); 666 return util.translateNaturalLanguageForProposition(naturalLanguageUsageId, proposition, languageCode); 667 } 668 669 @Override 670 public NaturalLanguageTree translateNaturalLanguageTreeForProposition(String naturalLanguageUsageId, 671 PropositionDefinition propositionDefinintion, 672 String languageCode) throws RiceIllegalArgumentException { 673 TranslationUtility util = new TranslationUtility (this, this.templater); 674 return util.translateNaturalLanguageTreeForProposition(naturalLanguageUsageId, propositionDefinintion, languageCode); 675 } 676 677 678 679 //// 680 //// context methods 681 //// 682 @Override 683 public ContextDefinition createContext(ContextDefinition contextDefinition) throws RiceIllegalArgumentException { 684 return this.contextBoService.createContext(contextDefinition); 685 } 686 687 688 @Override 689 public ContextDefinition findCreateContext(ContextDefinition contextDefinition) throws RiceIllegalArgumentException { 690 ContextDefinition orig = this.contextBoService.getContextByNameAndNamespace(contextDefinition.getName(), contextDefinition.getNamespace()); 691 if (orig != null) { 692 return orig; 693 } 694 return this.contextBoService.createContext(contextDefinition); 695 } 696 697 @Override 698 public void updateContext(ContextDefinition contextDefinition) throws RiceIllegalArgumentException { 699 this.contextBoService.updateContext(contextDefinition); 700 } 701 702 @Override 703 public void deleteContext(String id) throws RiceIllegalArgumentException { 704 throw new RiceIllegalArgumentException("not implemented yet"); 705 } 706 707 @Override 708 public ContextDefinition getContext(String id) throws RiceIllegalArgumentException { 709 return this.contextBoService.getContextByContextId(id); 710 } 711 712 @Override 713 public ContextDefinition getContextByNameAndNamespace(String name, String namespace) throws RiceIllegalArgumentException { 714 return this.contextBoService.getContextByNameAndNamespace(name, namespace); 715 } 716 717 //// 718 //// natural language templates 719 //// 720 @Override 721 public NaturalLanguageTemplate createNaturalLanguageTemplate(NaturalLanguageTemplate naturalLanguageTemplate) throws RiceIllegalArgumentException { 722 return this.naturalLanguageTemplateBoService.createNaturalLanguageTemplate(naturalLanguageTemplate); 723 } 724 725 @Override 726 public NaturalLanguageTemplate getNaturalLanguageTemplate(String naturalLanguageTemplateId) throws RiceIllegalArgumentException { 727 return this.naturalLanguageTemplateBoService.getNaturalLanguageTemplate(naturalLanguageTemplateId); 728 } 729 730 @Override 731 public void updateNaturalLanguageTemplate(NaturalLanguageTemplate naturalLanguageTemplate) throws RiceIllegalArgumentException { 732 this.naturalLanguageTemplateBoService.updateNaturalLanguageTemplate(naturalLanguageTemplate); 733 } 734 735 @Override 736 public void deleteNaturalLanguageTemplate(String naturalLanguageTemplateId) throws RiceIllegalArgumentException { 737 this.naturalLanguageTemplateBoService.deleteNaturalLanguageTemplate(naturalLanguageTemplateId); 738 } 739 740 @Override 741 public List<NaturalLanguageTemplate> findNaturalLanguageTemplatesByLanguageCode(String languageCode) throws RiceIllegalArgumentException { 742 return this.naturalLanguageTemplateBoService.findNaturalLanguageTemplatesByLanguageCode(languageCode); 743 } 744 745 @Override 746 public NaturalLanguageTemplate findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(String languageCode, String typeId, String naturalLanguageUsageId) throws RiceIllegalArgumentException { 747 return this.naturalLanguageTemplateBoService.findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(languageCode, typeId, naturalLanguageUsageId); 748 } 749 750 @Override 751 public List<NaturalLanguageTemplate> findNaturalLanguageTemplatesByNaturalLanguageUsage(String naturalLanguageUsageId) throws RiceIllegalArgumentException { 752 return this.naturalLanguageTemplateBoService.findNaturalLanguageTemplatesByNaturalLanguageUsage(naturalLanguageUsageId); 753 } 754 755 @Override 756 public List<NaturalLanguageTemplate> findNaturalLanguageTemplatesByType(String typeId) throws RiceIllegalArgumentException { 757 return this.naturalLanguageTemplateBoService.findNaturalLanguageTemplatesByType(typeId); 758 } 759 760 @Override 761 public List<NaturalLanguageTemplate> findNaturalLanguageTemplatesByTemplate(String template) throws RiceIllegalArgumentException { 762 return this.naturalLanguageTemplateBoService.findNaturalLanguageTemplatesByTemplate(template); 763 } 764 765 @Override 766 public List<String> findContextIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException { 767 GenericQueryResults<ContextBo> results = getCriteriaLookupService().lookup(ContextBo.class, queryByCriteria); 768 List<String> list = new ArrayList<String> (); 769 for (ContextBo bo : results.getResults()) { 770 list.add (bo.getId()); 771 } 772 return list; 773 } 774 775 @Override 776 public List<String> findAgendaIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException { 777 GenericQueryResults<AgendaBo> results = getCriteriaLookupService().lookup(AgendaBo.class, queryByCriteria); 778 List<String> list = new ArrayList<String> (); 779 for (AgendaBo bo : results.getResults()) { 780 list.add (bo.getId()); 781 } 782 return list; 783 } 784 785 @Override 786 public List<String> findRuleIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException { 787 GenericQueryResults<RuleBo> results = getCriteriaLookupService().lookup(RuleBo.class, queryByCriteria); 788 List<String> list = new ArrayList<String> (); 789 for (RuleBo bo : results.getResults()) { 790 list.add (bo.getId()); 791 } 792 return list; 793 } 794 795 @Override 796 public List<String> findPropositionIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException { 797 GenericQueryResults<PropositionBo> results = getCriteriaLookupService().lookup(PropositionBo.class, queryByCriteria); 798 List<String> list = new ArrayList<String> (); 799 for (PropositionBo bo : results.getResults()) { 800 list.add (bo.getId()); 801 } 802 return list; 803 } 804 805 @Override 806 public List<String> findActionIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException { 807 GenericQueryResults<ActionBo> results = getCriteriaLookupService().lookup(ActionBo.class, queryByCriteria); 808 List<String> list = new ArrayList<String> (); 809 for (ActionBo bo : results.getResults()) { 810 list.add (bo.getId()); 811 } 812 return list; 813 } 814 815 816 /** 817 * Sets the businessObjectService property. 818 * 819 * @param businessObjectService The businessObjectService to set. 820 */ 821 @Override 822 public void setBusinessObjectService(final BusinessObjectService businessObjectService) { 823 super.setBusinessObjectService(businessObjectService); 824 if (referenceObjectBindingBoService instanceof ReferenceObjectBindingBoServiceImpl) { 825 ((ReferenceObjectBindingBoServiceImpl) referenceObjectBindingBoService).setBusinessObjectService(businessObjectService); 826 } 827 if (agendaBoService instanceof AgendaBoServiceImpl) { 828 ((AgendaBoServiceImpl) agendaBoService).setBusinessObjectService(businessObjectService); 829 } 830 if (ruleBoService instanceof RuleBoServiceImpl) { 831 ((RuleBoServiceImpl) ruleBoService).setBusinessObjectService(businessObjectService); 832 } 833 if (actionBoService instanceof ActionBoServiceImpl) { 834 ((ActionBoServiceImpl) actionBoService).setBusinessObjectService(businessObjectService); 835 } 836 if (propositionBoService instanceof PropositionBoServiceImpl) { 837 ((PropositionBoServiceImpl) propositionBoService).setBusinessObjectService(businessObjectService); 838 } 839 if (naturalLanguageUsageBoService instanceof NaturalLanguageUsageBoServiceImpl) { 840 ((NaturalLanguageUsageBoServiceImpl) naturalLanguageUsageBoService).setBusinessObjectService(businessObjectService); 841 } 842 if (naturalLanguageTemplateBoService instanceof NaturalLanguageTemplateBoServiceImpl) { 843 ((NaturalLanguageTemplateBoServiceImpl) naturalLanguageTemplateBoService).setBusinessObjectService(businessObjectService); 844 } 845 if (contextBoService instanceof ContextBoServiceImpl) { 846 ((ContextBoServiceImpl) contextBoService).setBusinessObjectService(businessObjectService); 847 } 848 if (termRepositoryService instanceof TermBoServiceImpl) { 849 ((TermBoServiceImpl) termRepositoryService).setBusinessObjectService(businessObjectService); 850 } 851 } 852 }