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.earngroup.service; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.hr.time.earngroup.EarnGroup; 020 import org.kuali.hr.time.earngroup.EarnGroupDefinition; 021 import org.kuali.hr.time.earngroup.dao.EarnGroupDaoService; 022 import org.kuali.hr.time.timeblock.TimeBlock; 023 import org.kuali.hr.time.timesheet.TimesheetDocument; 024 025 import java.sql.Date; 026 import java.util.ArrayList; 027 import java.util.HashSet; 028 import java.util.List; 029 import java.util.Set; 030 031 public class EarnGroupServiceImpl implements EarnGroupService { 032 private EarnGroupDaoService earnGroupDao; 033 034 @Override 035 public EarnGroup getEarnGroup(String earnGroup, Date asOfDate) { 036 return earnGroupDao.getEarnGroup(earnGroup, asOfDate); 037 } 038 039 public EarnGroupDaoService getEarnGroupDao() { 040 return earnGroupDao; 041 } 042 043 public void setEarnGroupDao(EarnGroupDaoService earnGroupDao) { 044 this.earnGroupDao = earnGroupDao; 045 } 046 047 @Override 048 public EarnGroup getEarnGroupSummaryForEarnCode(String earnCode, Date asOfDate) { 049 return earnGroupDao.getEarnGroupSummaryForEarnCode(earnCode, asOfDate); 050 } 051 052 @Override 053 public EarnGroup getEarnGroupForEarnCode(String earnCode, Date asOfDate) { 054 return earnGroupDao.getEarnGroupForEarnCode(earnCode, asOfDate); 055 } 056 057 public Set<String> getEarnCodeListForEarnGroup(String earnGroup, Date asOfDate) { 058 Set<String> earnCodes = new HashSet<String>(); 059 EarnGroup earnGroupObj = earnGroupDao.getEarnGroup(earnGroup, asOfDate); 060 if ( earnGroupObj != null ) { 061 for (EarnGroupDefinition earnGroupDef : earnGroupObj.getEarnGroups()) { 062 if (!earnCodes.contains(earnGroupDef.getEarnCode())) { 063 earnCodes.add(earnGroupDef.getEarnCode()); 064 } 065 } 066 } 067 return earnCodes; 068 } 069 070 @Override 071 public EarnGroup getEarnGroup(String hrEarnGroupId) { 072 return earnGroupDao.getEarnGroup(hrEarnGroupId); 073 } 074 075 @Override 076 public List<String> warningTextFromEarnGroupsOfDocument(TimesheetDocument timesheetDocument) { 077 List<String> warningMessages = new ArrayList<String>(); 078 List<TimeBlock> tbList = timesheetDocument.getTimeBlocks(); 079 if (tbList.isEmpty()) { 080 return warningMessages; 081 } 082 083 Set<String> aSet = new HashSet<String>(); 084 for(TimeBlock tb : tbList) { 085 EarnGroup eg = this.getEarnGroupForEarnCode(tb.getEarnCode(), tb.getBeginDate()); 086 if(eg != null && !StringUtils.isEmpty(eg.getWarningText())) { 087 aSet.add(eg.getWarningText()); 088 } 089 } 090 warningMessages.addAll(aSet); 091 return warningMessages; 092 } 093 @Override 094 public int getEarnGroupCount(String earnGroup) { 095 return earnGroupDao.getEarnGroupCount(earnGroup); 096 } 097 @Override 098 public int getNewerEarnGroupCount(String earnGroup, Date effdt) { 099 return earnGroupDao.getNewerEarnGroupCount(earnGroup, effdt); 100 } 101 }