View Javadoc

1   /**
2    * Copyright 2004-2013 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.workarea.service;
17  
18  import java.sql.Date;
19  import java.util.List;
20  
21  import org.apache.commons.lang.ObjectUtils;
22  import org.kuali.hr.time.service.base.TkServiceLocator;
23  import org.kuali.hr.time.workarea.WorkArea;
24  import org.kuali.hr.time.workarea.dao.WorkAreaDao;
25  
26  public class WorkAreaServiceImpl implements WorkAreaService {
27  
28  	private WorkAreaDao workAreaDao;
29  
30      @Override
31      public List<WorkArea> getWorkAreas(String department, Date asOfDate) {
32          List<WorkArea> workAreas = workAreaDao.getWorkArea(department, asOfDate);
33  
34          for (WorkArea workArea : workAreas) {
35          	populateWorkAreaTasks(workArea);
36          	populateWorkAreaRoles(workArea);
37          }
38  
39          return workAreas;
40      }
41  
42      @Override
43  	public WorkArea getWorkArea(Long workArea, Date asOfDate) {
44          WorkArea workAreaObj = workAreaDao.getWorkArea(workArea, asOfDate);
45          populateWorkAreaTasks(workAreaObj);
46          populateWorkAreaRoles(workAreaObj);
47  		return workAreaObj;
48  	}
49  
50  	@Override
51  	public void saveOrUpdate(WorkArea workArea) {
52  		workAreaDao.saveOrUpdate(workArea);
53  	}
54  
55  	public WorkAreaDao getWorkAreaDao() {
56  		return workAreaDao;
57  	}
58  
59  	public void setWorkAreaDao(WorkAreaDao workAreaDao) {
60  		this.workAreaDao = workAreaDao;
61  	}
62  	
63  	@Override
64  	public void populateWorkAreaTasks(WorkArea workArea) {
65  		if (workArea != null) {
66  			workArea.setTasks(
67  					TkServiceLocator.getTaskService().getTasks(
68                              null,
69                              null,
70                              ObjectUtils.toString(workArea.getWorkArea()),
71                              workArea.getEffectiveDate(),
72                              null
73                      )
74              );
75  		}
76  	}
77  
78      @Override
79      public void populateWorkAreaRoles(WorkArea workArea) {
80          if (workArea != null) {
81              workArea.setRoles(TkServiceLocator.getTkRoleService().getWorkAreaRoles(workArea.getWorkArea()));
82              workArea.setInactiveRoles(TkServiceLocator.getTkRoleService().getInActiveWorkAreaRoles(workArea.getWorkArea()));
83          }
84      }
85  
86  	@Override
87  	public WorkArea getWorkArea(String tkWorkAreaId) {
88  		return workAreaDao.getWorkArea(tkWorkAreaId);
89  	}
90  
91  	@Override
92  	public Long getNextWorkAreaKey() {
93  		return workAreaDao.getNextWorkAreaKey();
94  	}
95  
96  	@Override
97  	public List<WorkArea> getWorkAreas(String dept, String workArea,
98  			String workAreaDescr, Date fromEffdt, Date toEffdt, String active,
99  			String showHistory) {
100 		return workAreaDao.getWorkAreas(dept, workArea, workAreaDescr, fromEffdt, toEffdt, active, showHistory);
101 	}
102 	
103 	@Override
104     public int getWorkAreaCount(String dept, Long workArea) {
105 		return workAreaDao.getWorkAreaCount(dept, workArea);
106     }
107 }