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