001/** 002 * Copyright 2004-2014 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 */ 016package org.kuali.kpme.tklm.api.leave.block; 017 018import org.joda.time.DateTime; 019import org.joda.time.LocalDate; 020import org.kuali.kpme.core.api.assignment.Assignment; 021import org.kuali.kpme.core.api.block.CalendarBlockPermissions; 022import org.kuali.kpme.core.api.calendar.entry.CalendarEntry; 023import org.springframework.cache.annotation.CacheEvict; 024import org.springframework.cache.annotation.Cacheable; 025import org.springframework.cache.annotation.Caching; 026 027import java.math.BigDecimal; 028import java.util.List; 029import java.util.Map; 030 031public interface LeaveBlockService { 032 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlock}' + 'leaveBlockId=' + #p0") 033 public LeaveBlock getLeaveBlock(String leaveBlockId); 034 035 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksForDocumentId}' + 'documentId=' + #p0") 036 public List<LeaveBlock> getLeaveBlocksForDocumentId(String documentId); 037 038 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocks}' + 'principalId=' + #p0 + '|' + 'beginDate=' + #p1 + '|' + 'endDate=' + #p2") 039 public List<LeaveBlock> getLeaveBlocks(String principalId, LocalDate beginDate, LocalDate endDate); 040 041 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksWithType}' + 'principalId=' + #p0 + '|' + 'beginDate=' + #p1 + '|' + 'endDate=' + #p2 + '|' + 'leaveBlockType=' + #p3") 042 public List<LeaveBlock> getLeaveBlocksWithType(String principalId, LocalDate beginDate, LocalDate endDate, String leaveBlockType); 043 044 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksWithAccrualCategory}' + 'principalId=' + #p0 + '|' + 'beginDate=' + #p1 + '|' + 'endDate=' + #p2 + '|' + 'accrualCategory=' + #p3") 045 public List<LeaveBlock> getLeaveBlocksWithAccrualCategory(String principalId, LocalDate beginDate, LocalDate endDate, String accrualCategory); 046 047 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksSinceCarryOver}' + 'principalId=' + #p0 + '|' + 'carryOverBlocks=' + T(org.kuali.rice.core.api.cache.CacheKeyUtils).mapKey(#p1) + '|' + 'endDate=' + #p2 + '|' + 'includeAllAccrualCategories=' + #p3") 048 public List<LeaveBlock> getLeaveBlocksSinceCarryOver(String principalId, Map<String, LeaveBlock> carryOverBlocks, LocalDate endDate, boolean includeAllAccrualCategories); 049 050 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLastCarryOverBlocks}' + 'principalId=' + #p0 + '|' + 'asOfDate=' + #p1") 051 public Map<String, LeaveBlock> getLastCarryOverBlocks(String principalId, LocalDate asOfDate); 052 053 @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true) 054 public List<LeaveBlock> saveLeaveBlocks(List<LeaveBlock> leaveBlocks); 055 056 057 @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true) 058 @Caching(evict = { 059 @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true), 060 @CacheEvict(value={CalendarBlockPermissions.CACHE_NAME}, key="#p0.blockId") 061 }) 062 public LeaveBlock saveLeaveBlock(LeaveBlock leaveBlock, String principalId); 063 064 /** 065 * The deletion marks the leave block inactive instead of removing the row from the database. 066 * @param leaveBlockId 067 * @param principalId 068 */ 069 @Caching(evict = { 070 @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true), 071 @CacheEvict(value={CalendarBlockPermissions.CACHE_NAME}, key="'{leave}' + #p0") 072 }) 073 public void deleteLeaveBlock(String leaveBlockId, String principalId); 074 075 076 @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true) 077 public List<LeaveBlock> addLeaveBlocks(DateTime beginDate, DateTime endDate, CalendarEntry ce, String selectedEarnCode, 078 BigDecimal hours, String description, Assignment selectedAssignment, String spanningWeeks, String leaveBlockType, String principalId, String userPrincipalId); 079 080 @Caching(evict = { 081 @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true), 082 @CacheEvict(value={CalendarBlockPermissions.CACHE_NAME}, key="#p0.getLmLeaveBlockId()") 083 }) 084 public void updateLeaveBlock(LeaveBlock leaveBlock, String principalId); 085 /** 086 * 087 * @param principalId 088 * @param leaveBlockType 089 * @param requestStatus 090 * @param currentDate currentDate to get the records for the future date, pass null when not required 091 * @return List of LeaveBlocks 092 */ 093 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocks}' + 'principalId=' + #p0 + '|' + 'leaveBlocktype=' + #p1 + '|' + 'requestStatus=' + #p2 + '|' + 'currentDate=' + #p3") 094 public List<LeaveBlock> getLeaveBlocks(String principalId, String leaveBlockType, String requestStatus, LocalDate currentDate); 095 096 /** 097 * 098 * @param principalId 099 * @param leaveBlockType 100 * @param requestStatus 101 * @param beginDate 102 * @param endDate 103 * @return List of LeaveBlocks 104 */ 105 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocks}' + 'principalId=' + #p0 + '|' + 'leaveBlocktype=' + #p1 + '|' + 'requestStatus=' + #p2 + '|' + 'beginDate=' + #p3 + '|' + 'endDate=' + #p4") 106 public List<LeaveBlock> getLeaveBlocks(String principalId, String leaveBlockType, String requestStatus, LocalDate beginDate, LocalDate endDate); 107 108 /** 109 * Get the list of leave blocks from the given leaveDate for the principalId 110 * @param principalId 111 * @param leaveDate 112 * @return List of LeaveBlocks 113 */ 114 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksForDate}' + 'principalId=' + #p0 + '|' + 'leaveDate=' + #p1") 115 public List<LeaveBlock> getLeaveBlocksForDate(String principalId, LocalDate leaveDate); 116 /** 117 * Get the list of not-accrual-generated leave blocks from the given leaveDate for the principalId 118 * @param principalId 119 * @param leaveDate 120 * @return List of LeaveBlocks 121 */ 122 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getNotAccrualGeneratedLeaveBlocksForDate}' + 'principalId=' + #p0 + '|' + 'leaveDate=' + #p1") 123 public List<LeaveBlock> getNotAccrualGeneratedLeaveBlocksForDate(String principalId, LocalDate leaveDate); 124 /** 125 * Get list of leave blocks to display on time sheet with given dates and principal id 126 * Only get leave blocks with type of leave calendar and time calendar 127 * the leave blocks should have assignments in the list of assignment keys 128 * @param principalId 129 * @param beginDate 130 * @param endDate 131 * @param assignmentKeys 132 * @return List of leave blocks 133 */ 134 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksForTimeCalendar}' + 'principalId=' + #p0 + '|' + 'beginDate=' + #p1 + '|' + 'endDate=' + #p2 + '|' + 'assignmentKeys=' + #p3") 135 public List<LeaveBlock> getLeaveBlocksForTimeCalendar(String principalId, LocalDate beginDate, LocalDate endDate, List<String> assignmentKeys); 136 /** 137 * Get list of leave blocks to display on leave calendar with given dates and principal id 138 * the leave blocks created from time calendar should have assignments in the list of assignment keys 139 * @param principalId 140 * @param beginDate 141 * @param endDate 142 * @param assignmentKeys 143 * @return List of leave blocks 144 */ 145 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksForLeaveCalendar}' + 'principalId=' + #p0 + '|' + 'beginDate=' + #p1 + '|' + 'endDate=' + #p2 + '|' + 'assignmentKeys=' + #p3") 146 public List<LeaveBlock> getLeaveBlocksForLeaveCalendar(String principalId, LocalDate beginDate, LocalDate endDate, List<String> assignmentKeys); 147 148 /** 149 * Filter list of leave blocks with given list of assignmentKeys for Time Calendar 150 * @param lbs 151 * @param assignmentKeys 152 * @return List of leave blocks 153 */ 154 public List<LeaveBlock> filterLeaveBlocksForTimeCalendar(List<LeaveBlock> lbs, List<String> assignmentKeys); 155 /** 156 * Filter list of leave blocks with given list of assignmentKeys for Leave Calendar 157 * @param lbs 158 * @param assignmentKeys 159 * @return List of leave blocks 160 */ 161 public List<LeaveBlock> filterLeaveBlocksForLeaveCalendar(List<LeaveBlock> lbs, List<String> assignmentKeys); 162 /** 163 * Delete time blocks for a given document id 164 * @param documentId 165 */ 166 public void deleteLeaveBlocksForDocumentId(String documentId); 167 168 /** 169 * Retrieve list of accrual generated leave blocks for given Date range and User 170 * @param principalId 171 * @param beginDate 172 * @param endDate 173 * @return List of leave blocks 174 */ 175 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getAccrualGeneratedLeaveBlocks}' + 'principalId=' + #p0 + '|' + 'beginDate=' + #p1 + '|' + 'endDate=' + #p2") 176 public List<LeaveBlock> getAccrualGeneratedLeaveBlocks(String principalId, LocalDate beginDate, LocalDate endDate); 177 178 /** 179 * Retrieve list of leave blocks generated with given system scheduled time off id, date and user 180 * @param principalId 181 * @param sstoId 182 * @param accruledDate 183 * @return 184 */ 185 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getSSTOLeaveBlocks}' + 'principalId=' + #p0 + '|' + 'sstoId=' + #p1 + '|' + 'accruleDate=' + #p2") 186 public List<LeaveBlock> getSSTOLeaveBlocks(String principalId, String sstoId, LocalDate accruledDate); 187 188 /** 189 * gets list of leave blocks created for earn codes with eligible-for-accrual=no since the given timestamp 190 * The leave blocks are normally for absent earn codes (ABE) 191 * @param principalId 192 * @param lastRanDateTime 193 * @return 194 */ 195 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getABELeaveBlocksSinceTime}' + 'principalId=' + #p0 + '|' + 'lastRanTime=' + #p1") 196 public List<LeaveBlock> getABELeaveBlocksSinceTime(String principalId, DateTime lastRanDateTime); 197 198 /** 199 * retrieves a list of leave blocks of type "TIME_CALENADAR" whose optional parameters match those required in Time Block Lookup. 200 * 201 * @param documentId This field is not used in persistence criteria. Leave Blocks do not have timesheet document id populated. TODO: Remove param, or set timesheet header ids on leave blocks. 202 * @param principalId optional principal to find leave blocks for 203 * @param userPrincipalId optional principal that made modifications to the leave block - i.e. an admin targeting a specific user. 204 * @param fromDate optional lower bound date, inclusive. matches against LeaveBlock.leaveDate 205 * @param toDate optional upper bound date, exclusive. matches against LeaveBlock.leaveDate 206 * @return 207 */ 208 @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getTimeCalendarLeaveBlocksForTimeBlockLookup}' + 'principalId=' + #p0 + '|' + 'lastRanTime=' + #p1") 209 public List<LeaveBlock> getTimeCalendarLeaveBlocksForTimeBlockLookup( 210 String documentId, String principalId, String userPrincipalId, 211 LocalDate fromDate, LocalDate toDate); 212 213 /** 214 * retrieves a list of leave blocks of whose optional parameters match those required in Time Block Lookup. 215 * 216 * @param documentId This field is not used in persistence criteria. Leave Blocks do not have timesheet document id populated. TODO: Remove param, or set timesheet header ids on leave blocks. 217 * @param principalId optional principal to find leave blocks for 218 * @param userPrincipalId optional principal that made modifications to the leave block - i.e. an admin targeting a specific user. 219 * @param fromDate optional lower bound date, inclusive. matches against LeaveBlock.leaveDate 220 * @param toDate optional upper bound date, exclusive. matches against LeaveBlock.leaveDate 221 * @param leaveBlockType optional Leave Block Type, exclusive. matches against LeaveBlock.leaveBlockType 222 * @return 223 */ 224 // @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksForLookup}' + 'principalId=' + #p0 + '|' + 'lastRanTime=' + #p1") 225 public List<LeaveBlock> getLeaveBlocksForLookup( 226 String documentId, String principalId, String userPrincipalId, 227 LocalDate fromDate, LocalDate toDate, String leaveBlockType); 228}