View Javadoc
1   /**
2    * Copyright 2004-2014 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.kpme.tklm.api.leave.block;
17  
18  import org.joda.time.DateTime;
19  import org.joda.time.LocalDate;
20  import org.kuali.kpme.core.api.assignment.Assignment;
21  import org.kuali.kpme.core.api.block.CalendarBlockPermissions;
22  import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
23  import org.springframework.cache.annotation.CacheEvict;
24  import org.springframework.cache.annotation.Cacheable;
25  import org.springframework.cache.annotation.Caching;
26  
27  import java.math.BigDecimal;
28  import java.util.List;
29  import java.util.Map;
30  
31  public interface LeaveBlockService {
32  	@Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlock}' + 'leaveBlockId=' + #p0")
33      public LeaveBlock getLeaveBlock(String leaveBlockId);
34  	
35  	@Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksForDocumentId}' + 'documentId=' + #p0")
36  	public List<LeaveBlock> getLeaveBlocksForDocumentId(String documentId);
37      
38  	@Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocks}' + 'principalId=' + #p0 + '|' + 'beginDate=' + #p1 + '|' + 'endDate=' + #p2")
39      public List<LeaveBlock> getLeaveBlocks(String principalId, LocalDate beginDate, LocalDate endDate);
40      
41      @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksWithType}' + 'principalId=' + #p0 + '|' + 'beginDate=' + #p1 + '|' + 'endDate=' + #p2 + '|' + 'leaveBlockType=' + #p3")
42      public List<LeaveBlock> getLeaveBlocksWithType(String principalId, LocalDate beginDate, LocalDate endDate, String leaveBlockType);
43      
44      @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksWithAccrualCategory}' + 'principalId=' + #p0 + '|' + 'beginDate=' + #p1 + '|' + 'endDate=' + #p2 + '|' + 'accrualCategory=' + #p3")
45      public List<LeaveBlock> getLeaveBlocksWithAccrualCategory(String principalId, LocalDate beginDate, LocalDate endDate, String accrualCategory);
46      
47      @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocksSinceCarryOver}' + 'principalId=' + #p0 + '|' + 'carryOverBlocks=' + #p1 + '|' + 'endDate=' + #p2 + '|' + 'includeAllAccrualCategories=' + #p3")
48      public List<LeaveBlock> getLeaveBlocksSinceCarryOver(String principalId, Map<String, LeaveBlock> carryOverBlocks, LocalDate endDate, boolean includeAllAccrualCategories);
49      
50      @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLastCarryOverBlocks}' + 'principalId=' + #p0 + '|' + 'asOfDate=' + #p1")
51      public Map<String, LeaveBlock> getLastCarryOverBlocks(String principalId, LocalDate asOfDate);
52      
53      @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true)
54      public List<LeaveBlock> saveLeaveBlocks(List<LeaveBlock> leaveBlocks);
55  
56  
57      @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true)
58      @Caching(evict = {
59              @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true),
60              @CacheEvict(value={CalendarBlockPermissions.CACHE_NAME}, key="#p0.blockId")
61      })
62      public LeaveBlock saveLeaveBlock(LeaveBlock leaveBlock, String principalId);
63  
64      /**
65       * The deletion marks the leave block inactive instead of removing the row from the database.
66       * @param leaveBlockId
67       * @param principalId
68       */
69      @Caching(evict = {
70              @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true),
71              @CacheEvict(value={CalendarBlockPermissions.CACHE_NAME}, key="'{leave}' + #p0")
72      })
73      public void deleteLeaveBlock(String leaveBlockId, String principalId);
74  
75  
76      @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true)
77      public List<LeaveBlock> addLeaveBlocks(DateTime beginDate, DateTime endDate, CalendarEntry ce, String selectedEarnCode,
78      		BigDecimal hours, String description, Assignment selectedAssignment, String spanningWeeks, String leaveBlockType, String principalId);
79      
80      @Caching(evict = {
81              @CacheEvict(value={LeaveBlock.CACHE_NAME}, allEntries = true),
82              @CacheEvict(value={CalendarBlockPermissions.CACHE_NAME}, key="#p0.getLmLeaveBlockId()")
83      })
84      public void updateLeaveBlock(LeaveBlock leaveBlock, String principalId);
85      /**
86       * 
87       * @param principalId
88       * @param leaveBlockType
89       * @param requestStatus
90       * @param currentDate currentDate to get the records for the future date, pass null when not required
91       * @return List of LeaveBlocks
92       */
93      @Cacheable(value= LeaveBlock.CACHE_NAME, key="'{getLeaveBlocks}' + 'principalId=' + #p0 + '|' + 'leaveBlocktype=' + #p1 + '|' + 'requestStatus=' + #p2 + '|' + 'currentDate=' + #p3")
94      public List<LeaveBlock> getLeaveBlocks(String principalId, String leaveBlockType, String requestStatus, LocalDate currentDate);
95  
96      /**
97       *
98       * @param principalId
99       * @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 }