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.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.criteria.GenericQueryResults;
20 import org.kuali.rice.core.api.criteria.Predicate;
21 import org.kuali.rice.core.api.criteria.QueryByCriteria;
22 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
23 import org.kuali.rice.krad.service.BusinessObjectService;
24 import org.kuali.rice.krms.api.repository.RuleManagementService;
25 import org.kuali.rice.krms.api.repository.TranslateBusinessMethods;
26 import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition;
27 import org.kuali.rice.krms.api.repository.agenda.AgendaItemDefinition;
28 import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplate;
29 import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
30 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
31 import org.kuali.rice.krms.api.repository.reference.ReferenceObjectBinding;
32 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
33
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.LinkedHashSet;
37 import java.util.LinkedList;
38 import java.util.List;
39 import java.util.Map;
40 import java.util.Set;
41
42 import org.kuali.rice.krad.service.KRADServiceLocator;
43 import org.kuali.rice.krad.service.SequenceAccessorService;
44 import org.kuali.rice.krms.api.repository.NaturalLanguageTree;
45 import org.kuali.rice.krms.api.repository.action.ActionDefinition;
46 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
47 import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplaterContract;
48 import org.kuali.rice.krms.api.repository.proposition.PropositionParameter;
49 import org.kuali.rice.krms.api.repository.proposition.PropositionParameterType;
50 import org.kuali.rice.krms.api.repository.proposition.PropositionType;
51 import org.kuali.rice.krms.api.repository.term.TermDefinition;
52 import org.kuali.rice.krms.api.repository.term.TermRepositoryService;
53 import org.kuali.rice.krms.impl.repository.language.SimpleNaturalLanguageTemplater;
54
55 import static org.kuali.rice.core.api.criteria.PredicateFactory.in;
56
57
58
59
60
61
62
63 public class RuleManagementServiceImpl extends RuleRepositoryServiceImpl implements RuleManagementService {
64
65 private ReferenceObjectBindingBoService referenceObjectBindingBoService = new ReferenceObjectBindingBoServiceImpl();
66 private AgendaBoService agendaBoService = new AgendaBoServiceImpl();
67 private RuleBoService ruleBoService = new RuleBoServiceImpl();
68 private ActionBoService actionBoService = new ActionBoServiceImpl();
69 private PropositionBoService propositionBoService = new PropositionBoServiceImpl();
70 private NaturalLanguageUsageBoService naturalLanguageUsageBoService = new NaturalLanguageUsageBoServiceImpl();
71 private NaturalLanguageTemplateBoService naturalLanguageTemplateBoService = new NaturalLanguageTemplateBoServiceImpl();
72 private ContextBoService contextBoService = new ContextBoServiceImpl();
73 private NaturalLanguageTemplaterContract templater = new SimpleNaturalLanguageTemplater();
74 private TermRepositoryService termRepositoryService = new TermBoServiceImpl();
75 private SequenceAccessorService sequenceAccessorService = null;
76 private TranslateBusinessMethods translationBusinessMethods = null;
77
78
79
80
81
82 public ReferenceObjectBindingBoService getReferenceObjectBindingBoService() {
83 return referenceObjectBindingBoService;
84 }
85
86
87
88
89
90 public void setReferenceObjectBindingBoService(ReferenceObjectBindingBoService referenceObjectBindingBoService) {
91 this.referenceObjectBindingBoService = referenceObjectBindingBoService;
92 }
93
94
95
96
97
98 public AgendaBoService getAgendaBoService() {
99 return agendaBoService;
100 }
101
102
103
104
105
106 public void setAgendaBoService(AgendaBoService agendaBoService) {
107 this.agendaBoService = agendaBoService;
108 }
109
110
111
112
113
114 public RuleBoService getRuleBoService() {
115 return ruleBoService;
116 }
117
118
119
120
121
122 public void setRuleBoService(RuleBoService ruleBoService) {
123 this.ruleBoService = ruleBoService;
124 }
125
126
127
128
129
130 public PropositionBoService getPropositionBoService() {
131 return propositionBoService;
132 }
133
134
135
136
137
138 public void setPropositionBoService(PropositionBoService propositionBoService) {
139 this.propositionBoService = propositionBoService;
140 }
141
142
143
144
145
146 public NaturalLanguageUsageBoService getNaturalLanguageUsageBoService() {
147 return naturalLanguageUsageBoService;
148 }
149
150
151
152
153
154 public void setNaturalLanguageUsageBoService(NaturalLanguageUsageBoService naturalLanguageUsageBoService) {
155 this.naturalLanguageUsageBoService = naturalLanguageUsageBoService;
156 }
157
158
159
160
161
162 public NaturalLanguageTemplateBoService getNaturalLanguageTemplateBoService() {
163 return naturalLanguageTemplateBoService;
164 }
165
166
167
168
169
170 public void setNaturalLanguageTemplateBoService(NaturalLanguageTemplateBoService naturalLanguageTemplateBoService) {
171 this.naturalLanguageTemplateBoService = naturalLanguageTemplateBoService;
172 }
173
174
175
176
177
178 public ContextBoService getContextBoService() {
179 return contextBoService;
180 }
181
182
183
184
185
186 public void setContextBoService(ContextBoService contextBoService) {
187 this.contextBoService = contextBoService;
188 }
189
190
191
192
193
194 public ActionBoService getActionBoService() {
195 return actionBoService;
196 }
197
198
199
200
201
202 public void setActionBoService(ActionBoService actionBoService) {
203 this.actionBoService = actionBoService;
204 }
205
206
207
208
209
210 public NaturalLanguageTemplaterContract getTemplater() {
211 return templater;
212 }
213
214
215
216
217
218 public void setTemplater(NaturalLanguageTemplaterContract templater) {
219 this.templater = templater;
220 }
221
222
223
224
225
226 public TermRepositoryService getTermRepositoryService() {
227 return termRepositoryService;
228 }
229
230
231
232
233
234 public void setTermRepositoryService(TermRepositoryService termRepositoryService) {
235 this.termRepositoryService = termRepositoryService;
236 }
237
238
239
240
241
242 public SequenceAccessorService getSequenceAccessorService() {
243 if (this.sequenceAccessorService == null) {
244 this.sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService();
245 }
246 return sequenceAccessorService;
247 }
248
249
250
251
252
253 public void setSequenceAccessorService(SequenceAccessorService sequenceAccessorService) {
254 this.sequenceAccessorService = sequenceAccessorService;
255 }
256
257
258
259
260
261 public TranslateBusinessMethods getTranslateBusinessMethods() {
262 if(translationBusinessMethods == null) {
263 this.translationBusinessMethods = new TranslationUtility(this, getTermRepositoryService(), this.templater);
264 }
265 return this.translationBusinessMethods ;
266 }
267
268
269
270
271
272 public void setTranslationBusinessMethods (TranslateBusinessMethods translationBusinessMethods) {
273 this.translationBusinessMethods = translationBusinessMethods;
274 }
275
276
277
278
279
280 @Override
281 public ReferenceObjectBinding createReferenceObjectBinding(ReferenceObjectBinding referenceObjectDefinition)
282 throws RiceIllegalArgumentException {
283
284 if (referenceObjectDefinition.getId() == null) {
285 String referenceObjectBindingId = getSequenceAccessorService().getNextAvailableSequenceNumber("KRMS_REF_OBJ_KRMS_OBJ_S", ReferenceObjectBindingBo.class).toString();
286 ReferenceObjectBinding.Builder refBldr = ReferenceObjectBinding.Builder.create(referenceObjectDefinition);
287 refBldr.setId(referenceObjectBindingId);
288 referenceObjectDefinition = refBldr.build();
289 }
290
291 return referenceObjectBindingBoService.createReferenceObjectBinding(referenceObjectDefinition);
292 }
293
294 @Override
295 public ReferenceObjectBinding getReferenceObjectBinding(String id) throws RiceIllegalArgumentException {
296 return referenceObjectBindingBoService.getReferenceObjectBinding(id);
297 }
298
299 @Override
300 public List<ReferenceObjectBinding> getReferenceObjectBindings(List<String> ids) throws RiceIllegalArgumentException {
301 if (ids == null) {
302 throw new IllegalArgumentException("reference binding object ids must not be null");
303 }
304
305
306 List<ReferenceObjectBindingBo> bos = null;
307
308 if (ids.size() == 0) {
309 bos = Collections.emptyList();
310 } else {
311 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
312 List<Predicate> pList = new ArrayList<Predicate>();
313 qBuilder.setPredicates(in("id", ids.toArray()));
314 GenericQueryResults<ReferenceObjectBindingBo> results = getCriteriaLookupService().lookup(ReferenceObjectBindingBo.class, qBuilder.build());
315
316 bos = results.getResults();
317 }
318
319
320 List<ReferenceObjectBinding> bindings = new LinkedList<ReferenceObjectBinding>();
321 for (ReferenceObjectBindingBo bo : bos) {
322 ReferenceObjectBinding binding = ReferenceObjectBindingBo.to(bo);
323 bindings.add(binding);
324 }
325
326 return Collections.unmodifiableList(bindings);
327 }
328
329 @Override
330 public List<ReferenceObjectBinding> findReferenceObjectBindingsByReferenceObject(String referenceObjectReferenceDiscriminatorType,
331 String referenceObjectId)
332 throws RiceIllegalArgumentException {
333 if (referenceObjectReferenceDiscriminatorType == null) {
334 throw new RiceIllegalArgumentException("reference binding object discriminator type must not be null");
335 }
336
337 if (referenceObjectId == null) {
338 throw new RiceIllegalArgumentException("reference object id must not be null");
339 }
340
341 List<ReferenceObjectBinding> list = new ArrayList<ReferenceObjectBinding>();
342 for (ReferenceObjectBinding binding : this.referenceObjectBindingBoService.findReferenceObjectBindingsByReferenceObject(referenceObjectId)) {
343 if (binding.getReferenceDiscriminatorType().equals(referenceObjectReferenceDiscriminatorType)) {
344 list.add(binding);
345 }
346 }
347
348 return list;
349 }
350
351 @Override
352 public List<ReferenceObjectBinding> findReferenceObjectBindingsByReferenceDiscriminatorType(String referenceObjectReferenceDiscriminatorType) throws RiceIllegalArgumentException {
353 return referenceObjectBindingBoService.findReferenceObjectBindingsByReferenceDiscriminatorType(referenceObjectReferenceDiscriminatorType);
354 }
355
356 @Override
357 public List<ReferenceObjectBinding> findReferenceObjectBindingsByKrmsDiscriminatorType(String referenceObjectKrmsDiscriminatorType) throws RiceIllegalArgumentException {
358 return referenceObjectBindingBoService.findReferenceObjectBindingsByKrmsDiscriminatorType(referenceObjectKrmsDiscriminatorType);
359 }
360
361 @Override
362 public List<ReferenceObjectBinding> findReferenceObjectBindingsByKrmsObject(String krmsObjectId) throws RiceIllegalArgumentException {
363 return referenceObjectBindingBoService.findReferenceObjectBindingsByKrmsObject(krmsObjectId);
364 }
365
366 @Override
367 public void updateReferenceObjectBinding(ReferenceObjectBinding referenceObjectBindingDefinition)
368 throws RiceIllegalArgumentException {
369 referenceObjectBindingBoService.updateReferenceObjectBinding(referenceObjectBindingDefinition);
370 }
371
372 @Override
373 public void deleteReferenceObjectBinding(String id) throws RiceIllegalArgumentException {
374 referenceObjectBindingBoService.deleteReferenceObjectBinding(id);
375 }
376
377 @Override
378 public List<String> findReferenceObjectBindingIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException {
379 return referenceObjectBindingBoService.findReferenceObjectBindingIds(queryByCriteria);
380 }
381
382
383
384
385 @Override
386 public AgendaDefinition createAgenda(AgendaDefinition agendaDefinition) throws RiceIllegalArgumentException {
387 return agendaBoService.createAgenda(agendaDefinition);
388 }
389
390 @Override
391 public AgendaDefinition getAgendaByNameAndContextId(String name, String contextId) {
392 return this.agendaBoService.getAgendaByNameAndContextId(name, contextId);
393 }
394
395 @Override
396 public AgendaDefinition findCreateAgenda(AgendaDefinition agendaDefinition) throws RiceIllegalArgumentException {
397 AgendaDefinition existing = this.getAgendaByNameAndContextId(agendaDefinition.getName(), agendaDefinition.getContextId());
398
399 if (existing != null) {
400 existing = this.updateAgendaIfNeeded(agendaDefinition, existing);
401 return existing;
402 }
403
404 return this.createAgenda(agendaDefinition);
405 }
406
407 private AgendaDefinition updateAgendaIfNeeded(AgendaDefinition agenda, AgendaDefinition existing) {
408 if (this.isSame(agenda, existing)) {
409 return existing;
410 }
411
412 AgendaDefinition.Builder bldr = AgendaDefinition.Builder.create(existing);
413 bldr.setActive(agenda.isActive());
414 bldr.setAttributes(agenda.getAttributes());
415 bldr.setContextId(agenda.getContextId());
416
417 if (agenda.getFirstItemId() != null) {
418 bldr.setFirstItemId(agenda.getFirstItemId());
419 }
420
421 bldr.setTypeId(agenda.getTypeId());
422 this.updateAgenda(bldr.build());
423
424 return this.getAgenda(existing.getId());
425 }
426
427 private boolean isSame(AgendaDefinition agenda, AgendaDefinition existing) {
428 if (!this.isSame(agenda.isActive(), existing.isActive())) {
429 return false;
430 }
431
432 if (!this.isSame(agenda.getAttributes(), existing.getAttributes())) {
433 return false;
434 }
435
436 if (!this.isSame(agenda.getContextId(), existing.getContextId())) {
437 return false;
438 }
439
440 if (!this.isSame(agenda.getFirstItemId(), existing.getFirstItemId())) {
441 return false;
442 }
443
444 if (!this.isSame(agenda.getName(), existing.getName())) {
445 return false;
446 }
447
448 if (!this.isSame(agenda.getTypeId(), existing.getTypeId())) {
449 return false;
450 }
451
452 return true;
453 }
454
455 private boolean isSame(boolean o1, boolean o2) {
456 if (o1 && !o2) {
457 return false;
458 }
459
460 if (!o1 && o2) {
461 return false;
462 }
463
464 return true;
465 }
466
467 private boolean isSame(Map<String, String> o1, Map<String, String> o2) {
468 if (o1 == null && o2 != null) {
469 return false;
470 }
471
472 if (o1 != null && o2 == null) {
473 return false;
474 }
475
476 return o1.equals(o2);
477 }
478
479 private boolean isSame(String o1, String o2) {
480 if (o1 == null && o2 != null) {
481 return false;
482 }
483
484 if (o1 != null && o2 == null) {
485 return false;
486 }
487
488 return o1.equals(o2);
489 }
490
491 @Override
492 public AgendaDefinition getAgenda(String id) throws RiceIllegalArgumentException {
493 return agendaBoService.getAgendaByAgendaId(id);
494 }
495
496 @Override
497 public List<AgendaDefinition> getAgendasByContext(String contextId) throws RiceIllegalArgumentException {
498 return agendaBoService.getAgendasByContextId(contextId);
499 }
500
501 @Override
502 public void updateAgenda(AgendaDefinition agendaDefinition) throws RiceIllegalArgumentException {
503 agendaBoService.updateAgenda(agendaDefinition);
504 }
505
506 @Override
507 public void deleteAgenda(String id) throws RiceIllegalArgumentException {
508 agendaBoService.deleteAgenda(id);
509 }
510
511 @Override
512 public List<AgendaDefinition> getAgendasByType(String typeId) throws RiceIllegalArgumentException {
513 return agendaBoService.getAgendasByType(typeId);
514 }
515
516 @Override
517 public List<AgendaDefinition> getAgendasByTypeAndContext(String typeId, String contextId)
518 throws RiceIllegalArgumentException {
519 return agendaBoService.getAgendasByTypeAndContext(typeId, contextId);
520 }
521
522
523
524
525 @Override
526 public AgendaItemDefinition createAgendaItem(AgendaItemDefinition agendaItemDefinition) throws RiceIllegalArgumentException {
527 agendaItemDefinition = createUpdateAgendaItemIfNeeded(agendaItemDefinition);
528 return agendaBoService.createAgendaItem(agendaItemDefinition);
529 }
530
531 private AgendaItemDefinition createUpdateAgendaItemIfNeeded(AgendaItemDefinition agendaItemDefinition) {
532 this.crossCheckRuleId(agendaItemDefinition);
533 this.crossCheckWhenTrueId(agendaItemDefinition);
534 this.crossCheckWhenFalseId(agendaItemDefinition);
535 this.crossCheckAlwaysId(agendaItemDefinition);
536 this.crossCheckSubAgendaId(agendaItemDefinition);
537 agendaItemDefinition = createUpdateRuleIfNeeded(agendaItemDefinition);
538 agendaItemDefinition = createWhenTrueAgendaItemIfNeeded(agendaItemDefinition);
539 agendaItemDefinition = createWhenFalseAgendaItemIfNeeded(agendaItemDefinition);
540 agendaItemDefinition = createAlwaysAgendaItemIfNeeded(agendaItemDefinition);
541 return createSubAgendaIfNeeded(agendaItemDefinition);
542 }
543
544 private void crossCheckRuleId(AgendaItemDefinition agendItemDefinition)
545 throws RiceIllegalArgumentException {
546
547 if (agendItemDefinition.getRuleId() != null && agendItemDefinition.getRule() != null) {
548 if (!agendItemDefinition.getRuleId().equals(agendItemDefinition.getRule().getId())) {
549 throw new RiceIllegalArgumentException("ruleId does not rule.getId" + agendItemDefinition.getRuleId() + " " + agendItemDefinition.getRule().getId());
550 }
551 }
552 }
553
554 private void crossCheckWhenTrueId(AgendaItemDefinition agendaItemDefinition)
555 throws RiceIllegalArgumentException {
556
557 if (agendaItemDefinition.getWhenTrueId()!= null && agendaItemDefinition.getWhenTrue() != null) {
558 if (!agendaItemDefinition.getWhenTrueId().equals(agendaItemDefinition.getWhenTrue().getId())) {
559 throw new RiceIllegalArgumentException("when true id does not match " + agendaItemDefinition.getWhenTrueId() + " " + agendaItemDefinition.getWhenTrue().getId());
560 }
561 }
562 }
563
564 private void crossCheckWhenFalseId(AgendaItemDefinition agendItemDefinition)
565 throws RiceIllegalArgumentException {
566
567 if (agendItemDefinition.getWhenFalseId()!= null && agendItemDefinition.getWhenFalse() != null) {
568 if (!agendItemDefinition.getWhenFalseId().equals(agendItemDefinition.getWhenFalse().getId())) {
569 throw new RiceIllegalArgumentException("when false id does not match " + agendItemDefinition.getWhenFalseId() + " " + agendItemDefinition.getWhenFalse().getId());
570 }
571 }
572 }
573
574 private void crossCheckAlwaysId(AgendaItemDefinition agendItemDefinition)
575 throws RiceIllegalArgumentException {
576
577 if (agendItemDefinition.getAlwaysId()!= null && agendItemDefinition.getAlways() != null) {
578 if (!agendItemDefinition.getAlwaysId().equals(agendItemDefinition.getAlways().getId())) {
579 throw new RiceIllegalArgumentException("Always id does not match " + agendItemDefinition.getAlwaysId() + " " + agendItemDefinition.getAlways().getId());
580 }
581 }
582 }
583
584 private void crossCheckSubAgendaId(AgendaItemDefinition agendItemDefinition)
585 throws RiceIllegalArgumentException {
586
587 if (agendItemDefinition.getSubAgendaId()!= null && agendItemDefinition.getSubAgenda() != null) {
588 if (!agendItemDefinition.getSubAgendaId().equals(agendItemDefinition.getSubAgenda().getId())) {
589 throw new RiceIllegalArgumentException("SubAgenda id does not match " + agendItemDefinition.getSubAgendaId() + " " + agendItemDefinition.getSubAgenda().getId());
590 }
591 }
592 }
593
594 private AgendaItemDefinition createUpdateRuleIfNeeded(AgendaItemDefinition agendaItemDefinition)
595 throws RiceIllegalArgumentException {
596
597 if (agendaItemDefinition.getRule() == null) {
598 return agendaItemDefinition;
599 }
600
601
602 if (agendaItemDefinition.getRule().getId() != null) {
603 this.updateRule(agendaItemDefinition.getRule());
604 RuleDefinition rule = this.getRule(agendaItemDefinition.getRule ().getId());
605 AgendaItemDefinition.Builder agendaItemBuilder = AgendaItemDefinition.Builder.create(agendaItemDefinition);
606 agendaItemBuilder.setRule(RuleDefinition.Builder.create(rule));
607 agendaItemBuilder.setRuleId(rule.getId());
608
609 return agendaItemBuilder.build();
610 }
611
612 AgendaItemDefinition.Builder agendaItemBuilder = AgendaItemDefinition.Builder.create(agendaItemDefinition);
613 RuleDefinition ruleDefinition = this.createRule(agendaItemDefinition.getRule());
614 RuleDefinition.Builder ruleBuilder = RuleDefinition.Builder.create(ruleDefinition);
615 agendaItemBuilder.setRule(ruleBuilder);
616 agendaItemBuilder.setRuleId(ruleBuilder.getId());
617
618 return agendaItemBuilder.build();
619 }
620
621 private AgendaItemDefinition createWhenTrueAgendaItemIfNeeded(AgendaItemDefinition agendaItemDefinition) {
622
623 if (agendaItemDefinition.getWhenTrue() == null) {
624 return agendaItemDefinition;
625 }
626
627
628 if (agendaItemDefinition.getWhenTrue().getId() != null) {
629 return agendaItemDefinition;
630 }
631
632
633 AgendaItemDefinition.Builder agendaItemBuilder = AgendaItemDefinition.Builder.create(agendaItemDefinition);
634 AgendaItemDefinition subAgendaItem = this.createUpdateAgendaItemIfNeeded(agendaItemDefinition.getWhenTrue());
635 agendaItemBuilder.setWhenTrue(AgendaItemDefinition.Builder.create(subAgendaItem));
636 agendaItemBuilder.setWhenTrueId(subAgendaItem.getId());
637
638 return agendaItemBuilder.build();
639 }
640
641
642 private AgendaItemDefinition createWhenFalseAgendaItemIfNeeded(AgendaItemDefinition agendaItemDefinition) {
643
644 if (agendaItemDefinition.getWhenFalse() == null) {
645 return agendaItemDefinition;
646 }
647
648
649 if (agendaItemDefinition.getWhenFalse().getId() != null) {
650 return agendaItemDefinition;
651 }
652
653
654 AgendaItemDefinition.Builder agendaItemBuilder = AgendaItemDefinition.Builder.create(agendaItemDefinition);
655 AgendaItemDefinition subAgendaItem = this.createUpdateAgendaItemIfNeeded(agendaItemDefinition.getWhenFalse());
656 agendaItemBuilder.setWhenFalse(AgendaItemDefinition.Builder.create(subAgendaItem));
657 agendaItemBuilder.setWhenFalseId(subAgendaItem.getId());
658 return agendaItemBuilder.build();
659 }
660
661
662 private AgendaItemDefinition createAlwaysAgendaItemIfNeeded(AgendaItemDefinition agendaItemDefinition) {
663
664 if (agendaItemDefinition.getAlways()== null) {
665 return agendaItemDefinition;
666 }
667
668 if (agendaItemDefinition.getAlways().getId() != null) {
669 return agendaItemDefinition;
670 }
671
672 AgendaItemDefinition.Builder agendaItemBuilder = AgendaItemDefinition.Builder.create(agendaItemDefinition);
673 AgendaItemDefinition subAgendaItem = this.createAgendaItem(agendaItemDefinition.getAlways());
674 agendaItemBuilder.setAlways(AgendaItemDefinition.Builder.create(subAgendaItem));
675 agendaItemBuilder.setAlwaysId(subAgendaItem.getId());
676
677 return agendaItemBuilder.build();
678 }
679
680 private AgendaItemDefinition createSubAgendaIfNeeded(AgendaItemDefinition agendaItemDefinition) {
681
682 if (agendaItemDefinition.getSubAgenda() == null) {
683 return agendaItemDefinition;
684 }
685
686
687 if (agendaItemDefinition.getSubAgenda().getId() != null) {
688 return agendaItemDefinition;
689 }
690
691 AgendaItemDefinition.Builder agendaItemBuilder = AgendaItemDefinition.Builder.create(agendaItemDefinition);
692 AgendaDefinition subAgenda = this.createAgenda(agendaItemDefinition.getSubAgenda());
693 agendaItemBuilder.setSubAgenda(AgendaDefinition.Builder.create(subAgenda));
694 agendaItemBuilder.setSubAgendaId(subAgenda.getId());
695
696 return agendaItemBuilder.build();
697 }
698
699 @Override
700 public AgendaItemDefinition getAgendaItem(String id) throws RiceIllegalArgumentException {
701 AgendaItemDefinition agendaItem = agendaBoService.getAgendaItemById(id);
702
703 if (agendaItem != null) {
704 return setTermValuesForAgendaItem(agendaItem).build();
705 }
706
707 return agendaItem;
708 }
709
710 private AgendaItemDefinition.Builder setTermValuesForAgendaItem(AgendaItemDefinition agendaItem) {
711 if (agendaItem == null){
712 return null;
713 }
714
715 AgendaItemDefinition.Builder itemBuiler = AgendaItemDefinition.Builder.create(agendaItem);
716 if (itemBuiler.getRule() != null) {
717
718 PropositionDefinition proposition = agendaItem.getRule().getProposition();
719 if (proposition != null) {
720 proposition = this.orderCompoundPropositionsIfNeeded(proposition);
721 itemBuiler.getRule().setProposition(this.replaceTermValues(proposition));
722 }
723 }
724
725
726 itemBuiler.setWhenTrue(setTermValuesForAgendaItem(agendaItem.getWhenTrue()));
727 itemBuiler.setWhenFalse(setTermValuesForAgendaItem(agendaItem.getWhenFalse()));
728 itemBuiler.setAlways(setTermValuesForAgendaItem(agendaItem.getAlways()));
729
730 return itemBuiler;
731 }
732
733 @Override
734 public List<AgendaItemDefinition> getAgendaItemsByType(String typeId)
735 throws RiceIllegalArgumentException {
736 return agendaBoService.getAgendaItemsByType(typeId);
737 }
738
739 @Override
740 public List<AgendaItemDefinition> getAgendaItemsByContext(String contextId) throws RiceIllegalArgumentException {
741 return agendaBoService.getAgendaItemsByContext(contextId);
742 }
743
744 @Override
745 public List<AgendaItemDefinition> getAgendaItemsByTypeAndContext(String typeId, String contextId)
746 throws RiceIllegalArgumentException {
747 return agendaBoService.getAgendaItemsByTypeAndContext(typeId, contextId);
748 }
749
750 @Override
751 public void deleteAgendaItem(String id) throws RiceIllegalArgumentException {
752 agendaBoService.deleteAgendaItem(id);
753 }
754
755 @Override
756 public void updateAgendaItem(AgendaItemDefinition agendaItemDefinition) throws RiceIllegalArgumentException {
757 agendaItemDefinition = createUpdateAgendaItemIfNeeded(agendaItemDefinition);
758 agendaBoService.updateAgendaItem(agendaItemDefinition);
759 }
760
761 private void crossCheckPropId(RuleDefinition ruleDefinition)
762 throws RiceIllegalArgumentException {
763
764 if (ruleDefinition.getPropId() != null && ruleDefinition.getProposition() != null) {
765 if (!ruleDefinition.getPropId().equals(ruleDefinition.getProposition().getId())) {
766 throw new RiceIllegalArgumentException("propId does not match proposition.getId" + ruleDefinition.getPropId() + " " + ruleDefinition.getProposition().getId());
767 }
768 }
769 }
770
771
772
773
774 @Override
775 public RuleDefinition getRuleByNameAndNamespace(String name, String namespace) {
776 return this.ruleBoService.getRuleByNameAndNamespace(name, namespace);
777 }
778
779
780 @Override
781 public RuleDefinition createRule(RuleDefinition ruleDefinition) throws RiceIllegalArgumentException {
782 if (ruleDefinition.getId() != null) {
783 RuleDefinition orig = this.getRule(ruleDefinition.getId());
784
785 if (orig != null) {
786 throw new RiceIllegalArgumentException(ruleDefinition.getId());
787 }
788 } else {
789
790 String ruleId = getSequenceAccessorService().getNextAvailableSequenceNumber("KRMS_RULE_S", RuleBo.class).toString();
791 RuleDefinition.Builder ruleBldr = RuleDefinition.Builder.create(ruleDefinition);
792 ruleBldr.setId(ruleId);
793 ruleDefinition = ruleBldr.build();
794 }
795
796
797 crossCheckPropId(ruleDefinition);
798 ruleDefinition = this.createUpdatePropositionIfNeeded(ruleDefinition);
799 ruleDefinition = ruleBoService.createRule(ruleDefinition);
800
801 return ruleDefinition;
802 }
803
804 private RuleDefinition createRuleIfNeeded(RuleDefinition ruleDefinition) throws RiceIllegalArgumentException {
805
806
807 if (ruleDefinition == null) {
808 return null;
809 }
810
811
812 if (ruleDefinition.getId() == null) {
813 String ruleId = getSequenceAccessorService().getNextAvailableSequenceNumber("KRMS_RULE_S", RuleBo.class).toString();
814 RuleDefinition.Builder ruleBldr = RuleDefinition.Builder.create(ruleDefinition);
815 ruleBldr.setId(ruleId);
816 ruleDefinition = ruleBldr.build();
817 }
818
819
820 crossCheckPropId(ruleDefinition);
821 ruleDefinition = this.createUpdatePropositionIfNeeded(ruleDefinition);
822
823 return ruleDefinition;
824 }
825
826 private RuleDefinition createUpdatePropositionIfNeeded(RuleDefinition rule) {
827
828 if (rule.getProposition() == null) {
829 return rule;
830 }
831
832
833 if (rule.getProposition().getId() != null) {
834 this.updateProposition(rule.getProposition());
835 PropositionDefinition prop = this.getProposition(rule.getProposition().getId());
836 RuleDefinition.Builder ruleBldr = RuleDefinition.Builder.create(rule);
837 ruleBldr.setProposition(PropositionDefinition.Builder.create(prop));
838 ruleBldr.setPropId(prop.getId());
839 return ruleBldr.build();
840 }
841
842
843 RuleDefinition.Builder ruleBldr = RuleDefinition.Builder.create(rule);
844 PropositionDefinition propositionDefinition = null;
845
846 PropositionDefinition.Builder propBldr = ruleBldr.getProposition();
847
848 if (rule.getProposition().getId() != null) {
849 this.crossCheckPropositionParameters(rule.getProposition());
850 propBldr = setSequenceOnCompoundPropositionsIfNeeded(propBldr);
851 propBldr = maintainTermValuesAndChildPropositions(propBldr);
852 } else {
853
854 propBldr.setRule(ruleBldr);
855 propositionDefinition = this.createProposition(propBldr.build());
856 propBldr = PropositionDefinition.Builder.create(propositionDefinition);
857 }
858
859
860 ruleBldr.setProposition(propBldr);
861
862 return ruleBldr.build();
863 }
864
865 @Override
866 public void updateRule(RuleDefinition ruleDefinition) throws RiceIllegalArgumentException {
867 crossCheckPropId(ruleDefinition);
868 ruleDefinition = this.createUpdatePropositionIfNeeded(ruleDefinition);
869
870 ruleBoService.updateRule(ruleDefinition);
871 }
872
873 @Override
874 public void deleteRule(String id) throws RiceIllegalArgumentException {
875 ruleBoService.deleteRule(id);
876 }
877
878
879
880
881 @Override
882 public ActionDefinition createAction(ActionDefinition actionDefinition) throws RiceIllegalArgumentException {
883 return actionBoService.createAction(actionDefinition);
884 }
885
886 @Override
887 public void updateAction(ActionDefinition actionDefinition) throws RiceIllegalArgumentException {
888 actionBoService.updateAction(actionDefinition);
889 }
890
891 @Override
892 public void deleteAction(String id) throws RiceIllegalArgumentException {
893 throw new RiceIllegalArgumentException("not implemented yet because not supported by the bo service");
894
895 }
896
897 @Override
898 public ActionDefinition getAction(String actionId) {
899 return actionBoService.getActionByActionId(actionId);
900 }
901
902 @Override
903 public List<ActionDefinition> getActions(List<String> actionIds) {
904
905 List<ActionDefinition> list = new ArrayList<ActionDefinition>();
906
907 for (String id : actionIds) {
908 list.add(this.getAction(id));
909 }
910
911 return list;
912 }
913
914 private void crossCheckPropositionParameters(PropositionDefinition propositionDefinition) {
915
916 for (PropositionParameter param : propositionDefinition.getParameters()) {
917 if (param.getValue() != null && param.getTermValue() != null) {
918 if (!param.getValue().equals(param.getTermValue().getId())) {
919 throw new RiceIllegalArgumentException("value does not match termValue.id on param "
920 + param.getSequenceNumber() + " " + param.getValue() + " " + param.getTermValue().getId());
921 }
922 }
923 }
924 }
925
926
927
928
929
930 @Override
931 public PropositionDefinition createProposition(PropositionDefinition propositionDefinition) throws RiceIllegalArgumentException {
932
933 if (propositionDefinition.getId() != null) {
934 PropositionDefinition orig = this.getProposition(propositionDefinition.getId());
935 if (orig != null) {
936 throw new RiceIllegalArgumentException(propositionDefinition.getId());
937 }
938 }
939
940 crossCheckPropositionParameters(propositionDefinition);
941 PropositionDefinition.Builder propBldr = PropositionDefinition.Builder.create(propositionDefinition);
942 propBldr = setSequenceOnCompoundPropositionsIfNeeded(propBldr);
943 propBldr = maintainTermValuesAndChildPropositions(propBldr);
944 PropositionDefinition prop = propositionBoService.createProposition(propBldr.build());
945
946 return prop;
947 }
948
949 private PropositionDefinition.Builder maintainTermValuesAndChildPropositions(PropositionDefinition.Builder propBldr) {
950 if (PropositionType.SIMPLE.getCode().equalsIgnoreCase(propBldr.getPropositionTypeCode())) {
951 return maintainTermValues(propBldr);
952 } else {
953 return createChildPropsIfNeeded(propBldr);
954 }
955 }
956
957 private PropositionDefinition.Builder maintainTermValues(PropositionDefinition.Builder propBldr) {
958 if (propBldr.getParameters() == null) {
959 return propBldr;
960 }
961
962 if (propBldr.getParameters().isEmpty()) {
963 return propBldr;
964 }
965
966 boolean updated = false;
967 List<PropositionParameter.Builder> paramBldrs = new ArrayList<PropositionParameter.Builder> ();
968
969 for (PropositionParameter.Builder paramBldr : propBldr.getParameters()) {
970 paramBldrs.add(paramBldr);
971
972
973
974 if (paramBldr.getPropId() == null) {
975 paramBldr.setPropId(propBldr.getId());
976 updated = true;
977 }
978
979
980 if (paramBldr.getTermValue() != null) {
981 TermDefinition termValue = paramBldr.getTermValue();
982
983
984 if (termValue.getId() == null) {
985 termValue = this.termRepositoryService.createTerm(termValue);
986 paramBldr.setTermValue(termValue);
987 updated = true;
988 } else {
989 this.termRepositoryService.updateTerm(termValue);
990 }
991
992 if ((paramBldr.getValue() == null) || (!paramBldr.getValue().equals(termValue.getId()))) {
993 paramBldr.setValue(termValue.getId());
994 updated = true;
995 }
996 }
997 }
998
999 if (!updated) {
1000 return propBldr;
1001 }
1002
1003 propBldr.setParameters(paramBldrs);
1004 return propBldr;
1005 }
1006
1007 private PropositionDefinition.Builder createChildPropsIfNeeded(PropositionDefinition.Builder propBldr) {
1008 if (propBldr.getCompoundComponents() == null) {
1009 return propBldr;
1010 }
1011
1012 if (propBldr.getCompoundComponents().isEmpty()) {
1013 return propBldr;
1014 }
1015
1016 List<PropositionDefinition.Builder> childPropBldrs = new ArrayList<PropositionDefinition.Builder>();
1017
1018 for (PropositionDefinition.Builder compPropBldr : propBldr.getCompoundComponents()) {
1019 compPropBldr.setRuleId(propBldr.getRuleId());
1020 propBldr = setSequenceOnCompoundPropositionsIfNeeded(propBldr);
1021 compPropBldr = maintainTermValuesAndChildPropositions(compPropBldr);
1022 childPropBldrs.add(compPropBldr);
1023 }
1024
1025 propBldr.setCompoundComponents(childPropBldrs);
1026
1027 return propBldr;
1028 }
1029
1030 @Override
1031 public PropositionDefinition getProposition(String id) throws RiceIllegalArgumentException {
1032 if (StringUtils.isBlank(id)) {
1033 throw new RiceIllegalArgumentException("Proposition id must not be null or blank");
1034 }
1035
1036 PropositionDefinition proposition = propositionBoService.getPropositionById(id);
1037
1038 if (proposition == null) {
1039 return null;
1040 }
1041
1042 proposition = this.replaceTermValues(proposition).build();
1043 proposition = this.orderCompoundPropositionsIfNeeded(proposition);
1044
1045 return proposition;
1046 }
1047
1048 private PropositionDefinition orderCompoundPropositionsIfNeeded(PropositionDefinition prop) {
1049 if (!prop.getPropositionTypeCode().equals(PropositionType.COMPOUND.getCode())) {
1050 return prop;
1051 }
1052
1053 if (prop.getCompoundComponents() == null) {
1054 return prop;
1055 }
1056
1057 if (prop.getCompoundComponents().size() <= 1) {
1058 return prop;
1059 }
1060
1061 PropositionDefinition.Builder propBldr = PropositionDefinition.Builder.create(prop);
1062 List<PropositionDefinition> childProps = new ArrayList<PropositionDefinition> (prop.getCompoundComponents());
1063 Collections.sort(childProps, new CompoundPropositionComparator());
1064 List<PropositionDefinition.Builder> childPropBldrs = new ArrayList<PropositionDefinition.Builder> (childProps.size());
1065
1066 for (PropositionDefinition chidProp : childProps) {
1067 PropositionDefinition.Builder childPropBlder = PropositionDefinition.Builder.create(chidProp);
1068 childPropBldrs.add(childPropBlder);
1069 }
1070
1071 propBldr.setCompoundComponents(childPropBldrs);
1072
1073 return propBldr.build();
1074 }
1075
1076 private PropositionDefinition.Builder replaceTermValues(PropositionDefinition proposition) {
1077
1078 PropositionDefinition.Builder bldr = PropositionDefinition.Builder.create(proposition);
1079
1080
1081 if (!PropositionType.SIMPLE.getCode().equalsIgnoreCase(proposition.getPropositionTypeCode())) {
1082 List<PropositionDefinition.Builder> cmpdProps = new ArrayList<PropositionDefinition.Builder>();
1083 for (PropositionDefinition cmpdProp : proposition.getCompoundComponents()) {
1084 cmpdProps.add(replaceTermValues(cmpdProp));
1085 }
1086 bldr.setCompoundComponents(cmpdProps);
1087 return bldr;
1088 }
1089
1090
1091 if (proposition.getParameters() == null) {
1092 return bldr;
1093 }
1094
1095 if (proposition.getParameters().isEmpty()) {
1096 return bldr;
1097 }
1098
1099 boolean found = false;
1100 List<PropositionParameter.Builder> params = new ArrayList<PropositionParameter.Builder>(proposition.getParameters().size());
1101
1102 for (PropositionParameter param : proposition.getParameters()) {
1103 if (!PropositionParameterType.TERM.getCode().equalsIgnoreCase(param.getParameterType())) {
1104 params.add(PropositionParameter.Builder.create(param));
1105 continue;
1106 }
1107
1108
1109 found = true;
1110 TermDefinition termValue = this.termRepositoryService.getTerm(param.getValue());
1111 PropositionParameter.Builder parmbldr = PropositionParameter.Builder.create(param);
1112 parmbldr.setTermValue(termValue);
1113 params.add(parmbldr);
1114 }
1115
1116 if (!found) {
1117 return bldr;
1118 }
1119
1120 bldr.setParameters(params);
1121
1122 return bldr;
1123 }
1124
1125
1126 private Set<PropositionDefinition> replaceTermValuesInSet(Set<PropositionDefinition> propositions) {
1127 if (propositions == null) {
1128 return null;
1129 }
1130
1131 if (propositions.isEmpty()) {
1132 return propositions;
1133 }
1134
1135 Set<PropositionDefinition> set = new LinkedHashSet<PropositionDefinition>(propositions.size());
1136 for (PropositionDefinition proposition : propositions) {
1137 proposition = this.replaceTermValues(proposition).build();
1138 set.add(proposition);
1139 }
1140
1141 return set;
1142 }
1143
1144 @Override
1145 public Set<PropositionDefinition> getPropositionsByType(String typeId) throws RiceIllegalArgumentException {
1146 return replaceTermValuesInSet(propositionBoService.getPropositionsByType(typeId));
1147 }
1148
1149 @Override
1150 public Set<PropositionDefinition> getPropositionsByRule(String ruleId) throws RiceIllegalArgumentException {
1151 return replaceTermValuesInSet(propositionBoService.getPropositionsByRule(ruleId));
1152 }
1153
1154 @Override
1155 public void updateProposition(PropositionDefinition propositionDefinition) throws RiceIllegalArgumentException {
1156 this.crossCheckPropositionParameters(propositionDefinition);
1157 PropositionDefinition.Builder propBldr = PropositionDefinition.Builder.create(propositionDefinition);
1158 propBldr = setSequenceOnCompoundPropositionsIfNeeded(propBldr);
1159 propBldr = maintainTermValuesAndChildPropositions(propBldr);
1160
1161 propositionBoService.updateProposition(propBldr.build());
1162 }
1163
1164 private PropositionDefinition.Builder setSequenceOnCompoundPropositionsIfNeeded(PropositionDefinition.Builder propBldr) {
1165 if (propBldr.getCompoundComponents() == null) {
1166 return propBldr;
1167 }
1168
1169 if (propBldr.getCompoundComponents().size() <= 1) {
1170 return propBldr;
1171 }
1172
1173 List<PropositionDefinition.Builder> childList = new ArrayList<PropositionDefinition.Builder>(propBldr.getCompoundComponents().size());
1174 int i = 1;
1175
1176 for (PropositionDefinition.Builder childPropBldr : propBldr.getCompoundComponents()) {
1177 childPropBldr.setCompoundSequenceNumber(i);
1178 i++;
1179 childList.add(childPropBldr);
1180 }
1181 propBldr.setCompoundComponents(childList);
1182 return propBldr;
1183 }
1184
1185 @Override
1186 public void deleteProposition(String id) throws RiceIllegalArgumentException {
1187 propositionBoService.deleteProposition(id);
1188 }
1189
1190
1191
1192
1193 @Override
1194 public NaturalLanguageUsage createNaturalLanguageUsage(NaturalLanguageUsage naturalLanguageUsage) throws RiceIllegalArgumentException {
1195 return naturalLanguageUsageBoService.createNaturalLanguageUsage(naturalLanguageUsage);
1196 }
1197
1198 @Override
1199 public NaturalLanguageUsage getNaturalLanguageUsage(String id) throws RiceIllegalArgumentException {
1200 return naturalLanguageUsageBoService.getNaturalLanguageUsage(id);
1201 }
1202
1203 @Override
1204 public void updateNaturalLanguageUsage(NaturalLanguageUsage naturalLanguageUsage) throws RiceIllegalArgumentException {
1205 naturalLanguageUsageBoService.updateNaturalLanguageUsage(naturalLanguageUsage);
1206 }
1207
1208 @Override
1209 public void deleteNaturalLanguageUsage(String naturalLanguageUsageId) throws RiceIllegalArgumentException {
1210 naturalLanguageUsageBoService.deleteNaturalLanguageUsage(naturalLanguageUsageId);
1211 }
1212
1213 @Override
1214 public List<NaturalLanguageUsage> getNaturalLanguageUsagesByNamespace(String namespace)
1215 throws RiceIllegalArgumentException {
1216 return this.naturalLanguageUsageBoService.findNaturalLanguageUsagesByNamespace(namespace);
1217 }
1218
1219 @Override
1220 public NaturalLanguageUsage getNaturalLanguageUsageByNameAndNamespace(String name, String namespace)
1221 throws RiceIllegalArgumentException {
1222 return this.naturalLanguageUsageBoService.getNaturalLanguageUsageByName(namespace, name);
1223 }
1224
1225
1226
1227
1228
1229 @Override
1230 public String translateNaturalLanguageForObject(String naturalLanguageUsageId,
1231 String typeId,
1232 String krmsObjectId,
1233 String languageCode)
1234 throws RiceIllegalArgumentException {
1235
1236 return this.getTranslateBusinessMethods().translateNaturalLanguageForObject(naturalLanguageUsageId, typeId, krmsObjectId, languageCode);
1237 }
1238
1239 @Override
1240 public String translateNaturalLanguageForProposition(String naturalLanguageUsageId,
1241 PropositionDefinition proposition, String languageCode)
1242 throws RiceIllegalArgumentException {
1243
1244 return this.getTranslateBusinessMethods().translateNaturalLanguageForProposition(naturalLanguageUsageId, proposition, languageCode);
1245 }
1246
1247 @Override
1248 public NaturalLanguageTree translateNaturalLanguageTreeForProposition(String naturalLanguageUsageId,
1249 PropositionDefinition propositionDefinintion, String languageCode) throws RiceIllegalArgumentException {
1250
1251 return getTranslateBusinessMethods().translateNaturalLanguageTreeForProposition(naturalLanguageUsageId,
1252 propositionDefinintion, languageCode);
1253 }
1254
1255
1256
1257
1258 @Override
1259 public ContextDefinition createContext(ContextDefinition contextDefinition) throws RiceIllegalArgumentException {
1260 return this.contextBoService.createContext(contextDefinition);
1261 }
1262
1263
1264 @Override
1265 public ContextDefinition findCreateContext(ContextDefinition contextDefinition) throws RiceIllegalArgumentException {
1266 ContextDefinition orig = this.contextBoService.getContextByNameAndNamespace(contextDefinition.getName(), contextDefinition.getNamespace());
1267
1268 if (orig != null) {
1269 return orig;
1270 }
1271
1272 return this.contextBoService.createContext(contextDefinition);
1273 }
1274
1275 @Override
1276 public void updateContext(ContextDefinition contextDefinition) throws RiceIllegalArgumentException {
1277 this.contextBoService.updateContext(contextDefinition);
1278 }
1279
1280 @Override
1281 public void deleteContext(String id) throws RiceIllegalArgumentException {
1282 throw new RiceIllegalArgumentException("not implemented yet");
1283 }
1284
1285 @Override
1286 public ContextDefinition getContext(String id) throws RiceIllegalArgumentException {
1287 return this.contextBoService.getContextByContextId(id);
1288 }
1289
1290 @Override
1291 public ContextDefinition getContextByNameAndNamespace(String name, String namespace) throws RiceIllegalArgumentException {
1292 return this.contextBoService.getContextByNameAndNamespace(name, namespace);
1293 }
1294
1295
1296
1297
1298 @Override
1299 public NaturalLanguageTemplate createNaturalLanguageTemplate(NaturalLanguageTemplate naturalLanguageTemplate) throws RiceIllegalArgumentException {
1300 return this.naturalLanguageTemplateBoService.createNaturalLanguageTemplate(naturalLanguageTemplate);
1301 }
1302
1303 @Override
1304 public NaturalLanguageTemplate getNaturalLanguageTemplate(String naturalLanguageTemplateId) throws RiceIllegalArgumentException {
1305 return this.naturalLanguageTemplateBoService.getNaturalLanguageTemplate(naturalLanguageTemplateId);
1306 }
1307
1308 @Override
1309 public void updateNaturalLanguageTemplate(NaturalLanguageTemplate naturalLanguageTemplate) throws RiceIllegalArgumentException {
1310 this.naturalLanguageTemplateBoService.updateNaturalLanguageTemplate(naturalLanguageTemplate);
1311 }
1312
1313 @Override
1314 public void deleteNaturalLanguageTemplate(String naturalLanguageTemplateId) throws RiceIllegalArgumentException {
1315 this.naturalLanguageTemplateBoService.deleteNaturalLanguageTemplate(naturalLanguageTemplateId);
1316 }
1317
1318 @Override
1319 public List<NaturalLanguageTemplate> findNaturalLanguageTemplatesByLanguageCode(String languageCode) throws RiceIllegalArgumentException {
1320 return this.naturalLanguageTemplateBoService.findNaturalLanguageTemplatesByLanguageCode(languageCode);
1321 }
1322
1323 @Override
1324 public NaturalLanguageTemplate findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(String languageCode, String typeId, String naturalLanguageUsageId) throws RiceIllegalArgumentException {
1325 return this.naturalLanguageTemplateBoService.findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId(languageCode, typeId, naturalLanguageUsageId);
1326 }
1327
1328 @Override
1329 public List<NaturalLanguageTemplate> findNaturalLanguageTemplatesByNaturalLanguageUsage(String naturalLanguageUsageId) throws RiceIllegalArgumentException {
1330 return this.naturalLanguageTemplateBoService.findNaturalLanguageTemplatesByNaturalLanguageUsage(naturalLanguageUsageId);
1331 }
1332
1333 @Override
1334 public List<NaturalLanguageTemplate> findNaturalLanguageTemplatesByType(String typeId) throws RiceIllegalArgumentException {
1335 return this.naturalLanguageTemplateBoService.findNaturalLanguageTemplatesByType(typeId);
1336 }
1337
1338 @Override
1339 public List<NaturalLanguageTemplate> findNaturalLanguageTemplatesByTemplate(String template) throws RiceIllegalArgumentException {
1340 return this.naturalLanguageTemplateBoService.findNaturalLanguageTemplatesByTemplate(template);
1341 }
1342
1343 @Override
1344 public List<String> findContextIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException {
1345 GenericQueryResults<ContextBo> results = getCriteriaLookupService().lookup(ContextBo.class, queryByCriteria);
1346
1347 List<String> list = new ArrayList<String> ();
1348 for (ContextBo bo : results.getResults()) {
1349 list.add(bo.getId());
1350 }
1351
1352 return list;
1353 }
1354
1355 @Override
1356 public List<String> findAgendaIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException {
1357 GenericQueryResults<AgendaBo> results = getCriteriaLookupService().lookup(AgendaBo.class, queryByCriteria);
1358 List<String> list = new ArrayList<String> ();
1359
1360 for (AgendaBo bo : results.getResults()) {
1361 list.add(bo.getId());
1362 }
1363
1364 return list;
1365 }
1366
1367 @Override
1368 public List<String> findRuleIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException {
1369 GenericQueryResults<RuleBo> results = getCriteriaLookupService().lookup(RuleBo.class, queryByCriteria);
1370 List<String> list = new ArrayList<String> ();
1371
1372 for (RuleBo bo : results.getResults()) {
1373 list.add(bo.getId());
1374 }
1375
1376 return list;
1377 }
1378
1379 @Override
1380 public List<String> findPropositionIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException {
1381 GenericQueryResults<PropositionBo> results = getCriteriaLookupService().lookup(PropositionBo.class, queryByCriteria);
1382
1383 List<String> list = new ArrayList<String> ();
1384 for (PropositionBo bo : results.getResults()) {
1385 list.add(bo.getId());
1386 }
1387
1388 return list;
1389 }
1390
1391 @Override
1392 public List<String> findActionIds(QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException {
1393 GenericQueryResults<ActionBo> results = getCriteriaLookupService().lookup(ActionBo.class, queryByCriteria);
1394
1395 List<String> list = new ArrayList<String> ();
1396 for (ActionBo bo : results.getResults()) {
1397 list.add(bo.getId());
1398 }
1399
1400 return list;
1401 }
1402
1403
1404
1405
1406
1407
1408 @Override
1409 public void setBusinessObjectService(final BusinessObjectService businessObjectService) {
1410 super.setBusinessObjectService(businessObjectService);
1411 if (referenceObjectBindingBoService instanceof ReferenceObjectBindingBoServiceImpl) {
1412 ((ReferenceObjectBindingBoServiceImpl) referenceObjectBindingBoService).setBusinessObjectService(businessObjectService);
1413 }
1414
1415 if (agendaBoService instanceof AgendaBoServiceImpl) {
1416 ((AgendaBoServiceImpl) agendaBoService).setBusinessObjectService(businessObjectService);
1417 }
1418
1419 if (ruleBoService instanceof RuleBoServiceImpl) {
1420 ((RuleBoServiceImpl) ruleBoService).setBusinessObjectService(businessObjectService);
1421 }
1422
1423 if (actionBoService instanceof ActionBoServiceImpl) {
1424 ((ActionBoServiceImpl) actionBoService).setBusinessObjectService(businessObjectService);
1425 }
1426
1427 if (propositionBoService instanceof PropositionBoServiceImpl) {
1428 ((PropositionBoServiceImpl) propositionBoService).setBusinessObjectService(businessObjectService);
1429 }
1430
1431 if (naturalLanguageUsageBoService instanceof NaturalLanguageUsageBoServiceImpl) {
1432 ((NaturalLanguageUsageBoServiceImpl) naturalLanguageUsageBoService).setBusinessObjectService(businessObjectService);
1433 }
1434
1435 if (naturalLanguageTemplateBoService instanceof NaturalLanguageTemplateBoServiceImpl) {
1436 ((NaturalLanguageTemplateBoServiceImpl) naturalLanguageTemplateBoService).setBusinessObjectService(businessObjectService);
1437 }
1438
1439 if (contextBoService instanceof ContextBoServiceImpl) {
1440 ((ContextBoServiceImpl) contextBoService).setBusinessObjectService(businessObjectService);
1441 }
1442
1443 if (termRepositoryService instanceof TermBoServiceImpl) {
1444 ((TermBoServiceImpl) termRepositoryService).setBusinessObjectService(businessObjectService);
1445 }
1446 }
1447 }