001/** 002 * Copyright 2004-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.kpme.tklm.leave.request.krms; 017 018import org.kuali.kpme.core.KPMENamespace; 019import org.kuali.kpme.core.api.assignment.Assignable; 020import org.kuali.kpme.core.krms.KPMERulesEngineExecuter; 021import org.kuali.kpme.core.krms.KpmeKrmsFactBuilderService; 022import org.kuali.kpme.core.service.HrServiceLocator; 023import org.kuali.kpme.tklm.common.krms.TklmKrmsConstants; 024import org.kuali.kpme.tklm.leave.block.LeaveBlock; 025import org.kuali.kpme.tklm.leave.request.service.LeaveRequestDocumentService; 026import org.kuali.kpme.tklm.leave.service.LmServiceLocator; 027import org.kuali.kpme.tklm.leave.workflow.LeaveRequestDocument; 028import org.kuali.rice.kew.api.exception.WorkflowException; 029import org.kuali.rice.kew.engine.RouteContext; 030import org.kuali.rice.krad.maintenance.MaintenanceDocument; 031import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 032import org.kuali.rice.krms.api.engine.Engine; 033import org.kuali.rice.krms.api.engine.EngineResults; 034import org.kuali.rice.krms.api.engine.Facts; 035import org.kuali.rice.krms.api.engine.SelectionCriteria; 036 037import java.util.HashMap; 038import java.util.Map; 039 040 041public class LeaveRequestRulesEngineExecutor extends KPMERulesEngineExecuter { 042 @Override 043 protected EngineResults performExecute(RouteContext routeContext, Engine engine) { 044 Map<String, String> contextQualifiers = new HashMap<String, String>(); 045 contextQualifiers.put("namespaceCode", KPMENamespace.KPME_LM.getNamespaceCode()); 046 contextQualifiers.put("name", TklmKrmsConstants.Context.LEAVE_REQUEST_CONTEXT_NAME); 047 048 // extract facts from routeContext 049 String docContent = routeContext.getDocument().getDocContent(); 050 051 SelectionCriteria selectionCriteria = SelectionCriteria.createCriteria(null, contextQualifiers, 052 new HashMap<String, String>()); 053 054 //Get leave request document to create facts 055 String documentId = routeContext.getDocument().getDocumentId(); 056 LeaveBlock leaveBlock = null; 057 MaintenanceDocument document = null; 058 LeaveRequestDocumentService lrds = LmServiceLocator.getLeaveRequestDocumentService(); 059 LeaveRequestDocument request = lrds.getLeaveRequestDocument(documentId); 060 if (request != null) { 061 leaveBlock = request.getLeaveBlock(); 062 } 063 064 KpmeKrmsFactBuilderService fbService = HrServiceLocator.getService("lmFactBuilderService"); 065 Facts.Builder factsBuilder = Facts.Builder.create(); 066 //factsBuilder.addFact() 067 fbService.addFacts(factsBuilder, leaveBlock, TklmKrmsConstants.Context.LM_CONTEXT_NAME, KPMENamespace.KPME_LM.getNamespaceCode()); 068 EngineResults results = engine.execute(selectionCriteria, factsBuilder.build(), null); 069 return results; 070 } 071}