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.admin.web;
17  
18  import java.text.DateFormat;
19  import java.text.SimpleDateFormat;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.apache.log4j.Logger;
26  import org.apache.struts.action.ActionForm;
27  import org.apache.struts.action.ActionForward;
28  import org.apache.struts.action.ActionMapping;
29  import org.kuali.hr.time.base.web.TkAction;
30  import org.kuali.hr.time.service.base.TkServiceLocator;
31  import org.kuali.rice.kim.api.identity.Person;
32  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
33  
34  public class CalculateLeaveAccrualsAction extends TkAction {
35  	
36  	private static final Logger LOG = Logger.getLogger(ChangeTargetPersonAction.class);
37  	
38      public ActionForward runAccruals(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
39      	CalculateLeaveAccrualsForm calculateLeaveAccrualsForm = (CalculateLeaveAccrualsForm) form;
40      	
41      	DateFormat formater = new SimpleDateFormat("MM/dd/yyyy");
42      	Person principal = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(calculateLeaveAccrualsForm.getPrincipalName());
43  		if (principal != null) {
44      		if (StringUtils.isNotBlank(calculateLeaveAccrualsForm.getStartDate()) && StringUtils.isNotBlank(calculateLeaveAccrualsForm.getEndDate())) {
45      			java.util.Date parsedStartDate = formater.parse(calculateLeaveAccrualsForm.getStartDate());
46      			java.sql.Date startDate= new java.sql.Date(parsedStartDate.getTime());
47  
48      			java.util.Date parsedEndDate = formater.parse(calculateLeaveAccrualsForm.getEndDate());
49      			java.sql.Date endDate= new java.sql.Date(parsedEndDate.getTime());
50      	
51      			LOG.debug("AccrualServiceImpl.runAccrual() called with Principal: " + principal.getPrincipalName() + " Start: " + startDate.toString() + " End: " + endDate.toString());
52      			TkServiceLocator.getLeaveAccrualService().runAccrual(principal.getPrincipalId(), startDate, endDate, true);
53      		} else {
54      			LOG.debug("AccrualServiceImpl.runAccrual() called with Principal: " + principal.getPrincipalName());
55      			TkServiceLocator.getLeaveAccrualService().runAccrual(principal.getPrincipalId());
56      		}
57  		}
58      	return mapping.findForward("basic");
59      }
60      
61      public ActionForward clearAccruals(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
62      	CalculateLeaveAccrualsForm adminForm = (CalculateLeaveAccrualsForm) form;
63      	
64      	if (StringUtils.isNotBlank(adminForm.getPrincipalName())) {
65      		LOG.debug("AccrualServiceImpl.clearAccrual() called with Principal: " + adminForm.getPrincipalName());
66      		adminForm.setPrincipalName("");
67      	} 
68      	if (StringUtils.isNotBlank(adminForm.getStartDate())) {
69      		LOG.debug("AccrualServiceImpl.clearAccrual() called with Start Date: " + adminForm.getStartDate());
70      		adminForm.setStartDate("");
71      	} 
72      	if (StringUtils.isNotBlank(adminForm.getEndDate())) {
73      		LOG.debug("AccrualServiceImpl.clearAccrual() called with End Date: " + adminForm.getEndDate());
74      		adminForm.setEndDate("");
75      	} 
76      	
77      	return mapping.findForward("basic");
78      }
79  
80  }