1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.calendar.rules;
17
18 import org.kuali.kpme.core.api.namespace.KPMENamespace;
19 import org.kuali.kpme.core.api.assignment.Assignable;
20 import org.kuali.kpme.core.krms.KPMERulesEngineExecuter;
21 import org.kuali.kpme.core.krms.KpmeKrmsFactBuilderService;
22 import org.kuali.kpme.core.service.HrServiceLocator;
23 import org.kuali.kpme.tklm.api.common.krms.TklmKrmsConstants;
24 import org.kuali.kpme.tklm.leave.calendar.LeaveCalendarDocument;
25 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
26 import org.kuali.rice.kew.engine.RouteContext;
27 import org.kuali.rice.krms.api.engine.Engine;
28 import org.kuali.rice.krms.api.engine.EngineResults;
29 import org.kuali.rice.krms.api.engine.Facts;
30 import org.kuali.rice.krms.api.engine.SelectionCriteria;
31
32 import java.util.HashMap;
33 import java.util.Map;
34
35
36 public class LeaveCalendarRulesEngineExecutor extends KPMERulesEngineExecuter {
37 @Override
38 protected EngineResults performExecute(RouteContext routeContext, Engine engine) {
39 Map<String, String> contextQualifiers = new HashMap<String, String>();
40 contextQualifiers.put("namespaceCode", KPMENamespace.KPME_LM.getNamespaceCode());
41 contextQualifiers.put("name", TklmKrmsConstants.Calendar.KPME_LEAVE_CALENDAR_CONTEXT_NAME);
42
43
44 String docContent = routeContext.getDocument().getDocContent();
45
46 SelectionCriteria selectionCriteria = SelectionCriteria.createCriteria(null, contextQualifiers,
47 new HashMap<String, String>());
48
49
50 LeaveCalendarDocument doc = LmServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(routeContext.getDocument().getDocumentId());
51 KpmeKrmsFactBuilderService fbService = HrServiceLocator.getService("calendarDocumentFactBuilderService");
52 Facts.Builder factsBuilder = Facts.Builder.create();
53 fbService.addFacts(factsBuilder, doc, TklmKrmsConstants.Calendar.KPME_LEAVE_CALENDAR_CONTEXT_NAME, KPMENamespace.KPME_LM.getNamespaceCode());
54 factsBuilder.addFact(Assignable.ASSIGNABLE_TERM_NAME, doc);
55 return engine.execute(selectionCriteria, factsBuilder.build(), null);
56 }
57 }