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