1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.krms;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.kuali.kpme.core.api.assignment.Assignable;
20 import org.kuali.kpme.core.api.assignment.AssignmentContract;
21 import org.kuali.kpme.core.assignment.Assignment;
22 import org.kuali.kpme.core.krms.KpmeKrmsJavaFunctionTermServiceBase;
23
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Set;
27
28
29 public class KpmeJavaFunctionTermService extends KpmeKrmsJavaFunctionTermServiceBase {
30
31 public Boolean containsDept(Assignable assignable, String deptartment) {
32
33 return getDepartmentsFromAssignments(assignable).contains(deptartment);
34 }
35
36 public Boolean containsWorkArea(Assignable assignable, Long workArea) {
37 return getWorkAreasFromAssignments(assignable).contains(workArea);
38 }
39
40 public Boolean containsJobNumber(Assignable assignable, Long jobNumber) {
41 return getJobNumbersFromAssignments(assignable).contains(jobNumber);
42 }
43
44 public Boolean containsTask(Assignable assignable, Long task) {
45 return getTasksFromAssignments(assignable).contains(task);
46 }
47
48 private Set<String> getDepartmentsFromAssignments(Assignable assignable) {
49 Set<String> depts = new HashSet<String>();
50 List<? extends AssignmentContract> assignments = assignable.getAssignments();
51 if (CollectionUtils.isNotEmpty(assignments)) {
52 for (AssignmentContract contract : assignments) {
53 depts.add(contract.getDept());
54 }
55 }
56 return depts;
57 }
58
59 private Set<Long> getWorkAreasFromAssignments(Assignable assignable) {
60 Set<Long> was = new HashSet<Long>();
61 List<? extends AssignmentContract> assignments = assignable.getAssignments();
62 if (CollectionUtils.isNotEmpty(assignments)) {
63 for (AssignmentContract contract : assignments) {
64 was.add(contract.getWorkArea());
65 }
66 }
67 return was;
68 }
69
70 private Set<Long> getTasksFromAssignments(Assignable assignable) {
71 Set<Long> tasks = new HashSet<Long>();
72 List<? extends AssignmentContract> assignments = assignable.getAssignments();
73 if (CollectionUtils.isNotEmpty(assignments)) {
74 for (AssignmentContract contract : assignments) {
75 tasks.add(contract.getTask());
76 }
77 }
78 return tasks;
79 }
80
81 private Set<Long> getJobNumbersFromAssignments(Assignable assignable) {
82 Set<Long> jobs = new HashSet<Long>();
83 List<? extends AssignmentContract> assignments = assignable.getAssignments();
84 if (CollectionUtils.isNotEmpty(assignments)) {
85 for (AssignmentContract contract : assignments) {
86 jobs.add(contract.getJobNumber());
87 }
88 }
89 return jobs;
90 }
91 }