1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.approval.web;
17
18 import java.text.SimpleDateFormat;
19 import java.util.Date;
20 import java.util.HashMap;
21 import java.util.LinkedList;
22 import java.util.List;
23 import java.util.Map;
24
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.apache.commons.lang.StringUtils;
29 import org.apache.log4j.Logger;
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionForward;
32 import org.apache.struts.action.ActionMapping;
33 import org.json.simple.JSONValue;
34 import org.kuali.hr.time.base.web.TkAction;
35 import org.kuali.hr.time.base.web.ApprovalForm;
36 import org.kuali.hr.time.person.TKPerson;
37 import org.kuali.hr.time.service.base.TkServiceLocator;
38 import org.kuali.hr.time.timesheet.TimesheetDocument;
39 import org.kuali.hr.time.timesummary.TimeSummary;
40 import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
41
42 public class TimeApprovalWSAction extends TkAction {
43
44 private static final Logger LOG = Logger.getLogger(TimeApprovalWSAction.class);
45
46
47
48
49
50
51
52 public ActionForward searchApprovalRows(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
53 TimeApprovalActionForm taaf = (TimeApprovalActionForm) form;
54 List<Map<String, String>> results = new LinkedList<Map<String, String>>();
55 if(StringUtils.isNotEmpty(taaf.getPayBeginDateForSearch())
56 && StringUtils.isNotEmpty(taaf.getPayEndDateForSearch()) ) {
57 Date beginDate = new SimpleDateFormat("MM/dd/yyyy").parse(taaf.getPayBeginDateForSearch());
58 Date endDate = new SimpleDateFormat("MM/dd/yyyy").parse(taaf.getPayEndDateForSearch());
59
60 List<String> principalIds = TkServiceLocator.getTimeApproveService().getPrincipalIdsByDeptWorkAreaRolename(taaf.getRoleName(), taaf.getSelectedDept(), taaf.getSelectedWorkArea(), new java.sql.Date(beginDate.getTime()), new java.sql.Date(endDate.getTime()), taaf.getSelectedPayCalendarGroup());
61 List<TKPerson> persons = TkServiceLocator.getPersonService().getPersonCollection(principalIds);
62
63 if (StringUtils.equals(taaf.getSearchField(), ApprovalForm.ORDER_BY_PRINCIPAL)) {
64 for (String id : principalIds) {
65 if(StringUtils.contains(id, taaf.getSearchTerm())) {
66 Map<String, String> labelValue = new HashMap<String, String>();
67 labelValue.put("id", id);
68 labelValue.put("result", id);
69 results.add(labelValue);
70 }
71 }
72 } else if (StringUtils.equals(taaf.getSearchField(), ApprovalForm.ORDER_BY_DOCID)) {
73 Map<String, TimesheetDocumentHeader> principalDocumentHeaders =
74 TkServiceLocator.getTimeApproveService().getPrincipalDocumehtHeader(persons, beginDate, endDate);
75
76 for (Map.Entry<String,TimesheetDocumentHeader> entry : principalDocumentHeaders.entrySet()) {
77 if (StringUtils.contains(entry.getValue().getDocumentId(), taaf.getSearchTerm())) {
78 Map<String, String> labelValue = new HashMap<String, String>();
79 labelValue.put("id", entry.getValue().getDocumentId() + " (" + entry.getValue().getPrincipalId() + ")");
80 labelValue.put("result", entry.getValue().getPrincipalId());
81 results.add(labelValue);
82 }
83 }
84 }
85 }
86
87 taaf.setOutputString(JSONValue.toJSONString(results));
88 return mapping.findForward("ws");
89 }
90
91 public ActionForward getTimeSummary(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
92 TimeApprovalActionForm taaf = (TimeApprovalActionForm) form;
93 TimesheetDocument td = TkServiceLocator.getTimesheetService().getTimesheetDocument(taaf.getDocumentId());
94 TimeSummary ts = TkServiceLocator.getTimeSummaryService().getTimeSummary(td);
95
96 taaf.setOutputString(ts.toJsonString());
97 return mapping.findForward("ws");
98 }
99
100 }