001 /**
002 * Copyright 2004-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.department.service;
017
018 import org.kuali.hr.time.department.Department;
019 import org.kuali.hr.time.department.dao.DepartmentDao;
020 import org.kuali.hr.time.roles.TkRole;
021 import org.kuali.hr.time.service.base.TkServiceLocator;
022 import org.kuali.hr.time.util.TkConstants;
023
024 import java.sql.Date;
025 import java.util.List;
026
027 public class DepartmentServiceImpl implements DepartmentService {
028
029 private DepartmentDao departmentDao;
030
031 @Override
032 public List<Department> getDepartments(String chart, Date asOfDate) {
033 List<Department> ds = departmentDao.getDepartments(chart, asOfDate);
034
035 for (Department d : ds) {
036 populateDepartmentRoles(d);
037 }
038
039 return ds;
040 }
041
042 @Override
043 public Department getDepartment(String department, Date asOfDate) {
044 Department d = departmentDao.getDepartment(department, asOfDate);
045 populateDepartmentRoles(d);
046
047 return d;
048 }
049
050 public void setDepartmentDao(DepartmentDao departmentDao) {
051 this.departmentDao = departmentDao;
052 }
053
054 @Override
055 public void populateDepartmentRoles(Department department) {
056 if (department != null) {
057 List<TkRole> deptAdminRoles = TkServiceLocator.getTkRoleService().getDepartmentRoles(
058 department.getDept(),
059 TkConstants.ROLE_TK_DEPT_ADMIN,
060 department.getEffectiveDate());
061 List<TkRole> deptViewOnlyRoles = TkServiceLocator.getTkRoleService().getDepartmentRoles(department.getDept(),
062 TkConstants.ROLE_TK_DEPT_VO,
063 department.getEffectiveDate());
064 List<TkRole> deptAdminInactiveRoles = TkServiceLocator.getTkRoleService().getDepartmentInactiveRoles(
065 department.getDept(),
066 TkConstants.ROLE_TK_DEPT_ADMIN,
067 department.getEffectiveDate());
068 List<TkRole> deptViewOnlyInactiveRoles = TkServiceLocator.getTkRoleService().getDepartmentInactiveRoles(department.getDept(),
069 TkConstants.ROLE_TK_DEPT_VO,
070 department.getEffectiveDate());
071
072 department.getRoles().addAll(deptAdminRoles);
073 department.getRoles().addAll(deptViewOnlyRoles);
074 department.getInactiveRoles().addAll(deptAdminInactiveRoles);
075 department.getInactiveRoles().addAll(deptViewOnlyInactiveRoles);
076
077 //kpme1411, chen, 05/08/12
078 List<TkRole> leaveDeptAdminRoles = TkServiceLocator.getTkRoleService().getDepartmentRoles(
079 department.getDept(),
080 TkConstants.ROLE_LV_DEPT_ADMIN,
081 department.getEffectiveDate());
082 List<TkRole> leaveDeptViewOnlyRoles = TkServiceLocator.getTkRoleService().getDepartmentRoles(department.getDept(),
083 TkConstants.ROLE_LV_DEPT_VO,
084 department.getEffectiveDate());
085 List<TkRole> leaveDeptAdminInactiveRoles = TkServiceLocator.getTkRoleService().getDepartmentInactiveRoles(
086 department.getDept(),
087 TkConstants.ROLE_LV_DEPT_ADMIN,
088 department.getEffectiveDate());
089 List<TkRole> leaveDeptViewOnlyInactiveRoles = TkServiceLocator.getTkRoleService().getDepartmentInactiveRoles(department.getDept(),
090 TkConstants.ROLE_LV_DEPT_VO,
091 department.getEffectiveDate());
092
093 department.getRoles().addAll(leaveDeptAdminRoles);
094 department.getRoles().addAll(leaveDeptViewOnlyRoles);
095 department.getInactiveRoles().addAll(leaveDeptAdminInactiveRoles);
096 department.getInactiveRoles().addAll(leaveDeptViewOnlyInactiveRoles);
097 }
098 }
099
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 }