1   package org.kuali.ole.ingest;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.ingest.pojo.*;
5   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
6   import org.kuali.rice.kew.impl.peopleflow.PeopleFlowBo;
7   import org.kuali.rice.krad.service.BusinessObjectService;
8   import org.kuali.rice.krad.service.KRADServiceLocator;
9   import org.kuali.rice.krms.impl.repository.*;
10  
11  import java.io.IOException;
12  import java.net.URISyntaxException;
13  import java.util.*;
14  
15  
16  
17  
18  public class KrmsBuilder {
19  
20      private BusinessObjectService businessObjectService;
21      private TermBoService termBoService;
22      private KrmsObjectGeneratorFromXML krmsObjectGeneratorFromXML;
23      private ProfileBuilder profileBuilder = new ProfileBuilder();
24      private CategoryBo category;
25      private ContextBo context;
26      private AgendaBo agendaBo;
27      private RuleBo ruleBo;
28  
29      
30  
31  
32  
33  
34  
35  
36      public ContextBo createContext(String namespace, String contextName) {
37  
38          return profileBuilder.createContext(namespace,contextName);
39      }
40  
41      
42  
43  
44  
45  
46  
47  
48      public Object objectExists(Class objectClass, String key, String value) {
49  
50          return profileBuilder.objectExists(objectClass,key,value);
51      }
52  
53      
54  
55  
56  
57      private BusinessObjectService getBusinessObjectService() {
58          if (null == businessObjectService) {
59              businessObjectService = KRADServiceLocator.getBusinessObjectService();
60          }
61          return businessObjectService;
62      }
63  
64      
65  
66  
67  
68  
69  
70  
71      public CategoryBo createCategory(String namespace, String categoryName) {
72  
73          return profileBuilder.createCategory(namespace,categoryName);
74      }
75  
76      
77  
78  
79      public void registerDefaultFunctionLoader() {
80          profileBuilder.registerDefaultFunctionLoader();
81      }
82  
83      
84  
85  
86  
87  
88  
89  
90      public AgendaBo createAgenda(String agendaName, ContextBo contextBo) {
91  
92          return profileBuilder.createAgenda(agendaName, contextBo);
93      }
94  
95      
96  
97  
98  
99  
100 
101 
102 
103 
104 
105     public TermSpecificationBo createTermSpecification(String namespace, String termSpecificationName, String type, List<CategoryBo> categoryBoList, List<ContextBo> contextBoList) {
106 
107         return profileBuilder.createTermSpecification(namespace,termSpecificationName,type,categoryBoList,contextBoList);
108     }
109 
110     
111 
112 
113 
114     private TermBoService getTermBoService() {
115         if (null == termBoService) {
116             termBoService = GlobalResourceLoader.getService("termBoService");
117         }
118         return termBoService;
119     }
120 
121     
122 
123 
124 
125 
126 
127 
128     public TermBo createTerm(String name, TermSpecificationBo termSpecificationBo) {
129 
130         return profileBuilder.createTerm(name,termSpecificationBo);
131     }
132 
133     
134 
135 
136 
137 
138 
139 
140     public RuleBo createRule(String namespace, String ruleName) {
141 
142         return profileBuilder.createRule(namespace, ruleName);
143     }
144 
145     
146 
147 
148 
149 
150 
151 
152 
153     public AgendaBo addRuleToAgenda(AgendaBo agendaBo, RuleBo ruleBo,int count) {
154         AgendaItemBo agendaItemBo = new AgendaItemBo();
155         agendaItemBo.setAgendaId(agendaBo.getId());
156         agendaItemBo.setRule(ruleBo);
157         getBusinessObjectService().save(agendaItemBo);
158         List<AgendaItemBo> agendaBoItems = agendaBo.getItems();
159         if (null == agendaBoItems) {
160             agendaBoItems = new ArrayList<AgendaItemBo>();
161         }
162         agendaBoItems.add(agendaItemBo);
163         agendaBo.setItems(agendaBoItems);
164         agendaBo.setFirstItemId(agendaBoItems.get(0).getId());
165         if(count>-1){
166             AgendaItemBo updateAgendaItem = agendaBoItems.get(count);
167             updateAgendaItem.setAlways(agendaItemBo);
168             getBusinessObjectService().save(updateAgendaItem);
169         }
170         getBusinessObjectService().save(agendaBo);
171         return agendaBo;
172     }
173 
174     
175 
176 
177 
178 
179 
180 
181 
182 
183 
184     public PropositionBo createProposition(String categoryId, String propositionDescription, String propositionType, RuleBo rule,Integer seqNum) {
185         PropositionBo propositionBo = new PropositionBo();
186         propositionBo.setCategoryId(categoryId);
187         propositionBo.setDescription(propositionDescription);
188         propositionBo.setRuleId(rule.getId());
189         propositionBo.setPropositionTypeCode(propositionType);
190         propositionBo.setCompoundSequenceNumber(seqNum);
191         getBusinessObjectService().save(propositionBo);
192         return propositionBo;
193     }
194 
195     
196 
197 
198 
199 
200 
201 
202 
203 
204 
205     public PropositionBo createCompoundProposition(String categoryId, String propositionDescription, String propositionType, RuleBo rule,String operatorCode) {
206         PropositionBo propositionBo = new PropositionBo();
207         propositionBo.setCategoryId(categoryId);
208         propositionBo.setDescription(propositionDescription);
209         propositionBo.setRuleId(rule.getId());
210         propositionBo.setPropositionTypeCode(propositionType);
211         propositionBo.setCompoundOpCode(operatorCode);
212         getBusinessObjectService().save(propositionBo);
213         return propositionBo;
214     }
215 
216     
217 
218 
219 
220 
221 
222 
223 
224 
225 
226     public FunctionBo createFunction(String namespace, String termName, String returnType, List categories,String parameterType) {
227         Object existing = objectExists(FunctionBo.class, "nm", termName + "Function");
228         FunctionBo functionBo;
229         if (existing == null) {
230             HashMap<String, String> map = new HashMap<String, String>();
231             map.put("nm", "FunctionLoader");
232             List<KrmsTypeBo> matching =
233                     (List<KrmsTypeBo>) getBusinessObjectService().findMatching(KrmsTypeBo.class, map);
234             KrmsTypeBo krmsTypeBo = matching.get(0);
235             functionBo = new FunctionBo();
236             functionBo.setActive(true);
237             functionBo.setName(termName + "Function");
238             functionBo.setNamespace(namespace);
239             functionBo.setReturnType(returnType);
240             functionBo.setCategories(categories);
241             functionBo.setTypeId(krmsTypeBo.getId());
242             getBusinessObjectService().save(functionBo);
243 
244             FunctionParameterBo functionParameterBo = new FunctionParameterBo();
245             functionParameterBo.setFunctionId(functionBo.getId());
246             functionParameterBo.setParameterType(parameterType);
247             functionParameterBo.setName(termName);
248             functionParameterBo.setSequenceNumber(0);
249 
250             getBusinessObjectService().save(functionParameterBo);
251 
252             List<FunctionParameterBo> parameters = functionBo.getParameters();
253             if (null == parameters) {
254                 parameters = new ArrayList<FunctionParameterBo>();
255             }
256             parameters.add(functionParameterBo);
257             functionBo.setParameters(parameters);
258 
259             getBusinessObjectService().save(functionBo);
260         } else {
261             functionBo = (FunctionBo) existing;
262         }
263 
264         return functionBo;
265     }
266 
267     
268 
269 
270 
271 
272 
273 
274     public PropositionBo addTermToPropositionParameter(String termId, PropositionBo proposition) {
275 
276         return profileBuilder.addTermToPropositionParameter(termId,proposition);
277     }
278 
279     
280 
281 
282 
283 
284 
285 
286     public PropositionBo addOperatorToPropositionParameter(String operator,PropositionBo proposition){
287         PropositionParameterBo propositionParameterBo = new PropositionParameterBo();
288         propositionParameterBo.setPropId(proposition.getId());
289         propositionParameterBo.setValue(operator);
290         propositionParameterBo.setSequenceNumber(2);
291         propositionParameterBo.setParameterType("O");
292         getBusinessObjectService().save(propositionParameterBo);
293         List<PropositionParameterBo> parameters = proposition.getParameters();
294         if (null == parameters) {
295             parameters = new ArrayList<PropositionParameterBo>();
296         }
297         parameters.add(propositionParameterBo);
298         proposition.setParameters(parameters);
299         getBusinessObjectService().save(proposition);
300         return proposition;
301     }
302 
303     
304 
305 
306 
307 
308 
309 
310     public PropositionBo addConstantToPropositionParameter(String constant,PropositionBo proposition){
311         PropositionParameterBo propositionParameterBo = new PropositionParameterBo();
312         propositionParameterBo.setPropId(proposition.getId());
313         propositionParameterBo.setValue(constant);
314         propositionParameterBo.setSequenceNumber(1);
315         propositionParameterBo.setParameterType("C");
316         getBusinessObjectService().save(propositionParameterBo);
317         List<PropositionParameterBo> parameters = proposition.getParameters();
318         if (null == parameters) {
319             parameters = new ArrayList<PropositionParameterBo>();
320         }
321         parameters.add(propositionParameterBo);
322         proposition.setParameters(parameters);
323         getBusinessObjectService().save(proposition);
324         return proposition;
325     }
326 
327     
328 
329 
330 
331 
332 
333 
334     public PropositionBo addCustomFunctionToPropositionParameter(String functionId, PropositionBo proposition) {
335 
336         return profileBuilder.addCustomFunctionToPropositionParameter(functionId,proposition);
337     }
338 
339     
340 
341 
342 
343 
344     public String persist(OleAgenda oleAgenda) {
345         boolean agendaExists = doesKrmsExist(oleAgenda.getName());
346         if(agendaExists){
347             deleteAgenda(oleAgenda);
348         }
349         context = createContext(OLEConstants.OLE_NAMESPACE, oleAgenda.getContextName());
350         category = createCategory(OLEConstants.OLE_NAMESPACE, oleAgenda.getCategoryName());
351 
352         registerDefaultFunctionLoader();
353 
354         ContextValidActionBo contextValidActionBo = registerDefaultServiceTypes(context);
355 
356         agendaBo = createAgenda(oleAgenda.getName(), context);
357 
358         List<KrmsRule> rules = oleAgenda.getRules();
359         int count = -1;
360         for (Iterator<KrmsRule> iterator = rules.iterator(); iterator.hasNext(); ) {
361             KrmsRule rule = iterator.next();
362             ruleBo = createRule(OLEConstants.OLE_NAMESPACE, rule.getName());
363 
364             addRuleToAgenda(agendaBo, ruleBo,count);
365 
366             count++;
367             PropositionBo propositionBo =  null;
368 
369             if(rule.getProposition()!=null){
370                 propositionBo = createSimpleProposition(rule.getProposition(),1);
371             }
372             if(rule.getCompoundProposition()!=null){
373                 OleProposition oleProposition = rule.getCompoundProposition();
374                 List<PropositionBo> propositionBos = new ArrayList<PropositionBo>();
375                 propositionBos.addAll(createCompoundProposition(oleProposition, propositionBos));
376                 propositionBo = propositionBos.get(0);
377             }
378             ruleBo.setProposition(propositionBo);
379             getBusinessObjectService().save(ruleBo);
380             List<KrmsAction> trueActions =rule.getTrueActions()!=null && rule.getTrueActions().size()>0 ? rule.getTrueActions():new ArrayList<KrmsAction>();
381             for (Iterator<KrmsAction> oleActionIterator = trueActions.iterator(); oleActionIterator.hasNext(); ) {
382                 KrmsAction trueAction = oleActionIterator.next();
383                 contextValidActionBo = getContextValidActionBo(context,trueAction);
384                 ActionBo actionBo = addActionToRule(OLEConstants.OLE_NAMESPACE, trueAction.getName(), trueAction.getDescription(), contextValidActionBo.getActionTypeId(), ruleBo, trueAction.getSequenceNumber());
385                 addActionAttributes(actionBo,trueAction.getName());
386             }
387 
388             List<KrmsAction> falseActions = rule.getFalseActions()!=null && rule.getFalseActions().size()>0 ? rule.getFalseActions():new ArrayList<KrmsAction>();
389             for (Iterator<KrmsAction> oleActionIterator = falseActions.iterator(); oleActionIterator.hasNext(); ) {
390                 KrmsAction falseAction = oleActionIterator.next();
391                 RuleBo falseActionRuleBo = createRule(OLEConstants.OLE_NAMESPACE, rule.getName() + "_falseActionRule");
392                 addActionToRule(OLEConstants.OLE_NAMESPACE, falseAction.getName(), falseAction.getDescription(), contextValidActionBo.getActionTypeId(), falseActionRuleBo, falseAction.getSequenceNumber());
393                 addDummyRuleForFalseAction(ruleBo, falseActionRuleBo);
394             }
395 
396         }
397         persistProfileAttributes(oleAgenda);
398         return agendaBo.getName();
399     }
400 
401     
402 
403 
404 
405 
406     private List<PropositionBo> createCompoundProposition(OleProposition oleProposition, List<PropositionBo> propositionBos){
407 
408         if(oleProposition.getPropositions()!=null){
409             List<PropositionBo> propositionBoList = new ArrayList<PropositionBo>();
410             propositionBoList.add(createCompoundProposition(oleProposition.getPropositions(), oleProposition.getPropositionType()));
411             return propositionBoList;
412         } else if(oleProposition.getOlePropositions()!=null){
413             PropositionBo propositionBo =  null;
414             List<PropositionBo> propositionBoList = new ArrayList<PropositionBo>();
415             for(OleProposition oleProposition1 : oleProposition.getOlePropositions()){
416                 propositionBoList.addAll(createCompoundProposition(oleProposition1, propositionBoList));
417             }
418             propositionBo =  createCompoundProposition(category.getId(),"compound","C",ruleBo,oleProposition.getPropositionType());
419             propositionBo.setCompoundComponents(propositionBoList);
420             getBusinessObjectService().save(propositionBo);
421             propositionBoList = new ArrayList<PropositionBo>();
422             propositionBoList.add(propositionBo);
423             return propositionBoList;
424         }
425         return null;
426     }
427 
428     
429 
430 
431 
432 
433     private void addActionAttributes(ActionBo action,String peopleFlowName){
434         Map<String, String> peopleFlowPk = new HashMap<String, String>();
435         peopleFlowPk.put("nm", peopleFlowName);
436         List<PeopleFlowBo> peopleFlowBos =(List<PeopleFlowBo>) getBusinessObjectService().findMatching(PeopleFlowBo.class, peopleFlowPk);
437         if(peopleFlowBos!=null && peopleFlowBos.size()>0){
438             Map<String, String> attrDefPk = new HashMap<String, String>();
439             attrDefPk.put("attr_defn_id", "1000");
440             KrmsAttributeDefinitionBo peopleFlowIdDef = getBusinessObjectService().findByPrimaryKey(KrmsAttributeDefinitionBo.class,attrDefPk);
441 
442             attrDefPk = new HashMap<String, String>();
443             attrDefPk.put("attr_defn_id", "1006");
444             KrmsAttributeDefinitionBo peopleFlowNameDef = getBusinessObjectService().findByPrimaryKey(KrmsAttributeDefinitionBo.class,attrDefPk);
445 
446             Set<ActionAttributeBo> actionAttributeBos = new HashSet<ActionAttributeBo>();
447             String peopleFlowId =  peopleFlowBos.get(0).getId();
448             ActionAttributeBo actionAttributeBo = new ActionAttributeBo();
449             actionAttributeBo.setActionId(action.getId());
450             actionAttributeBo.setAttributeDefinitionId(peopleFlowIdDef.getId());
451             actionAttributeBo.setAttributeDefinition(peopleFlowIdDef);
452             actionAttributeBo.setValue(peopleFlowId);
453             getBusinessObjectService().save(actionAttributeBo);
454             actionAttributeBos.add(actionAttributeBo);
455 
456             actionAttributeBo = new ActionAttributeBo();
457             actionAttributeBo.setActionId(action.getId());
458             actionAttributeBo.setAttributeDefinitionId(peopleFlowNameDef.getId());
459             actionAttributeBo.setAttributeDefinition(peopleFlowNameDef);
460             actionAttributeBo.setValue(peopleFlowName);
461             getBusinessObjectService().save(actionAttributeBo);
462             actionAttributeBos.add(actionAttributeBo);
463 
464             action.setAttributeBos(actionAttributeBos);
465             getBusinessObjectService().save(action);
466 
467         }
468 
469     }
470 
471     
472 
473 
474 
475 
476 
477 
478     private ContextValidActionBo getContextValidActionBo(ContextBo contextBo,KrmsAction action){
479         KrmsTypeBo actionTypeService = getActiontypeService(action);
480         ContextValidActionBo contextValidActionBo =null;
481         if(actionTypeService!=null){
482             Object existing = objectExists(ContextValidActionBo.class, "actn_typ_id", actionTypeService.getId());
483             if (existing == null) {
484                 contextValidActionBo = new ContextValidActionBo();
485                 contextValidActionBo.setActionType(actionTypeService);
486                 contextValidActionBo.setActionTypeId(actionTypeService.getId());
487                 contextValidActionBo.setContextId(contextBo.getId());
488                 getBusinessObjectService().save(contextValidActionBo);
489             } else {
490                 contextValidActionBo = (ContextValidActionBo) existing;
491             }
492         }
493         if(contextValidActionBo==null){
494             contextValidActionBo = registerDefaultServiceTypes(contextBo);
495         }
496         return contextValidActionBo;
497     }
498 
499     
500 
501 
502 
503 
504     private KrmsTypeBo  getActiontypeService(KrmsAction action){
505         Map<String, String> krmsTypePk = new HashMap<String, String>();
506         krmsTypePk.put("srvc_nm", action.getServiceName());
507         KrmsTypeBo krmsTypeBo = getBusinessObjectService().findByPrimaryKey(KrmsTypeBo.class, krmsTypePk);
508         return  krmsTypeBo;
509     }
510 
511     
512 
513 
514 
515 
516     private void persistMatchBo(AgendaBo agendaBo, KrmsProposition proposition) {
517         MatchBo matchBo = new MatchBo();
518         matchBo.setAgendaName(agendaBo.getName());
519         matchBo.setTermName(proposition.getTerm());
520         getBusinessObjectService().save(matchBo);
521     }
522 
523     
524 
525 
526 
527 
528 
529 
530     public List<String> persistKrmsFromFileContent(String fileContent) throws IOException, URISyntaxException {
531         Krms krms = getKrmsObjectGeneratorFromXML().buildKrmsFromFileContent(fileContent);
532         List<String> agendaNames = new ArrayList<String>();
533         for(OleAgenda oleAgenda :krms.getOleAgendaList()){
534             agendaNames.add(persist(oleAgenda));
535         }
536         return agendaNames;
537 
538     }
539 
540     
541 
542 
543 
544     public KrmsObjectGeneratorFromXML getKrmsObjectGeneratorFromXML() {
545         if(null==krmsObjectGeneratorFromXML){
546             krmsObjectGeneratorFromXML = new KrmsObjectGeneratorFromXML();            krmsObjectGeneratorFromXML = new KrmsObjectGeneratorFromXML();
547         }
548         return krmsObjectGeneratorFromXML;
549     }
550 
551     
552 
553 
554 
555     public void setKrmsObjectGeneratorFromXML(KrmsObjectGeneratorFromXML krmsObjectGeneratorFromXML) {
556         this.krmsObjectGeneratorFromXML = krmsObjectGeneratorFromXML;
557     }
558 
559     
560 
561 
562 
563 
564     public Boolean doesKrmsExist(String agendaName) {
565         HashMap<String, String> map = new HashMap<String, String>();
566         map.put("nm", agendaName);
567         List<AgendaBo> matching = (List<AgendaBo>) getBusinessObjectService().findMatching(AgendaBo.class, map);
568         return !matching.isEmpty();
569     }
570 
571     
572 
573 
574 
575     public void deleteAgenda(OleAgenda oleAgenda) {
576 
577         Map<String, String> contextPks = new HashMap<String, String>();
578         contextPks.put("nm", oleAgenda.getContextName());
579         contextPks.put("nmspc_cd", OLEConstants.OLE_NAMESPACE);
580         ContextBo context = getBusinessObjectService().findByPrimaryKey(ContextBo.class, contextPks);
581         String contextId = context.getId();
582 
583         Map<String, String> agendaPks = new HashMap<String, String>();
584         agendaPks.put("nm", oleAgenda.getName());
585         agendaPks.put("cntxt_id", contextId);
586         AgendaBo oldAgenda = getBusinessObjectService().findByPrimaryKey(AgendaBo.class, agendaPks);
587 
588         Map<String, String> itemPks = new HashMap<String, String>();
589         itemPks.put("agenda_id", oldAgenda.getId());
590         List<AgendaItemBo> items = (List<AgendaItemBo>) getBusinessObjectService().findMatching(AgendaItemBo.class, itemPks);
591         for(AgendaItemBo agendaItemBo : items){
592             getBusinessObjectService().delete(agendaItemBo);
593         }
594         getBusinessObjectService().delete(oldAgenda);
595 
596         List<AgendaBo> agendas = context.getAgendas();
597         AgendaBo removeAgenda = null;
598         for (AgendaBo agenda : agendas) {
599             if (agenda.getName().equalsIgnoreCase(oldAgenda.getName())) {
600                 removeAgenda = agenda;
601             }
602         }
603         agendas.remove(removeAgenda);
604         context.setAgendas(agendas);
605         getBusinessObjectService().save(context);
606 
607         deleteRegisteredRules(oleAgenda);
608 
609         HashMap matchingProfileAttr = new HashMap();
610         matchingProfileAttr.put("agenda_name", oldAgenda.getName());
611         List<ProfileAttributeBo> profileAttributeBos =
612                 (List<ProfileAttributeBo>) getBusinessObjectService().findMatching(ProfileAttributeBo.class, matchingProfileAttr);
613         getBusinessObjectService().delete(profileAttributeBos);
614 
615         HashMap matchingProfileFacts = new HashMap();
616         matchingProfileFacts.put("agenda_name", oldAgenda.getName());
617         List<MatchBo> matchBos =
618                 (List<MatchBo>) getBusinessObjectService().findMatching(MatchBo.class, matchingProfileFacts);
619         getBusinessObjectService().delete(matchBos);
620     }
621 
622     
623 
624 
625 
626     private void deleteRegisteredRules(OleAgenda oleAgenda) {
627         Map map = new HashMap();
628         List<KrmsRule> rules = oleAgenda.getRules();
629         for (Iterator<KrmsRule> iterator = rules.iterator(); iterator.hasNext(); ) {
630             KrmsRule krmsRule = iterator.next();
631             if(krmsRule.getProposition()!=null){
632                 String term = krmsRule.getProposition().getTerm();
633                 deleteTerm(term) ;
634             }
635             if(krmsRule.getCompoundProposition()!=null){
636                 deleteCompoundProposition(krmsRule.getCompoundProposition());
637             }
638             map.put("nm", krmsRule.getName());
639             List<RuleBo> matching = (List<RuleBo>) getBusinessObjectService().findMatching(RuleBo.class, map);
640             getBusinessObjectService().delete(matching);
641         }
642     }
643 
644     
645 
646 
647 
648     private void deleteCompoundProposition(OleProposition oleProposition){
649         for(OleProposition oleProposition1 : oleProposition.getOlePropositions()!=null?oleProposition.getOlePropositions():new ArrayList<OleProposition>()){
650             deleteCompoundProposition(oleProposition1);
651         }
652         for(KrmsProposition krmsProposition : oleProposition.getPropositions()!=null?oleProposition.getPropositions():new ArrayList<KrmsProposition>()){
653             String term = krmsProposition.getTerm();
654             deleteTerm(term) ;
655         }
656     }
657 
658     
659 
660 
661 
662     private void deleteTerm(String term) {
663         Map map = new HashMap();
664         map.put("desc_txt", term);
665         List<TermBo> termsToBeDeleted = (List<TermBo>) getBusinessObjectService().findMatching(TermBo.class, map);
666         if (!termsToBeDeleted.isEmpty()) {
667             getBusinessObjectService().delete(termsToBeDeleted);
668         }
669     }
670 
671     
672 
673 
674 
675 
676     public ContextValidActionBo registerDefaultServiceTypes(ContextBo contextBo) {
677         return profileBuilder.registerDefaultServiceTypes(contextBo);
678     }
679 
680     
681 
682 
683 
684 
685 
686 
687 
688 
689 
690     public ActionBo addActionToRule(String namespace, String actionName, String description, String actionTypeId, RuleBo ruleBo, Integer sequenceNumber) {
691         return profileBuilder.addActionToRule(namespace,actionName,description,actionTypeId,ruleBo,sequenceNumber);
692     }
693 
694     
695 
696 
697 
698 
699 
700     public AgendaItemBo addDummyRuleForFalseAction(RuleBo ruleBo, RuleBo falseActionRuleBo) {
701         return profileBuilder.addDummyRuleForFalseAction(ruleBo,falseActionRuleBo);
702     }
703 
704     
705 
706 
707 
708     private void persistProfileAttributes(OleAgenda oleAgenda) {
709         List<ProfileAttributeBo> profileAttributes = oleAgenda.getProfileAttributes();
710         for (Iterator<ProfileAttributeBo> iterator = profileAttributes.iterator(); iterator.hasNext(); ) {
711             ProfileAttributeBo profileAttributeBo = iterator.next();
712             profileAttributeBo.setAgendaName(oleAgenda.getName());
713         }
714         getBusinessObjectService().save(profileAttributes);
715     }
716 
717     
718 
719 
720 
721 
722 
723     private PropositionBo createCompoundProposition(List<KrmsProposition> propositions,String opCode){
724         List<PropositionBo> propositionBos = new ArrayList<PropositionBo>();
725         int seqNum = 0;
726         for(KrmsProposition proposition : propositions){
727             PropositionBo propositionBo = createSimpleProposition(proposition,seqNum);
728             if(opCode==null){
729                 return propositionBo;
730             }
731             seqNum++;
732             propositionBos.add(propositionBo);
733         }
734         PropositionBo propositionBo =  createCompoundProposition(category.getId(),"compound","C",ruleBo,opCode);
735         propositionBo.setCompoundComponents(propositionBos);
736         return propositionBo;
737     }
738 
739     
740 
741 
742 
743 
744 
745     private PropositionBo createSimpleProposition(KrmsProposition proposition,int seqNum){
746         TermSpecificationBo termSpecification =
747                 createTermSpecification(OLEConstants.OLE_NAMESPACE, proposition.getTerm(), proposition.getType(), Arrays.asList(category), Arrays.asList(context));
748 
749         TermBo termBo = createTerm(proposition.getTerm(), termSpecification);
750 
751 
752         PropositionBo propositionBo = createProposition(category.getId(), proposition.getTerm() + " check", "S", ruleBo,seqNum);
753 
754         if(proposition.getFunction()!=null && proposition.getFunction().equalsIgnoreCase("yes")){
755 
756             FunctionBo function = createFunction(OLEConstants.OLE_NAMESPACE, proposition.getTerm(), "java.lang.Boolean", Arrays.asList(category),proposition.getType());
757 
758             addTermToPropositionParameter(termBo.getId(), propositionBo);
759 
760             addCustomFunctionToPropositionParameter(function.getId(), propositionBo);
761         }   else{
762 
763             addTermToPropositionParameter(termBo.getId(), propositionBo);
764 
765             addConstantToPropositionParameter(proposition.getConstant(),propositionBo);
766 
767             addOperatorToPropositionParameter(proposition.getOperator(),propositionBo);
768         }
769         persistMatchBo(agendaBo, proposition);
770         return propositionBo;
771     }
772 
773     
774 
775 
776 
777     public CategoryBo getCategory() {
778         return category;
779     }
780 
781     
782 
783 
784 
785     public void setCategory(CategoryBo category) {
786         this.category = category;
787     }
788 
789     
790 
791 
792 
793     public ContextBo getContext() {
794         return context;
795     }
796 
797     
798 
799 
800 
801     public void setContext(ContextBo context) {
802         this.context = context;
803     }
804 
805     
806 
807 
808 
809     public AgendaBo getAgendaBo() {
810         return agendaBo;
811     }
812 
813     
814 
815 
816 
817     public void setAgendaBo(AgendaBo agendaBo) {
818         this.agendaBo = agendaBo;
819     }
820 
821     
822 
823 
824 
825     public RuleBo getRuleBo() {
826         return ruleBo;
827     }
828 
829     
830 
831 
832 
833     public void setRuleBo(RuleBo ruleBo) {
834         this.ruleBo = ruleBo;
835     }
836 }