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.pm.workflow.krms;
17  
18  
19  import org.kuali.kpme.core.api.assignment.Assignable;
20  import org.kuali.kpme.core.api.namespace.KPMENamespace;
21  import org.kuali.kpme.core.krms.KPMERulesEngineExecuter;
22  import org.kuali.kpme.core.krms.KpmeKrmsFactBuilderService;
23  import org.kuali.kpme.core.service.HrServiceLocator;
24  import org.kuali.kpme.pm.api.common.krms.PmKrmsConstants;
25  import org.kuali.rice.kew.api.exception.WorkflowException;
26  import org.kuali.rice.kew.engine.RouteContext;
27  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
28  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
29  import org.kuali.rice.krms.api.engine.Engine;
30  import org.kuali.rice.krms.api.engine.EngineResults;
31  import org.kuali.rice.krms.api.engine.Facts;
32  import org.kuali.rice.krms.api.engine.SelectionCriteria;
33  
34  import java.util.HashMap;
35  import java.util.Map;
36  
37  public class PositionMaintDocRulesEngineExecutor extends KPMERulesEngineExecuter {
38  
39      //assumes document's dataobject being routed implements AssignedToAssignment
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_PM.getNamespaceCode());
44          contextQualifiers.put("name", PmKrmsConstants.Context.PM_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 position maintenance document to create facts
53          String documentId = routeContext.getDocument().getDocumentId();
54          Object document = null;
55          try {
56              document = (MaintenanceDocument) KRADServiceLocatorWeb.getDocumentService().getByDocumentHeaderId(documentId);
57          } catch (WorkflowException e) {
58              e.printStackTrace();
59          }
60  
61          KpmeKrmsFactBuilderService fbService = HrServiceLocator.getService("pmFactBuilderService");
62          Facts.Builder factsBuilder = Facts.Builder.create();
63          //factsBuilder.addFact()
64          fbService.addFacts(factsBuilder, document, PmKrmsConstants.Context.PM_CONTEXT_NAME, KPMENamespace.KPME_PM.getNamespaceCode());
65          EngineResults results = engine.execute(selectionCriteria, factsBuilder.build(), null);
66          return results;
67      }
68  }