View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  			// TODO Auto-generated catch block
58  			e.printStackTrace();
59  		}
60      }
61  }