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.earncodegroup.service;
17  
18  import org.apache.commons.collections.CollectionUtils;
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.hr.time.earncodegroup.EarnCodeGroup;
21  import org.kuali.hr.time.earncodegroup.EarnCodeGroupDefinition;
22  import org.kuali.hr.time.earncodegroup.dao.EarnCodeGroupDaoService;
23  import org.kuali.hr.time.timeblock.TimeBlock;
24  import org.kuali.hr.time.timesheet.TimesheetDocument;
25  
26  import java.sql.Date;
27  import java.util.ArrayList;
28  import java.util.HashSet;
29  import java.util.List;
30  import java.util.Set;
31  
32  public class EarnCodeGroupServiceImpl implements EarnCodeGroupService {
33      private EarnCodeGroupDaoService earnCodeGroupDao;
34  
35      @Override
36      public EarnCodeGroup getEarnCodeGroup(String earnCodeGroup, Date asOfDate) {
37          return earnCodeGroupDao.getEarnCodeGroup(earnCodeGroup, asOfDate);
38      }
39  
40      public EarnCodeGroupDaoService getEarnCodeGroupDao() {
41          return earnCodeGroupDao;
42      }
43  
44      public void setEarnCodeGroupDao(EarnCodeGroupDaoService earnCodeGroupDao) {
45          this.earnCodeGroupDao = earnCodeGroupDao;
46      }
47  
48      @Override
49      public EarnCodeGroup getEarnCodeGroupSummaryForEarnCode(String earnCode, Date asOfDate) {
50          return earnCodeGroupDao.getEarnCodeGroupSummaryForEarnCode(earnCode, asOfDate);
51      }
52  
53      @Override
54      public EarnCodeGroup getEarnCodeGroupForEarnCode(String earnCode, Date asOfDate) {
55          return earnCodeGroupDao.getEarnCodeGroupForEarnCode(earnCode, asOfDate);
56      }
57  
58      public Set<String> getEarnCodeListForEarnCodeGroup(String earnCodeGroup, Date asOfDate) {
59          Set<String> earnCodes = new HashSet<String>();
60          EarnCodeGroup earnGroupObj = earnCodeGroupDao.getEarnCodeGroup(earnCodeGroup, asOfDate);
61          if ( earnGroupObj != null ) {
62              for (EarnCodeGroupDefinition earnGroupDef : earnGroupObj.getEarnCodeGroups()) {
63                  if (!earnCodes.contains(earnGroupDef.getEarnCode())) {
64                      earnCodes.add(earnGroupDef.getEarnCode());
65                  }
66              }
67          }
68          return earnCodes;
69      }
70  
71      @Override
72      public EarnCodeGroup getEarnCodeGroup(String hrEarnCodeGroupId) {
73          return earnCodeGroupDao.getEarnCodeGroup(hrEarnCodeGroupId);
74      }
75  
76      @Override
77      public List<String> warningTextFromEarnCodeGroupsOfTimeblocks(List<TimeBlock> tbList) {
78          List<String> warningMessages = new ArrayList<String>();
79          if (CollectionUtils.isEmpty(tbList)) {
80              return warningMessages;
81          }
82  
83          Set<String> aSet = new HashSet<String>();
84          for(TimeBlock tb : tbList) {
85              EarnCodeGroup eg = this.getEarnCodeGroupForEarnCode(tb.getEarnCode(), tb.getBeginDate());
86              if(eg != null && !StringUtils.isEmpty(eg.getWarningText())) {
87                  aSet.add(eg.getWarningText());
88              }
89          }
90          warningMessages.addAll(aSet);
91          return warningMessages;
92      }
93  
94      @Override
95      public List<String> warningTextFromEarnCodeGroupsOfDocument(TimesheetDocument timesheetDocument) {
96      	 List<String> warningMessages = new ArrayList<String>();
97           if (timesheetDocument == null) {
98               return warningMessages;
99           }
100 	    warningMessages.addAll(warningTextFromEarnCodeGroupsOfTimeblocks(timesheetDocument.getTimeBlocks()));
101 		return warningMessages;
102     }
103     @Override
104     public int getEarnCodeGroupCount(String earnCodeGroup) {
105     	return earnCodeGroupDao.getEarnCodeGroupCount(earnCodeGroup);
106     }
107     @Override
108     public int getNewerEarnCodeGroupCount(String earnCodeGroup, Date effdt) {
109     	return earnCodeGroupDao.getNewerEarnCodeGroupCount(earnCodeGroup, effdt);
110     }
111 }