View Javadoc
1   /**
2    * Copyright 2004-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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          // extract facts from routeContext
47          String docContent = routeContext.getDocument().getDocContent();
48  
49          SelectionCriteria selectionCriteria = SelectionCriteria.createCriteria(null, contextQualifiers,
50                  new HashMap<String, String>());
51  
52          //Get leave request document to create facts
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          //factsBuilder.addFact()
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  }