View Javadoc

1   /**
2    * Copyright 2004-2014 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.kpme.tklm.common;
17  
18  import javax.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpServletResponse;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.apache.struts.action.ActionForm;
23  import org.apache.struts.action.ActionForward;
24  import org.apache.struts.action.ActionMapping;
25  import org.kuali.kpme.core.calendar.Calendar;
26  import org.kuali.kpme.core.calendar.entry.CalendarEntry;
27  import org.kuali.kpme.core.service.HrServiceLocator;
28  import org.kuali.kpme.core.web.KPMEAction;
29  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
30  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
31  import org.kuali.rice.kim.api.identity.principal.Principal;
32  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
33  
34  public class InitiateDocumentAction extends KPMEAction {
35  
36      public ActionForward initiateDocument(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
37      	InitiateDocumentForm initiateDocumentForm = (InitiateDocumentForm) form;
38      	String principalId = initiateDocumentForm.getPrincipalId();
39      	String hrCalendarEntryId = initiateDocumentForm.getHrCalendarEntryId();
40      	
41      	if (StringUtils.isNotBlank(principalId) && StringUtils.isNotBlank(hrCalendarEntryId)) {
42      		Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
43      		CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry(hrCalendarEntryId);
44      		
45      		if (principal != null && calendarEntry != null) {
46      			Calendar calendar = HrServiceLocator.getCalendarService().getCalendar(calendarEntry.getHrCalendarId());
47      			
48      			if (calendar != null) {
49      				if (StringUtils.equals(calendar.getCalendarTypes(), TkConstants.CALENDAR_TYPE_PAY)) {
50      					TkServiceLocator.getTimesheetService().openTimesheetDocument(principalId, calendarEntry);
51      				} else if (StringUtils.equals(calendar.getCalendarTypes(), TkConstants.CALENDAR_TYPE_LEAVE)) {
52      					LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument(principalId, calendarEntry);
53      				}
54      			}
55      		}
56      	}
57      	
58      	return mapping.findForward("basic");
59      }
60      
61  }