1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }