001 /**
002 * Copyright 2004-2013 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.apache.commons.collections.CollectionUtils;
019 import org.kuali.hr.time.department.Department;
020 import org.kuali.hr.time.department.dao.DepartmentDao;
021 import org.kuali.hr.time.roles.TkRole;
022 import org.kuali.hr.time.service.base.TkServiceLocator;
023 import org.kuali.hr.time.util.TkConstants;
024
025 import java.sql.Date;
026 import java.util.List;
027
028 public class DepartmentServiceImpl implements DepartmentService {
029
030 private DepartmentDao departmentDao;
031
032 @Override
033 public List<Department> getDepartments(String chart, Date asOfDate) {
034 List<Department> ds = departmentDao.getDepartments(chart, asOfDate);
035
036 for (Department d : ds) {
037 populateDepartmentRoles(d);
038 }
039
040 return ds;
041 }
042
043 @Override
044 public Department getDepartment(String department, Date asOfDate) {
045 Department d = departmentDao.getDepartment(department, asOfDate);
046 populateDepartmentRoles(d);
047
048 return d;
049 }
050
051 public void setDepartmentDao(DepartmentDao departmentDao) {
052 this.departmentDao = departmentDao;
053 }
054
055 @Override
056 public void populateDepartmentRoles(Department department) {
057 if (department != null
058 && CollectionUtils.isEmpty(department.getRoles())
059 && CollectionUtils.isEmpty(department.getInactiveRoles())) {
060 department.getRoles().addAll(TkServiceLocator.getTkRoleService().getDepartmentRoles(department.getDept()));
061 department.getInactiveRoles().addAll(TkServiceLocator.getTkRoleService().getDepartmentInactiveRoles(department.getDept()));
062 }
063 }
064
065 @Override
066 public Department getDepartment(String hrDeptId) {
067 return departmentDao.getDepartment(hrDeptId);
068 }
069
070 @Override
071 public List<Department> getDepartmentByLocation(String location) {
072 return departmentDao.getDepartmentByLocation(location);
073 }
074
075 @Override
076 public int getDepartmentCount(String department) {
077 return departmentDao.getDepartmentCount(department);
078 }
079
080 @Override
081 public List<Department> getDepartments(String department, String location, String descr, String active, String showHistory) {
082 return departmentDao.getDepartments(department, location, descr, active, showHistory);
083 }
084 }