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.Assignment;
21
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Set;
25
26
27 public class KpmeJavaFunctionTermService extends KpmeKrmsJavaFunctionTermServiceBase {
28
29 public Boolean containsDept(Assignable assignable, String department) {
30
31 return getDepartmentsFromAssignments(assignable).contains(department);
32 }
33
34 public Boolean containsWorkArea(Assignable assignable, Long workArea) {
35 return getWorkAreasFromAssignments(assignable).contains(workArea);
36 }
37
38 public Boolean containsJobNumber(Assignable assignable, Long jobNumber) {
39 return getJobNumbersFromAssignments(assignable).contains(jobNumber);
40 }
41
42 public Boolean containsTask(Assignable assignable, Long task) {
43 return getTasksFromAssignments(assignable).contains(task);
44 }
45
46 private Set<String> getDepartmentsFromAssignments(Assignable assignable) {
47 Set<String> depts = new HashSet<String>();
48 List<Assignment> assignments = assignable.getAssignments();
49 if (CollectionUtils.isNotEmpty(assignments)) {
50 for (Assignment contract : assignments) {
51 depts.add(contract.getDept());
52 }
53 }
54 return depts;
55 }
56
57 private Set<Long> getWorkAreasFromAssignments(Assignable assignable) {
58 Set<Long> was = new HashSet<Long>();
59 List<Assignment> assignments = assignable.getAssignments();
60 if (CollectionUtils.isNotEmpty(assignments)) {
61 for (Assignment contract : assignments) {
62 was.add(contract.getWorkArea());
63 }
64 }
65 return was;
66 }
67
68 private Set<Long> getTasksFromAssignments(Assignable assignable) {
69 Set<Long> tasks = new HashSet<Long>();
70 List<Assignment> assignments = assignable.getAssignments();
71 if (CollectionUtils.isNotEmpty(assignments)) {
72 for (Assignment contract : assignments) {
73 tasks.add(contract.getTask());
74 }
75 }
76 return tasks;
77 }
78
79 private Set<Long> getJobNumbersFromAssignments(Assignable assignable) {
80 Set<Long> jobs = new HashSet<Long>();
81 List<Assignment> assignments = assignable.getAssignments();
82 if (CollectionUtils.isNotEmpty(assignments)) {
83 for (Assignment contract : assignments) {
84 jobs.add(contract.getJobNumber());
85 }
86 }
87 return jobs;
88 }
89 }