View Javadoc
1   /**
2    * Copyright 2004-2014 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.kpme.tklm.time.timehourdetail.service;
17  
18  import java.util.List;
19  
20  import org.kuali.kpme.tklm.api.time.timeblock.TimeBlock;
21  import org.kuali.kpme.tklm.api.time.timehourdetail.TimeHourDetail;
22  import org.kuali.kpme.tklm.api.time.timehourdetail.TimeHourDetailService;
23  import org.kuali.kpme.tklm.time.timehourdetail.TimeHourDetailBo;
24  import org.kuali.kpme.tklm.time.timehourdetail.dao.TimeHourDetailDao;
25  import org.kuali.rice.core.api.mo.ModelObjectUtils;
26  import org.kuali.rice.krad.service.KRADServiceLocator;
27  
28  public class TimeHourDetailServiceImpl implements TimeHourDetailService {
29      private static final ModelObjectUtils.Transformer<TimeHourDetailBo, TimeHourDetail> toTimeHourDetail =
30              new ModelObjectUtils.Transformer<TimeHourDetailBo, TimeHourDetail>() {
31                  public TimeHourDetail transform(TimeHourDetailBo input) {
32                      return TimeHourDetailBo.to(input);
33                  };
34              };
35      private static final ModelObjectUtils.Transformer<TimeHourDetail, TimeHourDetailBo> toTimeHourDetailBo =
36              new ModelObjectUtils.Transformer<TimeHourDetail, TimeHourDetailBo>() {
37                  public TimeHourDetailBo transform(TimeHourDetail input) {
38                      return TimeHourDetailBo.from(input);
39                  };
40              };
41  	TimeHourDetailDao timeHourDetailDao;
42  
43  	@Override
44  	public TimeHourDetail getTimeHourDetail(String timeHourDetailId) {
45  		return TimeHourDetailBo.to(getTimeHourDetailBo(timeHourDetailId));
46  	}
47  
48      protected TimeHourDetailBo getTimeHourDetailBo(String timeHourDetailId) {
49          return timeHourDetailDao.getTimeHourDetail(timeHourDetailId);
50      }
51  
52  	@Override
53  	public TimeHourDetail saveTimeHourDetail(TimeBlock tb) {
54  
55  		TimeHourDetailBo td = new TimeHourDetailBo();
56  
57  		td.setTkTimeBlockId(tb.getTkTimeBlockId());
58  		td.setEarnCode(tb.getEarnCode());
59  		td.setHours(tb.getHours());
60          td.setTotalMinutes(tb.getTotalMinutes());
61  		td.setAmount(tb.getAmount());
62  
63  		TimeHourDetailBo timeHourDetailBo = KRADServiceLocator.getBusinessObjectService().save(td);
64  
65  		return TimeHourDetailBo.to(timeHourDetailBo);
66  	}
67  
68  	public void setTimeHourDetailDao(TimeHourDetailDao timeHourDetailDao) {
69  		this.timeHourDetailDao = timeHourDetailDao;
70  	}
71  
72      @Override
73  	public List<TimeHourDetail> getTimeHourDetailsForTimeBlock(String timeBlockId) {
74  		return ModelObjectUtils.transform(this.timeHourDetailDao.getTimeHourDetailsForTimeBlock(timeBlockId), toTimeHourDetail);
75  	}
76  
77      public void removeTimeHourDetails(String timeBlockId) {
78          this.timeHourDetailDao.remove(timeBlockId);
79      }
80      
81      @Override
82      public void removeTimeHourDetail(String timeHourDetailId) {
83          timeHourDetailDao.removeById(timeHourDetailId);
84      }
85  }