1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.roles;
17
18 import java.util.ArrayList;
19 import java.util.HashSet;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Set;
24
25 import org.kuali.hr.job.Job;
26 import org.kuali.hr.time.service.base.TkServiceLocator;
27 import org.kuali.hr.time.util.TKUtils;
28 import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
29 import org.kuali.rice.krad.bo.BusinessObject;
30
31
32 public class TkRoleGroupInquirableImpl extends KualiInquirableImpl {
33
34 @Override
35 public BusinessObject getBusinessObject(Map fieldValues) {
36 TkRoleGroup tkRoleGroup = (TkRoleGroup) super.getBusinessObject(fieldValues);
37
38 List<Job> jobs = TkServiceLocator.getJobService().getJobs(tkRoleGroup.getPrincipalId(), TKUtils.getCurrentDate());
39 List<TkRole> positionRoles = new ArrayList<TkRole>();
40 List<TkRole> inactivePositionRoles = new ArrayList<TkRole>();
41 Set<String> positionNumbers = new HashSet<String>();
42 for(Job job : jobs){
43 positionNumbers.add(job.getPositionNumber());
44 }
45 for(String pNo : positionNumbers){
46 TkRole positionRole = TkServiceLocator.getTkRoleService().getRolesByPosition(pNo);
47 if(positionRole != null)
48 positionRoles.add(positionRole);
49 TkRole inactivePositionRole = TkServiceLocator.getTkRoleService().getInactiveRolesByPosition(pNo);
50 if(inactivePositionRole != null)
51 inactivePositionRoles.add(inactivePositionRole);
52 }
53 tkRoleGroup.setInactivePositionRoles(inactivePositionRoles);
54 tkRoleGroup.setPositionRoles(positionRoles);
55
56 List<TkRole> tkRoles = TkServiceLocator.getTkRoleService().getRoles(tkRoleGroup.getPrincipalId(), TKUtils.getCurrentDate());
57 List<TkRole> tkInActiveRoles = TkServiceLocator.getTkRoleService().getInactiveRoles(tkRoleGroup.getPrincipalId(), TKUtils.getCurrentDate());
58 Iterator<TkRole> itr = tkRoles.iterator();
59
60 while (itr.hasNext()) {
61 TkRole tkRole = (TkRole) itr.next();
62 if(tkRoleGroup.getPositionRoles()!=null && tkRoleGroup.getPositionRoles().contains(tkRole)){
63 itr.remove();
64 }
65 }
66 itr = tkInActiveRoles.iterator();
67 while (itr.hasNext()) {
68 TkRole tkRole = (TkRole) itr.next();
69 if(tkRoleGroup.getPositionRoles()!=null && tkRoleGroup.getPositionRoles().contains(tkRole)){
70 itr.remove();
71 }
72 }
73 tkRoleGroup.setRoles(tkRoles);
74 tkRoleGroup.setInactiveRoles(tkInActiveRoles);
75
76 return tkRoleGroup;
77 }
78 }