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.department.service;
17  
18  import org.kuali.hr.time.department.Department;
19  import org.kuali.hr.time.department.dao.DepartmentDao;
20  import org.kuali.hr.time.roles.TkRole;
21  import org.kuali.hr.time.service.base.TkServiceLocator;
22  import org.kuali.hr.time.util.TkConstants;
23  
24  import java.sql.Date;
25  import java.util.List;
26  
27  public class DepartmentServiceImpl implements DepartmentService {
28  
29  	private DepartmentDao departmentDao;
30  
31      @Override
32      public List<Department> getDepartments(String chart, Date asOfDate) {
33          List<Department> ds = departmentDao.getDepartments(chart, asOfDate);
34  
35          for (Department d : ds) {
36              populateDepartmentRoles(d);
37          }
38  
39          return ds;
40      }
41  
42      @Override
43  	public Department getDepartment(String department, Date asOfDate) {
44          Department d = departmentDao.getDepartment(department, asOfDate);
45          populateDepartmentRoles(d);
46  
47  		return d;
48  	}
49  
50  	public void setDepartmentDao(DepartmentDao departmentDao) {
51  		this.departmentDao = departmentDao;
52  	}
53  
54      @Override
55      public void populateDepartmentRoles(Department department) {
56          if (department != null) {
57          	List<TkRole> deptAdminRoles = TkServiceLocator.getTkRoleService().getDepartmentRoles(
58                      department.getDept(),
59                      TkConstants.ROLE_TK_DEPT_ADMIN,
60                      department.getEffectiveDate()); 
61          	List<TkRole> deptViewOnlyRoles = TkServiceLocator.getTkRoleService().getDepartmentRoles(department.getDept(),
62                      TkConstants.ROLE_TK_DEPT_VO,
63                      department.getEffectiveDate());
64          	List<TkRole> deptAdminInactiveRoles = TkServiceLocator.getTkRoleService().getDepartmentInactiveRoles(
65                      department.getDept(),
66                      TkConstants.ROLE_TK_DEPT_ADMIN,
67                      department.getEffectiveDate()); 
68          	List<TkRole> deptViewOnlyInactiveRoles = TkServiceLocator.getTkRoleService().getDepartmentInactiveRoles(department.getDept(),
69                      TkConstants.ROLE_TK_DEPT_VO,
70                      department.getEffectiveDate());
71          	
72          	department.getRoles().addAll(deptAdminRoles);
73          	department.getRoles().addAll(deptViewOnlyRoles);
74          	department.getInactiveRoles().addAll(deptAdminInactiveRoles);
75          	department.getInactiveRoles().addAll(deptViewOnlyInactiveRoles);
76          	
77          	//kpme1411, chen, 05/08/12
78          	List<TkRole> leaveDeptAdminRoles = TkServiceLocator.getTkRoleService().getDepartmentRoles(
79                      department.getDept(),
80                      TkConstants.ROLE_LV_DEPT_ADMIN,
81                      department.getEffectiveDate()); 
82          	List<TkRole> leaveDeptViewOnlyRoles = TkServiceLocator.getTkRoleService().getDepartmentRoles(department.getDept(),
83                      TkConstants.ROLE_LV_DEPT_VO,
84                      department.getEffectiveDate());
85          	List<TkRole> leaveDeptAdminInactiveRoles = TkServiceLocator.getTkRoleService().getDepartmentInactiveRoles(
86                      department.getDept(),
87                      TkConstants.ROLE_LV_DEPT_ADMIN,
88                      department.getEffectiveDate()); 
89          	List<TkRole> leaveDeptViewOnlyInactiveRoles = TkServiceLocator.getTkRoleService().getDepartmentInactiveRoles(department.getDept(),
90                      TkConstants.ROLE_LV_DEPT_VO,
91                      department.getEffectiveDate());
92          	
93          	department.getRoles().addAll(leaveDeptAdminRoles);
94          	department.getRoles().addAll(leaveDeptViewOnlyRoles);
95          	department.getInactiveRoles().addAll(leaveDeptAdminInactiveRoles);
96          	department.getInactiveRoles().addAll(leaveDeptViewOnlyInactiveRoles);
97          }
98      }
99  
100 	@Override
101 	public Department getDepartment(String hrDeptId) {
102 		return departmentDao.getDepartment(hrDeptId);
103 	}
104 	
105 	@Override
106 	public List<Department> getDepartmentByLocation(String location) {
107 		return departmentDao.getDepartmentByLocation(location);
108 	}
109 	
110 	@Override
111 	public int getDepartmentCount(String department) {
112 		return departmentDao.getDepartmentCount(department);
113 	}
114 }