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.admin.web; 017 018 import javax.servlet.http.HttpServletRequest; 019 import javax.servlet.http.HttpServletResponse; 020 021 import org.apache.commons.lang3.StringUtils; 022 import org.apache.struts.action.ActionForm; 023 import org.apache.struts.action.ActionForward; 024 import org.apache.struts.action.ActionMapping; 025 import org.kuali.hr.time.base.web.TkAction; 026 import org.kuali.hr.time.calendar.Calendar; 027 import org.kuali.hr.time.calendar.CalendarEntries; 028 import org.kuali.hr.time.service.base.TkServiceLocator; 029 import org.kuali.hr.time.util.TkConstants; 030 import org.kuali.rice.kim.api.identity.principal.Principal; 031 import org.kuali.rice.kim.api.services.KimApiServiceLocator; 032 033 public class InitiateDocumentAction extends TkAction { 034 035 public ActionForward initiateDocument(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 036 InitiateDocumentForm initiateDocumentForm = (InitiateDocumentForm) form; 037 String principalId = initiateDocumentForm.getPrincipalId(); 038 String hrCalendarEntriesId = initiateDocumentForm.getHrCalendarEntriesId(); 039 040 if (StringUtils.isNotBlank(principalId) && StringUtils.isNotBlank(hrCalendarEntriesId)) { 041 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId); 042 CalendarEntries calendarEntries = TkServiceLocator.getCalendarEntriesService().getCalendarEntries(hrCalendarEntriesId); 043 044 if (principal != null && calendarEntries != null) { 045 Calendar calendar = TkServiceLocator.getCalendarService().getCalendar(calendarEntries.getHrCalendarId()); 046 047 if (calendar != null) { 048 if (StringUtils.equals(calendar.getCalendarTypes(), TkConstants.CALENDAR_TYPE_PAY)) { 049 TkServiceLocator.getTimesheetService().openTimesheetDocument(principalId, calendarEntries); 050 } else if (StringUtils.equals(calendar.getCalendarTypes(), TkConstants.CALENDAR_TYPE_LEAVE)) { 051 TkServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument(principalId, calendarEntries); 052 } 053 } 054 } 055 } 056 057 return mapping.findForward("basic"); 058 } 059 060 }