1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.shiftdiff.rule.service;
17
18 import org.apache.log4j.Logger;
19 import org.joda.time.*;
20 import org.kuali.hr.job.Job;
21 import org.kuali.hr.time.calendar.CalendarEntries;
22 import org.kuali.hr.time.principal.PrincipalHRAttributes;
23 import org.kuali.hr.time.service.base.TkServiceLocator;
24 import org.kuali.hr.time.shiftdiff.rule.ShiftDifferentialRule;
25 import org.kuali.hr.time.shiftdiff.rule.dao.ShiftDifferentialRuleDao;
26 import org.kuali.hr.time.timeblock.TimeBlock;
27 import org.kuali.hr.time.timeblock.TimeHourDetail;
28 import org.kuali.hr.time.timesheet.TimesheetDocument;
29 import org.kuali.hr.time.util.TKUtils;
30 import org.kuali.hr.time.util.TkConstants;
31 import org.kuali.hr.time.util.TkTimeBlockAggregate;
32 import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
33
34 import java.math.BigDecimal;
35 import java.sql.Date;
36 import java.util.*;
37
38
39 public class ShiftDifferentialRuleServiceImpl implements ShiftDifferentialRuleService {
40
41 @SuppressWarnings("unused")
42 private static final Logger LOG = Logger.getLogger(ShiftDifferentialRuleServiceImpl.class);
43
44
45
46
47 private ShiftDifferentialRuleDao shiftDifferentialRuleDao = null;
48
49 private Map<Long,List<ShiftDifferentialRule>> getJobNumberToShiftRuleMap(TimesheetDocument timesheetDocument) {
50 Map<Long,List<ShiftDifferentialRule>> jobNumberToShifts = new HashMap<Long,List<ShiftDifferentialRule>>();
51 PrincipalHRAttributes principalCal = TkServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(timesheetDocument.getPrincipalId(),timesheetDocument.getPayCalendarEntry().getEndPeriodDate());
52
53 for (Job job : timesheetDocument.getJobs()) {
54 List<ShiftDifferentialRule> shiftDifferentialRules = getShiftDifferentalRules(job.getLocation(),job.getHrSalGroup(),job.getPayGrade(),principalCal.getPayCalendar(),
55 TKUtils.getTimelessDate(timesheetDocument.getPayCalendarEntry().getBeginPeriodDateTime()));
56 if (shiftDifferentialRules.size() > 0)
57 jobNumberToShifts.put(job.getJobNumber(), shiftDifferentialRules);
58 }
59
60 return jobNumberToShifts;
61 }
62
63 private Map<Long,List<TimeBlock>> getPreviousPayPeriodLastDayJobToTimeBlockMap(TimesheetDocument timesheetDocument, Map<Long,List<ShiftDifferentialRule>> jobNumberToShifts) {
64 Map<Long, List<TimeBlock>> jobNumberToTimeBlocksPreviousDay = null;
65
66
67
68 List<TimeBlock> prevBlocks = TkServiceLocator.getTimesheetService().getPrevDocumentTimeBlocks(timesheetDocument.getPrincipalId(), timesheetDocument.getDocumentHeader().getPayBeginDate());
69 if (prevBlocks.size() > 0) {
70 TimesheetDocumentHeader prevTdh = TkServiceLocator.getTimesheetDocumentHeaderService().getPreviousDocumentHeader(timesheetDocument.getPrincipalId(), timesheetDocument.getDocumentHeader().getPayBeginDate());
71 if (prevTdh != null) {
72 CalendarEntries prevPayCalendarEntry = TkServiceLocator.getCalendarService().getCalendarDatesByPayEndDate(timesheetDocument.getPrincipalId(), prevTdh.getPayEndDate(), null);
73 TkTimeBlockAggregate prevTimeAggregate = new TkTimeBlockAggregate(prevBlocks, prevPayCalendarEntry, prevPayCalendarEntry.getCalendarObj(), true);
74 List<List<TimeBlock>> dayBlocks = prevTimeAggregate.getDayTimeBlockList();
75 List<TimeBlock> previousPeriodLastDayBlocks = dayBlocks.get(dayBlocks.size() - 1);
76
77 if (previousPeriodLastDayBlocks.size() > 0) {
78 jobNumberToTimeBlocksPreviousDay = new HashMap<Long, List<TimeBlock>>();
79
80 for (TimeBlock block : previousPeriodLastDayBlocks) {
81
82
83 Long jobNumber = block.getJobNumber();
84 if (jobNumberToShifts.containsKey(jobNumber)) {
85
86 List<TimeBlock> jblist = jobNumberToTimeBlocksPreviousDay.get(jobNumber);
87 if (jblist == null) {
88 jblist = new ArrayList<TimeBlock>();
89 jobNumberToTimeBlocksPreviousDay.put(jobNumber, jblist);
90 }
91 jblist.add(block);
92 }
93 }
94 }
95 }
96 }
97
98 return jobNumberToTimeBlocksPreviousDay;
99 }
100
101 private boolean timeBlockHasEarnCode(Set<String> earnCodes, TimeBlock block) {
102 boolean present = false;
103
104 if (block != null && earnCodes != null)
105 present = earnCodes.contains(block.getEarnCode());
106
107 return present;
108 }
109
110
111
112
113
114
115
116
117
118
119 private BigDecimal negativeTimeHourDetailSum(TimeBlock block) {
120 BigDecimal sum = BigDecimal.ZERO;
121
122 if (block != null) {
123 List<TimeHourDetail> details = block.getTimeHourDetails();
124 for (TimeHourDetail detail : details) {
125 if (detail.getEarnCode().equals(TkConstants.LUNCH_EARN_CODE)) {
126 sum = sum.add(detail.getHours());
127 }
128 }
129 }
130
131 return sum;
132 }
133
134 @Override
135 public void processShiftDifferentialRules(TimesheetDocument timesheetDocument, TkTimeBlockAggregate aggregate) {
136 DateTimeZone zone = TkServiceLocator.getTimezoneService().getUserTimezoneWithFallback();
137 List<List<TimeBlock>> blockDays = aggregate.getDayTimeBlockList();
138 DateTime periodStartDateTime = timesheetDocument.getPayCalendarEntry().getBeginLocalDateTime().toDateTime(zone);
139 Map<Long,List<ShiftDifferentialRule>> jobNumberToShifts = getJobNumberToShiftRuleMap(timesheetDocument);
140
141
142
143 if (jobNumberToShifts.isEmpty()) {
144 return;
145 }
146
147
148
149
150
151
152 boolean previousPayPeriodPrevDay = true;
153 Map<Long, List<TimeBlock>> jobNumberToTimeBlocksPreviousDay =
154 getPreviousPayPeriodLastDayJobToTimeBlockMap(timesheetDocument, jobNumberToShifts);
155
156
157
158
159 for (int pos = 0; pos < blockDays.size(); pos++) {
160 List<TimeBlock> blocks = blockDays.get(pos);
161 if (blocks.isEmpty())
162 continue;
163
164 DateTime currentDay = periodStartDateTime.plusDays(pos);
165 Interval virtualDay = new Interval(currentDay, currentDay.plusHours(24));
166
167
168
169
170
171
172
173 Map<Long, List<TimeBlock>> jobNumberToTimeBlocks = new HashMap<Long,List<TimeBlock>>();
174 for (TimeBlock block : blocks) {
175 Long jobNumber = block.getJobNumber();
176 if (jobNumberToShifts.containsKey(jobNumber)) {
177 List<TimeBlock> jblist = jobNumberToTimeBlocks.get(jobNumber);
178 if (jblist == null) {
179 jblist = new ArrayList<TimeBlock>();
180 jobNumberToTimeBlocks.put(jobNumber, jblist);
181 }
182 jblist.add(block);
183 }
184 }
185
186
187
188
189
190
191
192
193
194 for (Long jobNumber: jobNumberToShifts.keySet()) {
195 List<ShiftDifferentialRule> shiftDifferentialRules = jobNumberToShifts.get(jobNumber);
196
197 List<TimeBlock> ruleTimeBlocksPrev = null;
198 List<TimeBlock> ruleTimeBlocksCurr = jobNumberToTimeBlocks.get(jobNumber);
199 if (ruleTimeBlocksCurr != null && ruleTimeBlocksCurr.size() > 0) {
200 if (jobNumberToTimeBlocksPreviousDay != null)
201 ruleTimeBlocksPrev = jobNumberToTimeBlocksPreviousDay.get(jobNumber);
202 if (ruleTimeBlocksPrev != null && ruleTimeBlocksPrev.size() > 0)
203 this.sortTimeBlocksInverse(ruleTimeBlocksPrev);
204 this.sortTimeBlocksNatural(ruleTimeBlocksCurr);
205 } else {
206
207
208
209 continue;
210 }
211
212 for (ShiftDifferentialRule rule : shiftDifferentialRules) {
213 Set<String> fromEarnGroup = TkServiceLocator.getEarnGroupService().getEarnCodeListForEarnGroup(rule.getFromEarnGroup(), TKUtils.getTimelessDate(timesheetDocument.getPayCalendarEntry().getBeginPeriodDateTime()));
214
215
216
217
218 LocalTime ruleStart = new LocalTime(rule.getBeginTime(), TKUtils.getSystemDateTimeZone());
219 LocalTime ruleEnd = new LocalTime(rule.getEndTime(), TKUtils.getSystemDateTimeZone());
220 ruleStart = new LocalTime(ruleStart, zone);
221 ruleEnd = new LocalTime(ruleEnd, zone);
222
223
224 DateTime shiftEnd = ruleEnd.toDateTime(currentDay);
225 DateTime shiftStart = ruleStart.toDateTime(currentDay);
226
227 if (shiftEnd.isBefore(shiftStart) || shiftEnd.isEqual(shiftStart))
228 shiftEnd = shiftEnd.plusDays(1);
229 Interval shiftInterval = new Interval(shiftStart, shiftEnd);
230
231
232 BigDecimal hoursBeforeVirtualDay = BigDecimal.ZERO;
233
234
235
236 TimeBlock firstBlockOfCurrentDay = null;
237 for (TimeBlock b : ruleTimeBlocksCurr) {
238 if (timeBlockHasEarnCode(fromEarnGroup, b)) {
239 firstBlockOfCurrentDay = b;
240 break;
241 }
242 }
243
244
245 Interval previousDayShiftInterval = new Interval(shiftStart.minusDays(1), shiftEnd.minusDays(1));
246
247
248 Interval evalInterval = null;
249 if (ruleTimeBlocksPrev != null && ruleTimeBlocksPrev.size() > 0 && dayIsRuleActive(currentDay.minusDays(1), rule)) {
250
251
252 if (shiftEnd.isAfter(virtualDay.getEnd())) {
253
254 TimeBlock firstBlockOfPreviousDay = null;
255 for (TimeBlock b : ruleTimeBlocksPrev) {
256 if (timeBlockHasEarnCode(fromEarnGroup, b)) {
257 firstBlockOfPreviousDay = b;
258 break;
259 }
260 }
261
262
263
264
265 if ( (firstBlockOfPreviousDay != null) && (firstBlockOfCurrentDay != null)) {
266 Interval previousBlockInterval = new Interval(new DateTime(firstBlockOfPreviousDay.getEndTimestamp(), zone), new DateTime(firstBlockOfCurrentDay.getBeginTimestamp(), zone));
267 Duration blockGapDuration = previousBlockInterval.toDuration();
268 BigDecimal bgdHours = TKUtils.convertMillisToHours(blockGapDuration.getMillis());
269 if (bgdHours.compareTo(rule.getMaxGap()) <= 0) {
270
271
272
273
274 for (int i=0; i<ruleTimeBlocksPrev.size(); i++) {
275 TimeBlock b = ruleTimeBlocksPrev.get(i);
276 if (timeBlockHasEarnCode(fromEarnGroup, b)) {
277 Interval blockInterval = new Interval(new DateTime(b.getBeginTimestamp(), zone), new DateTime(b.getEndTimestamp(), zone));
278
279
280 if (previousBlockInterval != null) {
281 blockGapDuration = new Duration(new DateTime(b.getEndTimestamp(), zone), previousBlockInterval.getStart());
282 bgdHours = TKUtils.convertMillisToHours(blockGapDuration.getMillis());
283 }
284
285
286 if (bgdHours.compareTo(rule.getMaxGap()) <= 0) {
287
288 if (blockInterval.overlaps(previousDayShiftInterval)) {
289 BigDecimal hrs = TKUtils.convertMillisToHours(blockInterval.overlap(previousDayShiftInterval).toDurationMillis());
290 hoursBeforeVirtualDay = hoursBeforeVirtualDay.add(hrs);
291 }
292
293 } else {
294
295 break;
296 }
297
298 previousBlockInterval = blockInterval;
299
300 }
301 }
302 } else {
303
304 }
305 }
306 }
307 }
308
309 BigDecimal hoursToApply = BigDecimal.ZERO;
310 BigDecimal hoursToApplyPrevious = BigDecimal.ZERO;
311
312
313
314 if (hoursBeforeVirtualDay.compareTo(rule.getMinHours()) <= 0) {
315
316 hoursToApplyPrevious = hoursBeforeVirtualDay;
317 }
318
319
320
321
322 TimeBlock previous = null;
323 List<TimeBlock> accumulatedBlocks = new ArrayList<TimeBlock>();
324 List<Interval> accumulatedBlockIntervals = new ArrayList<Interval>();
325
326 long accumulatedMillis = TKUtils.convertHoursToMillis(hoursBeforeVirtualDay);
327
328 boolean previousDayOnly = false;
329 if (!dayIsRuleActive(currentDay, rule)) {
330 if (dayIsRuleActive(currentDay.minusDays(1), rule)) {
331 previousDayOnly = true;
332 } else {
333
334 continue;
335 }
336
337 }
338
339
340
341
342
343
344
345
346
347
348
349
350 List<TimeBlock> previousBlocksFiltered = (previousPayPeriodPrevDay) ? null : filterBlocksByApplicableEarnGroup(fromEarnGroup, ruleTimeBlocksPrev);
351
352 for (TimeBlock current : ruleTimeBlocksCurr) {
353 if (!timeBlockHasEarnCode(fromEarnGroup, current)) {
354
355 continue;
356 }
357
358 Interval blockInterval = new Interval(new DateTime(current.getBeginTimestamp(), zone), new DateTime(current.getEndTimestamp(), zone));
359
360
361
362
363 if (previousDayShiftInterval.overlaps(shiftInterval))
364 throw new RuntimeException("Interval of greater than 24 hours created in the rules processing.");
365
366
367
368
369
370 Interval overlap = previousDayShiftInterval.overlap(blockInterval);
371 evalInterval = previousDayShiftInterval;
372 if (overlap == null) {
373 if (hoursToApplyPrevious.compareTo(BigDecimal.ZERO) > 0) {
374
375
376
377
378 BigDecimal accumHours = TKUtils.convertMillisToHours(accumulatedMillis);
379 this.applyAccumulatedWrapper(accumHours, evalInterval, accumulatedBlockIntervals, accumulatedBlocks, previousBlocksFiltered, hoursToApplyPrevious, hoursToApply, rule);
380 accumulatedMillis = 0L;
381 hoursToApply = BigDecimal.ZERO;
382 hoursToApplyPrevious = BigDecimal.ZERO;
383 }
384
385
386
387
388
389 if (previousDayOnly) {
390 continue;
391 }
392
393 overlap = shiftInterval.overlap(blockInterval);
394 evalInterval = shiftInterval;
395 }
396
397
398
399 if (overlap != null) {
400
401 if (previous != null) {
402 if (exceedsMaxGap(previous, current, rule.getMaxGap())) {
403 BigDecimal accumHours = TKUtils.convertMillisToHours(accumulatedMillis);
404 this.applyAccumulatedWrapper(accumHours, evalInterval, accumulatedBlockIntervals, accumulatedBlocks, previousBlocksFiltered, hoursToApplyPrevious, hoursToApply, rule);
405 accumulatedMillis = 0L;
406 hoursToApply = BigDecimal.ZERO;
407 hoursToApplyPrevious = BigDecimal.ZERO;
408 } else {
409 long millis = overlap.toDurationMillis();
410 accumulatedMillis += millis;
411 hoursToApply = hoursToApply.add(TKUtils.convertMillisToHours(millis));
412 }
413 } else {
414
415 long millis = overlap.toDurationMillis();
416 accumulatedMillis += millis;
417 hoursToApply = hoursToApply.add(TKUtils.convertMillisToHours(millis));
418 }
419 accumulatedBlocks.add(current);
420 accumulatedBlockIntervals.add(blockInterval);
421 previous = current;
422 } else {
423
424 if (previous != null) {
425 BigDecimal accumHours = TKUtils.convertMillisToHours(accumulatedMillis);
426 this.applyAccumulatedWrapper(accumHours, evalInterval, accumulatedBlockIntervals, accumulatedBlocks, previousBlocksFiltered, hoursToApplyPrevious, hoursToApply, rule);
427 accumulatedMillis = 0L;
428 hoursToApply = BigDecimal.ZERO;
429 hoursToApplyPrevious = BigDecimal.ZERO;
430 }
431 }
432
433 }
434
435
436
437 BigDecimal accumHours = TKUtils.convertMillisToHours(accumulatedMillis);
438 this.applyAccumulatedWrapper(accumHours, evalInterval, accumulatedBlockIntervals, accumulatedBlocks, previousBlocksFiltered, hoursToApplyPrevious, hoursToApply, rule);
439 }
440 }
441
442 jobNumberToTimeBlocksPreviousDay = jobNumberToTimeBlocks;
443 previousPayPeriodPrevDay = false;
444 }
445
446 }
447
448 private List<TimeBlock> filterBlocksByApplicableEarnGroup(Set<String> fromEarnGroup, List<TimeBlock> blocks) {
449 List<TimeBlock> filtered;
450
451 if (blocks == null || blocks.size() == 0)
452 filtered = null;
453 else {
454 filtered = new ArrayList<TimeBlock>();
455 for (TimeBlock b : blocks) {
456 if (timeBlockHasEarnCode(fromEarnGroup, b))
457 filtered.add(b);
458 }
459 }
460
461 return filtered;
462 }
463
464
465 private void applyAccumulatedWrapper(BigDecimal accumHours, Interval evalInterval, List<Interval>accumulatedBlockIntervals, List<TimeBlock>accumulatedBlocks, List<TimeBlock> previousBlocks, BigDecimal hoursToApplyPrevious, BigDecimal hoursToApply, ShiftDifferentialRule rule) {
466 if (accumHours.compareTo(rule.getMinHours()) >= 0) {
467 this.applyPremium(evalInterval, accumulatedBlockIntervals, accumulatedBlocks, previousBlocks, hoursToApplyPrevious, hoursToApply, rule.getEarnCode());
468 }
469 accumulatedBlocks.clear();
470 accumulatedBlockIntervals.clear();
471 }
472
473 private void sortTimeBlocksInverse(List<TimeBlock> blocks) {
474 Collections.sort(blocks, new Comparator<TimeBlock>() {
475 public int compare(TimeBlock tb1, TimeBlock tb2) {
476 if (tb1 != null && tb2 != null)
477 return -1 * tb1.getBeginTimestamp().compareTo(tb2.getBeginTimestamp());
478 return 0;
479 }
480 });
481 }
482
483 private void sortTimeBlocksNatural(List<TimeBlock> blocks) {
484 Collections.sort(blocks, new Comparator<TimeBlock>() {
485 public int compare(TimeBlock tb1, TimeBlock tb2) {
486 if (tb1 != null && tb2 != null)
487 return tb1.getBeginTimestamp().compareTo(tb2.getBeginTimestamp());
488 return 0;
489 }
490 });
491 }
492
493
494
495
496
497
498
499
500
501
502
503 void applyPremium(Interval shift, List<Interval> blockIntervals, List<TimeBlock> blocks, List<TimeBlock> previousBlocks, BigDecimal initialHours, BigDecimal hours, String earnCode) {
504 for (int i=0; i<blocks.size(); i++) {
505 TimeBlock b = blocks.get(i);
506
507
508 if (i == 0 && (initialHours.compareTo(BigDecimal.ZERO) > 0)) {
509
510
511 if (previousBlocks != null && previousBlocks.size() > 0 && previousBlocks.get(0).getDocumentId().equals(b.getDocumentId())) {
512 for (TimeBlock pb : previousBlocks) {
513 BigDecimal lunchSub = this.negativeTimeHourDetailSum(pb);
514 initialHours = BigDecimal.ZERO.max(initialHours.add(lunchSub));
515 if (initialHours.compareTo(BigDecimal.ZERO) <= 0)
516 break;
517
518
519 BigDecimal hoursToApply = initialHours.min(pb.getHours().add(lunchSub));
520 addPremiumTimeHourDetail(pb, hoursToApply, earnCode);
521 initialHours = initialHours.subtract(hoursToApply, TkConstants.MATH_CONTEXT);
522 if (initialHours.compareTo(BigDecimal.ZERO) <= 0)
523 break;
524 }
525 } else {
526 addPremiumTimeHourDetail(b, initialHours, earnCode);
527 }
528 }
529
530 BigDecimal lunchSub = this.negativeTimeHourDetailSum(b);
531 hours = BigDecimal.ZERO.max(hours.add(lunchSub));
532
533 if (hours.compareTo(BigDecimal.ZERO) > 0) {
534 Interval blockInterval = blockIntervals.get(i);
535 Interval overlapInterval = shift.overlap(blockInterval);
536 if (overlapInterval == null)
537 continue;
538
539 long overlap = overlapInterval.toDurationMillis();
540 BigDecimal hoursMax = TKUtils.convertMillisToHours(overlap);
541
542
543 BigDecimal hoursToApply = hours.min(hoursMax.add(lunchSub));
544
545 addPremiumTimeHourDetail(b, hoursToApply, earnCode);
546 hours = hours.subtract(hoursToApply, TkConstants.MATH_CONTEXT);
547 }
548 }
549 }
550
551 void addPremiumTimeHourDetail(TimeBlock block, BigDecimal hours, String earnCode) {
552 List<TimeHourDetail> details = block.getTimeHourDetails();
553 TimeHourDetail premium = new TimeHourDetail();
554 premium.setHours(hours);
555 premium.setEarnCode(earnCode);
556 premium.setTkTimeBlockId(block.getTkTimeBlockId());
557 details.add(premium);
558 }
559
560
561
562
563
564
565
566
567
568
569 boolean exceedsMaxGap(TimeBlock previous, TimeBlock current, BigDecimal maxGap) {
570 long difference = current.getBeginTimestamp().getTime() - previous.getEndTimestamp().getTime();
571 BigDecimal gapHours = TKUtils.convertMillisToHours(difference);
572
573 return (gapHours.compareTo(maxGap) > 0);
574 }
575
576 public void setShiftDifferentialRuleDao(ShiftDifferentialRuleDao shiftDifferentialRuleDao) {
577 this.shiftDifferentialRuleDao = shiftDifferentialRuleDao;
578 }
579
580 @Override
581 public ShiftDifferentialRule getShiftDifferentialRule(String tkShiftDifferentialRuleId) {
582 return this.shiftDifferentialRuleDao.findShiftDifferentialRule(tkShiftDifferentialRuleId);
583 }
584
585 @Override
586 public List<ShiftDifferentialRule> getShiftDifferentalRules(String location, String hrSalGroup, String payGrade, String pyCalendarGroup, Date asOfDate) {
587 List<ShiftDifferentialRule> sdrs = new ArrayList<ShiftDifferentialRule>();
588
589
590
591 sdrs.addAll(shiftDifferentialRuleDao.findShiftDifferentialRules(location, hrSalGroup, payGrade, pyCalendarGroup, asOfDate));
592
593
594 sdrs.addAll(shiftDifferentialRuleDao.findShiftDifferentialRules(location, hrSalGroup, "%", pyCalendarGroup, asOfDate));
595
596
597 sdrs.addAll(shiftDifferentialRuleDao.findShiftDifferentialRules(location, "%", payGrade, pyCalendarGroup, asOfDate));
598
599
600 sdrs.addAll(shiftDifferentialRuleDao.findShiftDifferentialRules(location, "%", "%", pyCalendarGroup, asOfDate));
601
602
603 sdrs.addAll(shiftDifferentialRuleDao.findShiftDifferentialRules("%", hrSalGroup, payGrade, pyCalendarGroup, asOfDate));
604
605
606 sdrs.addAll(shiftDifferentialRuleDao.findShiftDifferentialRules("%", hrSalGroup, "%", pyCalendarGroup, asOfDate));
607
608
609 sdrs.addAll(shiftDifferentialRuleDao.findShiftDifferentialRules("%", "%", payGrade, pyCalendarGroup, asOfDate));
610
611
612 sdrs.addAll(shiftDifferentialRuleDao.findShiftDifferentialRules("%", "%", "%", pyCalendarGroup, asOfDate));
613
614 if (sdrs == null)
615 sdrs = Collections.emptyList();
616
617 return sdrs;
618 }
619
620 private boolean dayIsRuleActive(DateTime currentDate, ShiftDifferentialRule sdr) {
621 boolean active = false;
622
623 switch (currentDate.getDayOfWeek()) {
624 case DateTimeConstants.MONDAY:
625 active = sdr.isMonday();
626 break;
627 case DateTimeConstants.TUESDAY:
628 active = sdr.isTuesday();
629 break;
630 case DateTimeConstants.WEDNESDAY:
631 active = sdr.isWednesday();
632 break;
633 case DateTimeConstants.THURSDAY:
634 active = sdr.isThursday();
635 break;
636 case DateTimeConstants.FRIDAY:
637 active = sdr.isFriday();
638 break;
639 case DateTimeConstants.SATURDAY:
640 active = sdr.isSaturday();
641 break;
642 case DateTimeConstants.SUNDAY:
643 active = sdr.isSunday();
644 break;
645 }
646
647 return active;
648 }
649
650 @Override
651 public void saveOrUpdate(List<ShiftDifferentialRule> shiftDifferentialRules) {
652 shiftDifferentialRuleDao.saveOrUpdate(shiftDifferentialRules);
653 }
654
655 @Override
656 public void saveOrUpdate(ShiftDifferentialRule shiftDifferentialRule) {
657 shiftDifferentialRuleDao.saveOrUpdate(shiftDifferentialRule);
658 }
659
660 }