View Javadoc
1   /**
2    * Copyright 2004-2014 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.calendar.rules;
17  
18  import org.kuali.kpme.core.api.namespace.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.api.common.krms.TklmKrmsConstants;
24  import org.kuali.kpme.tklm.leave.calendar.LeaveCalendarDocument;
25  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
26  import org.kuali.rice.kew.engine.RouteContext;
27  import org.kuali.rice.krms.api.engine.Engine;
28  import org.kuali.rice.krms.api.engine.EngineResults;
29  import org.kuali.rice.krms.api.engine.Facts;
30  import org.kuali.rice.krms.api.engine.SelectionCriteria;
31  
32  import java.util.HashMap;
33  import java.util.Map;
34  
35  
36  public class LeaveCalendarRulesEngineExecutor extends KPMERulesEngineExecuter {
37      @Override
38      protected EngineResults performExecute(RouteContext routeContext, Engine engine) {
39          Map<String, String> contextQualifiers = new HashMap<String, String>();
40          contextQualifiers.put("namespaceCode", KPMENamespace.KPME_LM.getNamespaceCode());
41          contextQualifiers.put("name", TklmKrmsConstants.Calendar.KPME_LEAVE_CALENDAR_CONTEXT_NAME);
42  
43          // extract facts from routeContext
44          String docContent = routeContext.getDocument().getDocContent();
45  
46          SelectionCriteria selectionCriteria = SelectionCriteria.createCriteria(null, contextQualifiers,
47                  new HashMap<String, String>());
48  
49          //Get timesheet document to create facts
50          LeaveCalendarDocument doc = LmServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(routeContext.getDocument().getDocumentId());
51          KpmeKrmsFactBuilderService fbService = HrServiceLocator.getService("calendarDocumentFactBuilderService");
52          Facts.Builder factsBuilder = Facts.Builder.create();
53          fbService.addFacts(factsBuilder, doc, TklmKrmsConstants.Calendar.KPME_LEAVE_CALENDAR_CONTEXT_NAME, KPMENamespace.KPME_LM.getNamespaceCode());
54          factsBuilder.addFact(Assignable.ASSIGNABLE_TERM_NAME, doc);
55          return engine.execute(selectionCriteria, factsBuilder.build(), null);
56      }
57  }