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.time.krms;
17  
18  import org.kuali.kpme.core.KPMENamespace;
19  import org.kuali.kpme.core.krms.KPMERulesEngineExecuter;
20  import org.kuali.kpme.core.krms.KpmeKrmsFactBuilderService;
21  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
22  import org.kuali.rice.kew.engine.RouteContext;
23  import org.kuali.rice.krms.api.engine.Engine;
24  import org.kuali.rice.krms.api.engine.EngineResults;
25  import org.kuali.rice.krms.api.engine.Facts;
26  import org.kuali.rice.krms.api.engine.SelectionCriteria;
27  
28  import java.util.Collections;
29  import java.util.HashMap;
30  import java.util.Map;
31  
32  
33  public class TkRulesEngineExecutor extends KPMERulesEngineExecuter {
34      private final static String TK_TIMESHEET_CONTEXT = "KPME-TK-Context";
35  
36      @Override
37      protected EngineResults performExecute(RouteContext routeContext, Engine engine) {
38          Map<String, String> contextQualifiers = new HashMap<String, String>();
39          contextQualifiers.put("namespaceCode", KPMENamespace.KPME_TK.getNamespaceCode());
40          contextQualifiers.put("name", TK_TIMESHEET_CONTEXT);
41  
42          // extract facts from routeContext
43          String docContent = routeContext.getDocument().getDocContent();
44          String unitNumber = getElementValue(docContent, "//document/coiDisclosureList[1]/org.kuali.kra.coi.CoiDisclosure[1]/disclosurePersons[1]/org.kuali.kra.coi.disclosure.DisclosurePerson[1]/disclosurePersonUnits[1]/org.kuali.kra.coi.disclosure.DisclosurePersonUnit[1]/unitNumber[1]");
45  
46          SelectionCriteria selectionCriteria = SelectionCriteria.createCriteria(null, contextQualifiers,
47                  Collections.singletonMap("Unit Number", unitNumber));
48  
49          //KpmeKrmsFactBuilderService fbService = HrServiceLocator.getService("tkTimesheetFactBuilderService");
50          Facts.Builder factsBuilder = Facts.Builder.create();
51          //fbService.addFacts(factsBuilder, docContent);
52          EngineResults results = engine.execute(selectionCriteria, factsBuilder.build(), null);
53          return results;
54      }
55  }