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.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  }