View Javadoc

1   /**
2    * Copyright 2004-2013 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.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          // extract facts from routeContext
49          String docContent = routeContext.getDocument().getDocContent();
50  
51          SelectionCriteria selectionCriteria = SelectionCriteria.createCriteria(null, contextQualifiers,
52                  new HashMap<String, String>());
53  
54          //Get leave request document to create facts
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          //factsBuilder.addFact()
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  }