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 java.text.DateFormat; 019 import java.text.SimpleDateFormat; 020 021 import javax.servlet.http.HttpServletRequest; 022 import javax.servlet.http.HttpServletResponse; 023 024 import org.apache.commons.lang.StringUtils; 025 import org.apache.log4j.Logger; 026 import org.apache.struts.action.ActionForm; 027 import org.apache.struts.action.ActionForward; 028 import org.apache.struts.action.ActionMapping; 029 import org.kuali.hr.time.base.web.TkAction; 030 import org.kuali.hr.time.service.base.TkServiceLocator; 031 import org.kuali.rice.kim.api.identity.Person; 032 import org.kuali.rice.kim.api.services.KimApiServiceLocator; 033 034 public class CalculateLeaveAccrualsAction extends TkAction { 035 036 private static final Logger LOG = Logger.getLogger(ChangeTargetPersonAction.class); 037 038 public ActionForward runAccruals(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 039 CalculateLeaveAccrualsForm calculateLeaveAccrualsForm = (CalculateLeaveAccrualsForm) form; 040 041 DateFormat formater = new SimpleDateFormat("MM/dd/yyyy"); 042 Person principal = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(calculateLeaveAccrualsForm.getPrincipalName()); 043 if (principal != null) { 044 if (StringUtils.isNotBlank(calculateLeaveAccrualsForm.getStartDate()) && StringUtils.isNotBlank(calculateLeaveAccrualsForm.getEndDate())) { 045 java.util.Date parsedStartDate = formater.parse(calculateLeaveAccrualsForm.getStartDate()); 046 java.sql.Date startDate= new java.sql.Date(parsedStartDate.getTime()); 047 048 java.util.Date parsedEndDate = formater.parse(calculateLeaveAccrualsForm.getEndDate()); 049 java.sql.Date endDate= new java.sql.Date(parsedEndDate.getTime()); 050 051 LOG.debug("AccrualServiceImpl.runAccrual() called with Principal: " + principal.getPrincipalName() + " Start: " + startDate.toString() + " End: " + endDate.toString()); 052 TkServiceLocator.getLeaveAccrualService().runAccrual(principal.getPrincipalId(), startDate, endDate, true); 053 } else { 054 LOG.debug("AccrualServiceImpl.runAccrual() called with Principal: " + principal.getPrincipalName()); 055 TkServiceLocator.getLeaveAccrualService().runAccrual(principal.getPrincipalId()); 056 } 057 } 058 return mapping.findForward("basic"); 059 } 060 061 public ActionForward clearAccruals(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 062 CalculateLeaveAccrualsForm adminForm = (CalculateLeaveAccrualsForm) form; 063 064 if (StringUtils.isNotBlank(adminForm.getPrincipalName())) { 065 LOG.debug("AccrualServiceImpl.clearAccrual() called with Principal: " + adminForm.getPrincipalName()); 066 adminForm.setPrincipalName(""); 067 } 068 if (StringUtils.isNotBlank(adminForm.getStartDate())) { 069 LOG.debug("AccrualServiceImpl.clearAccrual() called with Start Date: " + adminForm.getStartDate()); 070 adminForm.setStartDate(""); 071 } 072 if (StringUtils.isNotBlank(adminForm.getEndDate())) { 073 LOG.debug("AccrualServiceImpl.clearAccrual() called with End Date: " + adminForm.getEndDate()); 074 adminForm.setEndDate(""); 075 } 076 077 return mapping.findForward("basic"); 078 } 079 080 }