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