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