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.task.service;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.hr.time.service.base.TkServiceLocator;
020 import org.kuali.hr.time.task.Task;
021 import org.kuali.hr.time.task.dao.TaskDao;
022 import org.kuali.hr.time.util.TkConstants;
023 import org.kuali.hr.time.workarea.WorkArea;
024
025 import java.sql.Date;
026 import java.util.ArrayList;
027 import java.util.List;
028
029 public class TaskServiceImpl implements TaskService {
030
031 private TaskDao taskDao;
032
033 @Override
034 public Task getTask(Long task, Date asOfDate) {
035 Task taskObj = taskDao.getTask(task, asOfDate);
036 if(taskObj == null){
037 taskObj = new Task();
038 taskObj.setActive(true);
039 taskObj.setEffectiveDate(asOfDate);
040 taskObj.setTask(task);
041 taskObj.setDescription(TkConstants.TASK_DEFAULT_DESP);
042 taskObj.setTkTaskId("0");
043 }
044 return taskObj;
045 }
046
047 @Override
048 public void saveTask(Task task) {
049 taskDao.saveOrUpdate(task);
050 }
051
052 @Override
053 public void saveTasks(List<Task> tasks) {
054 taskDao.saveOrUpdate(tasks);
055 }
056
057 public void setTaskDao(TaskDao taskDao) {
058 this.taskDao = taskDao;
059 }
060
061 @Override
062 public Task getMaxTask(){
063 return taskDao.getMaxTask();
064 }
065
066 @Override
067 public List<Task> getTasks(String task, String description, String workArea, String workAreaDesc, Date fromEffdt, Date toEffdt) {
068
069 Long taskForQuery = StringUtils.isEmpty(task) ? null : Long.parseLong(task);
070
071 List<Task> results = new ArrayList<Task>();
072 if (StringUtils.isNotEmpty(workAreaDesc)) {
073 List<WorkArea> workAreas = TkServiceLocator.getWorkAreaService().getWorkAreas(null, null, workAreaDesc, null, null, "Y", "N");
074 for (WorkArea wa : workAreas) {
075 List<Task> tasks = taskDao.getTasks(taskForQuery, description, wa.getWorkArea(), workAreaDesc, fromEffdt, toEffdt);
076 results.addAll(tasks);
077 }
078 } else {
079 Long wa = StringUtils.isEmpty(workArea) ? null : Long.parseLong(workArea);
080 List<Task> tasks = taskDao.getTasks(taskForQuery, description, wa, workAreaDesc, fromEffdt, toEffdt);
081 results.addAll(tasks);
082 }
083
084 return results;
085 }
086
087 @Override
088 public int getTaskCount(Long task) {
089 return taskDao.getTaskCount(task);
090 }
091 }