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.task.service;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.hr.time.service.base.TkServiceLocator;
20  import org.kuali.hr.time.task.Task;
21  import org.kuali.hr.time.task.dao.TaskDao;
22  import org.kuali.hr.time.util.TkConstants;
23  import org.kuali.hr.time.workarea.WorkArea;
24  
25  import java.sql.Date;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  public class TaskServiceImpl implements TaskService {
30  
31      private TaskDao taskDao;
32  
33      @Override
34      public Task getTask(Long task, Date asOfDate) {
35          Task taskObj =  taskDao.getTask(task, asOfDate);
36          if(taskObj == null){
37          	taskObj = new Task();
38          	taskObj.setActive(true);
39          	taskObj.setEffectiveDate(asOfDate);
40          	taskObj.setTask(task);
41          	taskObj.setDescription(TkConstants.TASK_DEFAULT_DESP);
42          	taskObj.setTkTaskId("0");
43          }
44          return taskObj;
45      }
46  
47      @Override
48      public void saveTask(Task task) {
49          taskDao.saveOrUpdate(task);
50      }
51  
52      @Override
53      public void saveTasks(List<Task> tasks) {
54          taskDao.saveOrUpdate(tasks);
55      }
56  
57      public void setTaskDao(TaskDao taskDao) {
58          this.taskDao = taskDao;
59      } 
60  
61  	@Override
62  	public Task getMaxTask(){
63  		return taskDao.getMaxTask();
64  	}
65  
66      @Override
67      public List<Task> getTasks(String task, String description, String workArea, String workAreaDesc, Date fromEffdt, Date toEffdt) {
68  
69          Long taskForQuery = StringUtils.isEmpty(task) ? null : Long.parseLong(task);
70  
71          List<Task> results = new ArrayList<Task>();
72          if (StringUtils.isNotEmpty(workAreaDesc)) {
73              List<WorkArea> workAreas = TkServiceLocator.getWorkAreaService().getWorkAreas(null, null, workAreaDesc, null, null, "Y", "N");
74              for (WorkArea wa : workAreas) {
75                  List<Task> tasks = taskDao.getTasks(taskForQuery, description, wa.getWorkArea(), workAreaDesc, fromEffdt, toEffdt);
76                  results.addAll(tasks);
77              }
78          } else {
79              Long wa = StringUtils.isEmpty(workArea) ? null : Long.parseLong(workArea);
80              List<Task> tasks = taskDao.getTasks(taskForQuery, description, wa, workAreaDesc, fromEffdt, toEffdt);
81              results.addAll(tasks);
82          }
83  
84          return results;
85      }
86      
87      @Override
88      public int getTaskCount(Long task) {
89      	return taskDao.getTaskCount(task);
90      }
91  }