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.earngroup.service;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.hr.time.earngroup.EarnGroup;
20  import org.kuali.hr.time.earngroup.EarnGroupDefinition;
21  import org.kuali.hr.time.earngroup.dao.EarnGroupDaoService;
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 EarnGroupServiceImpl implements EarnGroupService {
32      private EarnGroupDaoService earnGroupDao;
33  
34      @Override
35      public EarnGroup getEarnGroup(String earnGroup, Date asOfDate) {
36          return earnGroupDao.getEarnGroup(earnGroup, asOfDate);
37      }
38  
39      public EarnGroupDaoService getEarnGroupDao() {
40          return earnGroupDao;
41      }
42  
43      public void setEarnGroupDao(EarnGroupDaoService earnGroupDao) {
44          this.earnGroupDao = earnGroupDao;
45      }
46  
47      @Override
48      public EarnGroup getEarnGroupSummaryForEarnCode(String earnCode, Date asOfDate) {
49          return earnGroupDao.getEarnGroupSummaryForEarnCode(earnCode, asOfDate);
50      }
51  
52      @Override
53      public EarnGroup getEarnGroupForEarnCode(String earnCode, Date asOfDate) {
54          return earnGroupDao.getEarnGroupForEarnCode(earnCode, asOfDate);
55      }
56  
57      public Set<String> getEarnCodeListForEarnGroup(String earnGroup, Date asOfDate) {
58          Set<String> earnCodes = new HashSet<String>();
59          EarnGroup earnGroupObj = earnGroupDao.getEarnGroup(earnGroup, asOfDate);
60          if ( earnGroupObj != null ) {
61              for (EarnGroupDefinition earnGroupDef : earnGroupObj.getEarnGroups()) {
62                  if (!earnCodes.contains(earnGroupDef.getEarnCode())) {
63                      earnCodes.add(earnGroupDef.getEarnCode());
64                  }
65              }
66          }
67          return earnCodes;
68      }
69  
70      @Override
71      public EarnGroup getEarnGroup(String hrEarnGroupId) {
72          return earnGroupDao.getEarnGroup(hrEarnGroupId);
73      }
74      
75      @Override
76      public List<String> warningTextFromEarnGroupsOfDocument(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  	    	EarnGroup eg = this.getEarnGroupForEarnCode(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 getEarnGroupCount(String earnGroup) {
95      	return earnGroupDao.getEarnGroupCount(earnGroup);
96      }
97      @Override
98      public int getNewerEarnGroupCount(String earnGroup, Date effdt) {
99      	return earnGroupDao.getNewerEarnGroupCount(earnGroup, effdt);
100     }
101 }