1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.timesheet.validation;
17
18 import org.kuali.hr.time.calendar.Calendar;
19 import org.kuali.hr.time.calendar.CalendarEntries;
20 import org.kuali.hr.time.service.base.TkServiceLocator;
21 import org.kuali.hr.time.timesheet.TimeSheetInitiate;
22 import org.kuali.hr.time.timesheet.TimesheetDocument;
23 import org.kuali.rice.kew.api.exception.WorkflowException;
24 import org.kuali.rice.kns.document.MaintenanceDocument;
25 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
26
27 public class TimeSheetInitiateValidation extends MaintenanceDocumentRuleBase {
28 @Override
29 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
30 boolean valid = true;
31 TimeSheetInitiate timeInit = (TimeSheetInitiate)this.getNewBo();
32 Calendar pc = TkServiceLocator.getCalendarService().getCalendarByGroup(timeInit.getPyCalendarGroup());
33 if(pc == null) {
34 this.putFieldError("pyCalendarGroup", "timeSheetInit.payCalendar.Invalid");
35 valid = false;
36 }
37
38 CalendarEntries pce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries(timeInit.getHrPyCalendarEntriesId());
39 if(pce == null) {
40 this.putFieldError("hrPyCalendarEntriesId", "timeSheetInit.payCalEntriesId.Invalid");
41 valid = false;
42 }
43
44 if(valid) {
45 this.createTimeSheetDocument(timeInit, pce);
46 }
47 return valid;
48 }
49
50 protected void createTimeSheetDocument(TimeSheetInitiate timeInit, CalendarEntries entries) {
51 try {
52 TimesheetDocument tsd = TkServiceLocator.getTimesheetService().openTimesheetDocument(timeInit.getPrincipalId(), entries);
53 if(tsd != null) {
54 timeInit.setDocumentId(tsd.getDocumentId());
55 }
56 } catch (WorkflowException e) {
57
58 e.printStackTrace();
59 }
60 }
61 }