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.workflow.krms;
17  
18  
19  import org.apache.commons.collections.CollectionUtils;
20  import org.kuali.kpme.core.api.assignment.Assignable;
21  import org.kuali.kpme.core.api.assignment.Assignment;
22  import org.kuali.kpme.core.api.department.Department;
23  import org.kuali.kpme.core.api.namespace.KPMENamespace;
24  import org.kuali.kpme.core.krms.KpmeKrmsFactBuilderServiceHelper;
25  import org.kuali.kpme.core.service.HrServiceLocator;
26  import org.kuali.kpme.tklm.api.common.krms.TklmKrmsConstants;
27  import org.kuali.rice.krms.api.engine.Facts;
28  import org.kuali.rice.krms.api.engine.Term;
29  
30  import java.util.HashSet;
31  import java.util.Set;
32  
33  public class LMFactBuilderServiceImpl extends KpmeKrmsFactBuilderServiceHelper {
34      @Override
35      public void addFacts(Facts.Builder factsBuilder, String docContent) {
36          //remove me?
37      }
38  
39      @Override
40      public void addFacts(Facts.Builder factsBuilder, Object factObject) {
41          addFacts(factsBuilder, factObject, KPMENamespace.KPME_LM.getNamespaceCode(), TklmKrmsConstants.Context.LM_CONTEXT_NAME);
42      }
43  
44      @Override
45      public void addFacts(Facts.Builder factsBuilder, Object factObject, String contextId, String namespace) {
46          addObjectMembersAsFacts(factsBuilder, factObject, contextId, namespace);
47          factsBuilder.addFact(new Term("payrollProcessorApproval"), Boolean.FALSE);
48          if (factObject != null
49                  && factObject instanceof Assignable) {
50              Assignable assignable = (Assignable)factObject;
51              factsBuilder.addFact(Assignable.ASSIGNABLE_TERM_NAME, assignable);
52              Set<String> workAreas = new HashSet<String>();
53              Set<String> depts = new HashSet<String>();
54  
55              for (Assignment a : assignable.getAssignments()) {
56                  workAreas.add(String.valueOf(a.getWorkArea()));
57                  depts.add(a.getDept());
58                  Department department = HrServiceLocator.getDepartmentService().getDepartment(a.getDept(), a.getGroupKeyCode(), a.getEffectiveLocalDate());
59                  if (department != null
60                          && department.isPayrollApproval()) {
61                      factsBuilder.addFact(new Term("payrollProcessorApproval"), Boolean.TRUE);
62                  }
63              }
64              if (CollectionUtils.isNotEmpty(depts)) {
65                  factsBuilder.addFact("department", depts);
66              }
67              if (CollectionUtils.isNotEmpty(workAreas)) {
68                  factsBuilder.addFact("workarea", workAreas);
69              }
70          }
71      }
72  }