1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }