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.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.common.krms.TklmKrmsConstants;
24 import org.kuali.kpme.tklm.leave.block.LeaveBlock;
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.api.exception.WorkflowException;
29 import org.kuali.rice.kew.engine.RouteContext;
30 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
31 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
32 import org.kuali.rice.krms.api.engine.Engine;
33 import org.kuali.rice.krms.api.engine.EngineResults;
34 import org.kuali.rice.krms.api.engine.Facts;
35 import org.kuali.rice.krms.api.engine.SelectionCriteria;
36
37 import java.util.HashMap;
38 import java.util.Map;
39
40
41 public class LeaveRequestRulesEngineExecutor extends KPMERulesEngineExecuter {
42 @Override
43 protected EngineResults performExecute(RouteContext routeContext, Engine engine) {
44 Map<String, String> contextQualifiers = new HashMap<String, String>();
45 contextQualifiers.put("namespaceCode", KPMENamespace.KPME_LM.getNamespaceCode());
46 contextQualifiers.put("name", TklmKrmsConstants.Context.LEAVE_REQUEST_CONTEXT_NAME);
47
48
49 String docContent = routeContext.getDocument().getDocContent();
50
51 SelectionCriteria selectionCriteria = SelectionCriteria.createCriteria(null, contextQualifiers,
52 new HashMap<String, String>());
53
54
55 String documentId = routeContext.getDocument().getDocumentId();
56 LeaveBlock leaveBlock = null;
57 MaintenanceDocument document = null;
58 LeaveRequestDocumentService lrds = LmServiceLocator.getLeaveRequestDocumentService();
59 LeaveRequestDocument request = lrds.getLeaveRequestDocument(documentId);
60 if (request != null) {
61 leaveBlock = request.getLeaveBlock();
62 }
63
64 KpmeKrmsFactBuilderService fbService = HrServiceLocator.getService("lmFactBuilderService");
65 Facts.Builder factsBuilder = Facts.Builder.create();
66
67 fbService.addFacts(factsBuilder, leaveBlock, TklmKrmsConstants.Context.LM_CONTEXT_NAME, KPMENamespace.KPME_LM.getNamespaceCode());
68 EngineResults results = engine.execute(selectionCriteria, factsBuilder.build(), null);
69 return results;
70 }
71 }