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.rule; 017 018 import java.util.List; 019 020 import org.apache.commons.lang.StringUtils; 021 import org.kuali.hr.lm.leaveblock.LeaveBlock; 022 import org.kuali.hr.time.calendar.CalendarEntries; 023 import org.kuali.hr.time.service.base.TkServiceLocator; 024 import org.kuali.hr.time.timeblock.TimeBlock; 025 import org.kuali.hr.time.timesheet.TimesheetDocument; 026 import org.kuali.hr.time.util.TKContext; 027 import org.kuali.hr.time.util.TKUser; 028 import org.kuali.hr.time.util.TkConstants; 029 import org.kuali.hr.time.util.TkTimeBlockAggregate; 030 import org.kuali.rice.krad.util.GlobalVariables; 031 032 public class TkRuleControllerServiceImpl implements TkRuleControllerService { 033 034 // TODO : Filter actions to reduce computation for rule runs: Clock IN for example does not need to execute rule running. 035 public void applyRules(String action, List<TimeBlock> timeBlocks, List<LeaveBlock> leaveBlocks, CalendarEntries payEntry, TimesheetDocument timesheetDocument, String principalId){ 036 //foreach action run the rules that apply 037 if(StringUtils.equals(action, TkConstants.ACTIONS.ADD_TIME_BLOCK) || StringUtils.equals(action, TkConstants.ACTIONS.CLOCK_OUT)){ 038 TkTimeBlockAggregate timeBlockAggregate = new TkTimeBlockAggregate(timeBlocks, leaveBlocks, payEntry, payEntry.getCalendarObj(), true); 039 // 040 // Need to run LunchRule first - It will reduce hours in some instances 041 042 // anyone who records time through the time entry form (async users) should not be affected by the lunch rule 043 // Noted that the date field in the buildTkUser method is not currently used. 044 if (GlobalVariables.getUserSession() != null && TKUser.getCurrentTargetRoles().isSynchronous()) { 045 TkServiceLocator.getDepartmentLunchRuleService().applyDepartmentLunchRule(timeBlockAggregate.getFlattenedTimeBlockList()); 046 } 047 TkServiceLocator.getShiftDifferentialRuleService().processShiftDifferentialRules(timesheetDocument, timeBlockAggregate); 048 TkServiceLocator.getDailyOvertimeRuleService().processDailyOvertimeRules(timesheetDocument, timeBlockAggregate); 049 TkServiceLocator.getWeeklyOvertimeRuleService().processWeeklyOvertimeRule(timesheetDocument, timeBlockAggregate); 050 } 051 } 052 053 054 }