View Javadoc
1   /**
2    * Copyright 2004-2015 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.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 department) {
32  
33          return getDepartmentsFromAssignments(assignable).contains(department);
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  }