1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.approval.web;
17
18 import java.text.SimpleDateFormat;
19 import java.util.*;
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.commons.lang.time.DateUtils;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.hsqldb.lib.StringUtil;
30 import org.json.simple.JSONValue;
31 import org.kuali.hr.lm.workflow.LeaveCalendarDocumentHeader;
32 import org.kuali.hr.time.base.web.TkAction;
33 import org.kuali.hr.time.base.web.ApprovalForm;
34 import org.kuali.hr.time.person.TKPerson;
35 import org.kuali.hr.time.service.base.TkServiceLocator;
36 import org.kuali.hr.time.util.TKContext;
37 import org.kuali.hr.time.util.TKUtils;
38
39 public class LeaveApprovalWSAction extends TkAction {
40
41 public ActionForward getLeaveSummary(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
42 LeaveApprovalWSActionForm laaf = (LeaveApprovalWSActionForm) form;
43 String docId = laaf.getDocumentId();
44 LeaveCalendarDocumentHeader lcdh = TkServiceLocator.getLeaveCalendarDocumentHeaderService().getDocumentHeader(docId);
45 if(lcdh != null) {
46 List<Map<String, Object>> detailMap = TkServiceLocator.getLeaveApprovalService().getLeaveApprovalDetailSections(lcdh);
47
48 String jsonString = JSONValue.toJSONString(detailMap);
49 laaf.setOutputString(jsonString);
50 }
51
52 return mapping.findForward("ws");
53 }
54
55 public ActionForward searchApprovalRows(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
56 LeaveApprovalWSActionForm laaf = (LeaveApprovalWSActionForm) form;
57 List<Map<String, String>> results = new LinkedList<Map<String, String>>();
58 if(StringUtils.isNotEmpty(laaf.getPayBeginDateForSearch())
59 && StringUtils.isNotEmpty(laaf.getPayEndDateForSearch()) ) {
60 Date beginDate = new SimpleDateFormat("MM/dd/yyyy").parse(laaf.getPayBeginDateForSearch());
61 Date endDate = new SimpleDateFormat("MM/dd/yyyy").parse(laaf.getPayEndDateForSearch());
62
63 endDate = DateUtils.addDays(endDate,1);
64 List<String> workAreaList = new ArrayList<String>();
65 if(StringUtil.isEmpty(laaf.getSelectedWorkArea())) {
66 Set<Long> workAreas = TkServiceLocator.getTkRoleService().getWorkAreasForApprover(TKContext.getPrincipalId(), TKUtils.getCurrentDate());
67 for(Long workArea : workAreas) {
68 workAreaList.add(workArea.toString());
69 }
70 } else {
71 workAreaList.add(laaf.getSelectedWorkArea());
72 }
73 List<String> principalIds = TkServiceLocator.getLeaveApprovalService()
74 .getLeavePrincipalIdsWithSearchCriteria(workAreaList, laaf.getSelectedPayCalendarGroup(),
75 new java.sql.Date(endDate.getTime()), new java.sql.Date(beginDate.getTime()), new java.sql.Date(endDate.getTime()));
76
77 List<TKPerson> persons = TkServiceLocator.getPersonService().getPersonCollection(principalIds);
78
79 if (StringUtils.equals(laaf.getSearchField(), ApprovalForm.ORDER_BY_PRINCIPAL)) {
80 for (String id : principalIds) {
81 if(StringUtils.contains(id, laaf.getSearchTerm())) {
82 Map<String, String> labelValue = new HashMap<String, String>();
83 labelValue.put("id", id);
84 labelValue.put("result", id);
85 results.add(labelValue);
86 }
87 }
88 } else if (StringUtils.equals(laaf.getSearchField(), ApprovalForm.ORDER_BY_DOCID)) {
89 Map<String, LeaveCalendarDocumentHeader> principalDocumentHeaders =
90 TkServiceLocator.getLeaveApprovalService().getPrincipalDocumehtHeader(persons, beginDate, endDate);
91
92 for (Map.Entry<String,LeaveCalendarDocumentHeader> entry : principalDocumentHeaders.entrySet()) {
93 if (StringUtils.contains(entry.getValue().getDocumentId(), laaf.getSearchTerm())) {
94 Map<String, String> labelValue = new HashMap<String, String>();
95
96
97 labelValue.put("id", entry.getValue().getDocumentId());
98 labelValue.put("result", entry.getValue().getPrincipalId());
99 results.add(labelValue);
100 }
101 }
102 }
103 }
104
105 laaf.setOutputString(JSONValue.toJSONString(results));
106
107 return mapping.findForward("ws");
108 }
109 }