1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.request.krms;
17
18 import org.kuali.kpme.core.api.namespace.KPMENamespace;
19 import org.kuali.kpme.core.krms.KPMERulesEngineExecuter;
20 import org.kuali.kpme.core.krms.KpmeKrmsFactBuilderService;
21 import org.kuali.kpme.core.service.HrServiceLocator;
22 import org.kuali.kpme.tklm.api.common.krms.TklmKrmsConstants;
23 import org.kuali.kpme.tklm.api.leave.block.LeaveBlock;
24 import org.kuali.kpme.tklm.leave.block.LeaveBlockBo;
25 import org.kuali.kpme.tklm.leave.request.service.LeaveRequestDocumentService;
26 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
27 import org.kuali.kpme.tklm.leave.workflow.LeaveRequestDocument;
28 import org.kuali.rice.kew.engine.RouteContext;
29 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
30 import org.kuali.rice.krms.api.engine.Engine;
31 import org.kuali.rice.krms.api.engine.EngineResults;
32 import org.kuali.rice.krms.api.engine.Facts;
33 import org.kuali.rice.krms.api.engine.SelectionCriteria;
34
35 import java.util.HashMap;
36 import java.util.Map;
37
38
39 public class LeaveRequestRulesEngineExecutor extends KPMERulesEngineExecuter {
40 @Override
41 protected EngineResults performExecute(RouteContext routeContext, Engine engine) {
42 Map<String, String> contextQualifiers = new HashMap<String, String>();
43 contextQualifiers.put("namespaceCode", KPMENamespace.KPME_LM.getNamespaceCode());
44 contextQualifiers.put("name", TklmKrmsConstants.Context.LEAVE_REQUEST_CONTEXT_NAME);
45
46
47 String docContent = routeContext.getDocument().getDocContent();
48
49 SelectionCriteria selectionCriteria = SelectionCriteria.createCriteria(null, contextQualifiers,
50 new HashMap<String, String>());
51
52
53 String documentId = routeContext.getDocument().getDocumentId();
54 LeaveBlock leaveBlock = null;
55 MaintenanceDocument document = null;
56 LeaveRequestDocumentService lrds = LmServiceLocator.getLeaveRequestDocumentService();
57 LeaveRequestDocument request = lrds.getLeaveRequestDocument(documentId);
58 if (request != null) {
59 leaveBlock = request.getLeaveBlock();
60 }
61
62 KpmeKrmsFactBuilderService fbService = HrServiceLocator.getService("lmFactBuilderService");
63 Facts.Builder factsBuilder = Facts.Builder.create();
64
65 fbService.addFacts(factsBuilder, leaveBlock, TklmKrmsConstants.Context.LM_CONTEXT_NAME, KPMENamespace.KPME_LM.getNamespaceCode());
66 EngineResults results = engine.execute(selectionCriteria, factsBuilder.build(), null);
67 return results;
68 }
69 }