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.lang.StringUtils;
19  import org.kuali.hr.time.earncodegroup.EarnCodeGroup;
20  import org.kuali.hr.time.earncodegroup.EarnCodeGroupDefinition;
21  import org.kuali.hr.time.earncodegroup.dao.EarnCodeGroupDaoService;
22  import org.kuali.hr.time.timeblock.TimeBlock;
23  import org.kuali.hr.time.timesheet.TimesheetDocument;
24  
25  import java.sql.Date;
26  import java.util.ArrayList;
27  import java.util.HashSet;
28  import java.util.List;
29  import java.util.Set;
30  
31  public class EarnCodeGroupServiceImpl implements EarnCodeGroupService {
32      private EarnCodeGroupDaoService earnCodeGroupDao;
33  
34      @Override
35      public EarnCodeGroup getEarnCodeGroup(String earnCodeGroup, Date asOfDate) {
36          return earnCodeGroupDao.getEarnCodeGroup(earnCodeGroup, asOfDate);
37      }
38  
39      public EarnCodeGroupDaoService getEarnCodeGroupDao() {
40          return earnCodeGroupDao;
41      }
42  
43      public void setEarnCodeGroupDao(EarnCodeGroupDaoService earnCodeGroupDao) {
44          this.earnCodeGroupDao = earnCodeGroupDao;
45      }
46  
47      @Override
48      public EarnCodeGroup getEarnCodeGroupSummaryForEarnCode(String earnCode, Date asOfDate) {
49          return earnCodeGroupDao.getEarnCodeGroupSummaryForEarnCode(earnCode, asOfDate);
50      }
51  
52      @Override
53      public EarnCodeGroup getEarnCodeGroupForEarnCode(String earnCode, Date asOfDate) {
54          return earnCodeGroupDao.getEarnCodeGroupForEarnCode(earnCode, asOfDate);
55      }
56  
57      public Set<String> getEarnCodeListForEarnCodeGroup(String earnCodeGroup, Date asOfDate) {
58          Set<String> earnCodes = new HashSet<String>();
59          EarnCodeGroup earnGroupObj = earnCodeGroupDao.getEarnCodeGroup(earnCodeGroup, asOfDate);
60          if ( earnGroupObj != null ) {
61              for (EarnCodeGroupDefinition earnGroupDef : earnGroupObj.getEarnCodeGroups()) {
62                  if (!earnCodes.contains(earnGroupDef.getEarnCode())) {
63                      earnCodes.add(earnGroupDef.getEarnCode());
64                  }
65              }
66          }
67          return earnCodes;
68      }
69  
70      @Override
71      public EarnCodeGroup getEarnCodeGroup(String hrEarnCodeGroupId) {
72          return earnCodeGroupDao.getEarnCodeGroup(hrEarnCodeGroupId);
73      }
74      
75      @Override
76      public List<String> warningTextFromEarnCodeGroupsOfDocument(TimesheetDocument timesheetDocument) {
77      	 List<String> warningMessages = new ArrayList<String>();
78  	     List<TimeBlock> tbList = timesheetDocument.getTimeBlocks();
79  	     if (tbList.isEmpty()) {
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      @Override
94      public int getEarnCodeGroupCount(String earnCodeGroup) {
95      	return earnCodeGroupDao.getEarnCodeGroupCount(earnCodeGroup);
96      }
97      @Override
98      public int getNewerEarnCodeGroupCount(String earnCodeGroup, Date effdt) {
99      	return earnCodeGroupDao.getNewerEarnCodeGroupCount(earnCodeGroup, effdt);
100     }
101 }