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.time.rules;
17  
18  import java.util.List;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.kpme.core.calendar.entry.CalendarEntry;
22  import org.kuali.kpme.tklm.common.TkConstants;
23  import org.kuali.kpme.tklm.leave.block.LeaveBlock;
24  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
25  import org.kuali.kpme.tklm.time.timeblock.TimeBlock;
26  import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
27  import org.kuali.kpme.tklm.time.util.TkContext;
28  import org.kuali.kpme.tklm.time.util.TkTimeBlockAggregate;
29  import org.kuali.rice.krad.util.GlobalVariables;
30  
31  public class TkRuleControllerServiceImpl implements TkRuleControllerService {
32  
33      // TODO : Filter actions to reduce computation for rule runs: Clock IN for example does not need to execute rule running.
34  	public void applyRules(String action, List<TimeBlock> timeBlocks, List<LeaveBlock> leaveBlocks, CalendarEntry payEntry, TimesheetDocument timesheetDocument, String principalId){
35  		//foreach action run the rules that apply
36  		if(StringUtils.equals(action, TkConstants.ACTIONS.ADD_TIME_BLOCK) || StringUtils.equals(action, TkConstants.ACTIONS.CLOCK_OUT)){
37              TkTimeBlockAggregate timeBlockAggregate = new TkTimeBlockAggregate(timeBlocks, leaveBlocks, payEntry, payEntry.getCalendarObj(), true);
38              //
39              // Need to run LunchRule first - It will reduce hours in some instances
40  
41              // anyone who records time through the time entry form (async users) should not be affected by the lunch rule
42              // Noted that the date field in the buildTkUser method is not currently used.
43              if (GlobalVariables.getUserSession() != null && TkContext.isTargetSynchronous()) {
44  			    TkServiceLocator.getDepartmentLunchRuleService().applyDepartmentLunchRule(timeBlockAggregate.getFlattenedTimeBlockList());
45              }
46  			TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(timesheetDocument, timeBlockAggregate);
47  			TkServiceLocator.getDailyOvertimeRuleService().processDailyOvertimeRules(timesheetDocument, timeBlockAggregate);
48  			TkServiceLocator.getWeeklyOvertimeRuleService().processWeeklyOvertimeRule(timesheetDocument, timeBlockAggregate);
49  		}
50  	}
51  
52  
53  }