001 /** 002 * Copyright 2004-2013 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.earncodegroup.service; 017 018 import org.apache.commons.collections.CollectionUtils; 019 import org.apache.commons.lang.StringUtils; 020 import org.kuali.hr.time.earncodegroup.EarnCodeGroup; 021 import org.kuali.hr.time.earncodegroup.EarnCodeGroupDefinition; 022 import org.kuali.hr.time.earncodegroup.dao.EarnCodeGroupDaoService; 023 import org.kuali.hr.time.timeblock.TimeBlock; 024 import org.kuali.hr.time.timesheet.TimesheetDocument; 025 026 import java.sql.Date; 027 import java.util.ArrayList; 028 import java.util.HashSet; 029 import java.util.List; 030 import java.util.Set; 031 032 public class EarnCodeGroupServiceImpl implements EarnCodeGroupService { 033 private EarnCodeGroupDaoService earnCodeGroupDao; 034 035 @Override 036 public EarnCodeGroup getEarnCodeGroup(String earnCodeGroup, Date asOfDate) { 037 return earnCodeGroupDao.getEarnCodeGroup(earnCodeGroup, asOfDate); 038 } 039 040 public EarnCodeGroupDaoService getEarnCodeGroupDao() { 041 return earnCodeGroupDao; 042 } 043 044 public void setEarnCodeGroupDao(EarnCodeGroupDaoService earnCodeGroupDao) { 045 this.earnCodeGroupDao = earnCodeGroupDao; 046 } 047 048 @Override 049 public EarnCodeGroup getEarnCodeGroupSummaryForEarnCode(String earnCode, Date asOfDate) { 050 return earnCodeGroupDao.getEarnCodeGroupSummaryForEarnCode(earnCode, asOfDate); 051 } 052 053 @Override 054 public EarnCodeGroup getEarnCodeGroupForEarnCode(String earnCode, Date asOfDate) { 055 return earnCodeGroupDao.getEarnCodeGroupForEarnCode(earnCode, asOfDate); 056 } 057 058 public Set<String> getEarnCodeListForEarnCodeGroup(String earnCodeGroup, Date asOfDate) { 059 Set<String> earnCodes = new HashSet<String>(); 060 EarnCodeGroup earnGroupObj = earnCodeGroupDao.getEarnCodeGroup(earnCodeGroup, asOfDate); 061 if ( earnGroupObj != null ) { 062 for (EarnCodeGroupDefinition earnGroupDef : earnGroupObj.getEarnCodeGroups()) { 063 if (!earnCodes.contains(earnGroupDef.getEarnCode())) { 064 earnCodes.add(earnGroupDef.getEarnCode()); 065 } 066 } 067 } 068 return earnCodes; 069 } 070 071 @Override 072 public EarnCodeGroup getEarnCodeGroup(String hrEarnCodeGroupId) { 073 return earnCodeGroupDao.getEarnCodeGroup(hrEarnCodeGroupId); 074 } 075 076 @Override 077 public List<String> warningTextFromEarnCodeGroupsOfTimeblocks(List<TimeBlock> tbList) { 078 List<String> warningMessages = new ArrayList<String>(); 079 if (CollectionUtils.isEmpty(tbList)) { 080 return warningMessages; 081 } 082 083 Set<String> aSet = new HashSet<String>(); 084 for(TimeBlock tb : tbList) { 085 EarnCodeGroup eg = this.getEarnCodeGroupForEarnCode(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 094 @Override 095 public List<String> warningTextFromEarnCodeGroupsOfDocument(TimesheetDocument timesheetDocument) { 096 List<String> warningMessages = new ArrayList<String>(); 097 if (timesheetDocument == null) { 098 return warningMessages; 099 } 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 }