1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.repository;
17
18 import org.kuali.rice.core.api.criteria.GenericQueryResults;
19 import org.kuali.rice.core.api.criteria.Predicate;
20 import org.kuali.rice.core.api.criteria.QueryByCriteria;
21 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
22 import org.kuali.rice.krms.api.repository.RuleManagementService;
23 import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition;
24 import org.kuali.rice.krms.api.repository.agenda.AgendaItemDefinition;
25 import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplate;
26 import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
27 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
28 import org.kuali.rice.krms.api.repository.reference.ReferenceObjectBinding;
29 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
30
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.LinkedHashSet;
34 import java.util.LinkedList;
35 import java.util.List;
36 import java.util.Set;
37
38 import static org.kuali.rice.core.api.criteria.PredicateFactory.in;
39 import org.kuali.rice.krad.service.BusinessObjectService;
40 import org.kuali.rice.krms.api.repository.NaturalLanguageTree;
41 import org.kuali.rice.krms.api.repository.action.ActionDefinition;
42 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
43 import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplaterContract;
44 import org.kuali.rice.krms.api.repository.proposition.PropositionParameter;
45 import org.kuali.rice.krms.api.repository.proposition.PropositionParameterType;
46 import org.kuali.rice.krms.api.repository.proposition.PropositionType;
47 import org.kuali.rice.krms.api.repository.term.TermDefinition;
48 import org.kuali.rice.krms.api.repository.term.TermRepositoryService;
49 import org.kuali.rice.krms.impl.repository.language.SimpleNaturalLanguageTemplater;
50
51
52
53
54
55
56
57 public class RuleManagementServiceImpl extends RuleRepositoryServiceImpl implements RuleManagementService {
58
59 private ReferenceObjectBindingBoService referenceObjectBindingBoService = new ReferenceObjectBindingBoServiceImpl();
60 private AgendaBoService agendaBoService = new AgendaBoServiceImpl();
61 private RuleBoService ruleBoService = new RuleBoServiceImpl();
62 private ActionBoService actionBoService = new ActionBoServiceImpl();
63 private PropositionBoService propositionBoService = new PropositionBoServiceImpl();
64 private NaturalLanguageUsageBoService naturalLanguageUsageBoService = new NaturalLanguageUsageBoServiceImpl();
65 private NaturalLanguageTemplateBoService naturalLanguageTemplateBoService = new NaturalLanguageTemplateBoServiceImpl();
66 private ContextBoService contextBoService = new ContextBoServiceImpl();
67 private NaturalLanguageTemplaterContract templater = new SimpleNaturalLanguageTemplater ();
68 private TermRepositoryService termRepositoryService = new TermBoServiceImpl ();
69
70
71 public ReferenceObjectBindingBoService getReferenceObjectBindingBoService() {
72 return referenceObjectBindingBoService;
73 }
74
75 public void setReferenceObjectBindingBoService(ReferenceObjectBindingBoService referenceObjectBindingBoService) {
76 this.referenceObjectBindingBoService = referenceObjectBindingBoService;
77 }
78
79 public AgendaBoService getAgendaBoService() {
80 return agendaBoService;
81 }
82
83 public void setAgendaBoService(AgendaBoService agendaBoService) {
84 this.agendaBoService = agendaBoService;
85 }
86
87 public RuleBoService getRuleBoService() {
88 return ruleBoService;
89 }
90
91 public void setRuleBoService(RuleBoService ruleBoService) {
92 this.ruleBoService = ruleBoService;
93 }
94
95 public PropositionBoService getPropositionBoService() {
96 return propositionBoService;
97 }
98
99 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
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
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
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
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
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
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
335
336 @Override
337 public RuleDefinition createRule(RuleDefinition ruleDefinition) throws RiceIllegalArgumentException {
338
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
346 crossCheckPropId (ruleDefinition);
347 RuleDefinition rule = ruleBoService.createRule(ruleDefinition);
348 return this.createPropositionIfNeeded(rule);
349 }
350
351 private RuleDefinition createPropositionIfNeeded(RuleDefinition rule) {
352
353 if (rule.getProposition() == null) {
354 return rule;
355 }
356
357 if (rule.getProposition().getId() != null) {
358 return rule;
359 }
360
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
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
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
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
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
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
436
437 @Override
438 public PropositionDefinition createProposition(PropositionDefinition propositionDefinition) throws RiceIllegalArgumentException {
439
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
466
467 if (paramBldr.getPropId() == null) {
468 paramBldr.setPropId(propBldr.getId());
469 updated = true;
470 }
471
472 if (paramBldr.getTermValue() != null) {
473 TermDefinition termValue = paramBldr.getTermValue();
474
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
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
540 if (!PropositionType.SIMPLE.getCode ().equalsIgnoreCase (proposition.getPropositionTypeCode())) {
541 return proposition;
542 }
543
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
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
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
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
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
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
818
819
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 }