View Javadoc

1   /**
2    * Copyright 2004-2012 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.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  // chen, KPME-938, implement the view link on lookup page
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  		// remove position roles from the active/inactive roles lists
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  }