1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.workflow.krms;
17
18
19 import org.kuali.kpme.core.KPMENamespace;
20 import org.kuali.kpme.core.api.assignment.Assignable;
21 import org.kuali.kpme.core.krms.KPMERulesEngineExecuter;
22 import org.kuali.kpme.core.krms.KpmeKrmsFactBuilderService;
23 import org.kuali.kpme.core.service.HrServiceLocator;
24 import org.kuali.kpme.tklm.common.krms.TklmKrmsConstants;
25 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
26 import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
27 import org.kuali.rice.kew.api.exception.WorkflowException;
28 import org.kuali.rice.kew.engine.RouteContext;
29 import org.kuali.rice.krad.document.Document;
30 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
31 import org.kuali.rice.krad.service.KRADServiceLocator;
32 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
33 import org.kuali.rice.krms.api.engine.Engine;
34 import org.kuali.rice.krms.api.engine.EngineResults;
35 import org.kuali.rice.krms.api.engine.Facts;
36 import org.kuali.rice.krms.api.engine.SelectionCriteria;
37
38 import java.util.HashMap;
39 import java.util.Map;
40
41 public class LeaveMaintDocRulesEngineExecutor extends KPMERulesEngineExecuter {
42
43
44 @Override
45 protected EngineResults performExecute(RouteContext routeContext, Engine engine) {
46 Map<String, String> contextQualifiers = new HashMap<String, String>();
47 contextQualifiers.put("namespaceCode", KPMENamespace.KPME_LM.getNamespaceCode());
48 contextQualifiers.put("name", TklmKrmsConstants.Context.LM_CONTEXT_NAME);
49
50
51 String docContent = routeContext.getDocument().getDocContent();
52
53 SelectionCriteria selectionCriteria = SelectionCriteria.createCriteria(null, contextQualifiers,
54 new HashMap<String, String>());
55
56
57 String documentId = routeContext.getDocument().getDocumentId();
58 Object dataObject = null;
59 MaintenanceDocument document = null;
60 try {
61 document = (MaintenanceDocument) KRADServiceLocatorWeb.getDocumentService().getByDocumentHeaderId(documentId);
62 if (document.getNewMaintainableObject().getDataObject() != null
63 && document.getNewMaintainableObject().getDataObject() instanceof Assignable) {
64 dataObject = document.getNewMaintainableObject().getDataObject();
65 }
66 } catch (WorkflowException e) {
67 e.printStackTrace();
68 }
69
70 KpmeKrmsFactBuilderService fbService = HrServiceLocator.getService("lmFactBuilderService");
71 Facts.Builder factsBuilder = Facts.Builder.create();
72
73 fbService.addFacts(factsBuilder, dataObject, TklmKrmsConstants.Context.LM_CONTEXT_NAME, KPMENamespace.KPME_LM.getNamespaceCode());
74 EngineResults results = engine.execute(selectionCriteria, factsBuilder.build(), null);
75 return results;
76 }
77 }