1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.log4j.Logger;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionForward;
25 import org.apache.struts.action.ActionMapping;
26 import org.joda.time.DateTime;
27 import org.kuali.kpme.core.util.TKUtils;
28 import org.kuali.kpme.core.web.KPMEAction;
29 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
30 import org.kuali.rice.kim.api.identity.principal.Principal;
31 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
32
33 public class CalculateLeaveAccrualsAction extends KPMEAction {
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 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(calculateLeaveAccrualsForm.getPrincipalName());
41 if (principal != null) {
42 if (StringUtils.isNotBlank(calculateLeaveAccrualsForm.getStartDate()) && StringUtils.isNotBlank(calculateLeaveAccrualsForm.getEndDate())) {
43 DateTime startDate = TKUtils.formatDateTimeString(calculateLeaveAccrualsForm.getStartDate());
44 DateTime endDate = TKUtils.formatDateTimeString(calculateLeaveAccrualsForm.getEndDate());
45
46 LOG.debug("AccrualServiceImpl.runAccrual() called with Principal: " + principal.getPrincipalName() + " Start: " + startDate.toString() + " End: " + endDate.toString());
47 LmServiceLocator.getLeaveAccrualService().runAccrual(principal.getPrincipalId(), startDate, endDate, true);
48 } else {
49 LOG.debug("AccrualServiceImpl.runAccrual() called with Principal: " + principal.getPrincipalName());
50 LmServiceLocator.getLeaveAccrualService().runAccrual(principal.getPrincipalId());
51 }
52 }
53 return mapping.findForward("basic");
54 }
55
56 public ActionForward clearAccruals(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
57 CalculateLeaveAccrualsForm adminForm = (CalculateLeaveAccrualsForm) form;
58
59 if (StringUtils.isNotBlank(adminForm.getPrincipalName())) {
60 LOG.debug("AccrualServiceImpl.clearAccrual() called with Principal: " + adminForm.getPrincipalName());
61 adminForm.setPrincipalName("");
62 }
63 if (StringUtils.isNotBlank(adminForm.getStartDate())) {
64 LOG.debug("AccrualServiceImpl.clearAccrual() called with Start Date: " + adminForm.getStartDate());
65 adminForm.setStartDate("");
66 }
67 if (StringUtils.isNotBlank(adminForm.getEndDate())) {
68 LOG.debug("AccrualServiceImpl.clearAccrual() called with End Date: " + adminForm.getEndDate());
69 adminForm.setEndDate("");
70 }
71
72 return mapping.findForward("basic");
73 }
74
75 }