1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leavecalendar.web;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.joda.time.DateTime;
20 import org.joda.time.format.ISODateTimeFormat;
21 import org.json.simple.JSONValue;
22 import org.kuali.hr.lm.leaveblock.LeaveBlock;
23 import org.kuali.hr.time.assignment.AssignmentDescriptionKey;
24 import org.kuali.hr.time.roles.TkUserRoles;
25 import org.kuali.hr.time.service.base.TkServiceLocator;
26 import org.kuali.hr.time.timeblock.TimeBlock;
27 import org.kuali.hr.time.timeblock.TimeHourDetail;
28 import org.kuali.hr.time.util.TKContext;
29 import org.kuali.hr.time.util.TKUtils;
30 import org.kuali.hr.time.util.TkConstants;
31 import org.kuali.hr.time.workarea.WorkArea;
32 import org.kuali.rice.krad.util.GlobalVariables;
33
34 import java.util.*;
35
36 public class LeaveActionFormUtils {
37
38
39
40
41
42
43
44
45 public static String getLeaveBlocksJson(List<LeaveBlock> leaveBlocks) {
46
47 if (leaveBlocks == null || leaveBlocks.size() == 0) {
48 return "";
49 }
50
51 List<Map<String, Object>> leaveBlockList = new LinkedList<Map<String, Object>>();
52 String timezone = TkServiceLocator.getTimezoneService().getUserTimezone();
53
54 for (LeaveBlock leaveBlock : leaveBlocks) {
55 Map<String, Object> LeaveBlockMap = new LinkedHashMap<String, Object>();
56
57 WorkArea workArea = TkServiceLocator.getWorkAreaService().getWorkArea(leaveBlock.getWorkArea(), leaveBlock.getLeaveDate());
58 String workAreaDesc = workArea == null ? "" : workArea.getDescription();
59
60 Boolean isAnyApprover = TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isAnyApproverActive();
61 LeaveBlockMap.put("isApprover", isAnyApprover);
62
63 LeaveBlockMap.put("documentId", leaveBlock.getDocumentId());
64 LeaveBlockMap.put("title", workAreaDesc);
65 DateTime dtLeaveDate = new DateTime(leaveBlock.getLeaveDate());
66 LeaveBlockMap.put("leaveDate", dtLeaveDate.toString(TkConstants.DT_BASIC_DATE_FORMAT));
67 LeaveBlockMap.put("id", leaveBlock.getLmLeaveBlockId().toString());
68 LeaveBlockMap.put("timezone", timezone);
69 LeaveBlockMap.put("assignment", new AssignmentDescriptionKey(leaveBlock.getJobNumber(), leaveBlock.getWorkArea(), leaveBlock.getTask()).toAssignmentKeyString());
70 LeaveBlockMap.put("lmLeaveBlockId", leaveBlock.getLmLeaveBlockId() != null ? leaveBlock.getLmLeaveBlockId() : "");
71 LeaveBlockMap.put("earnCode", leaveBlock.getEarnCode());
72 LeaveBlockMap.put("leaveAmount", leaveBlock.getLeaveAmount());
73 LeaveBlockMap.put("description", leaveBlock.getDescription());
74 LeaveBlockMap.put("leaveBlockType", leaveBlock.getLeaveBlockType());
75 LeaveBlockMap.put("editable", leaveBlock.isEditable());
76 LeaveBlockMap.put("requestStatus", leaveBlock.getRequestStatus());
77 LeaveBlockMap.put("canTransfer", TkServiceLocator.getPermissionsService().canTransferSSTOUsage(leaveBlock));
78 leaveBlockList.add(LeaveBlockMap);
79 }
80
81
82 return JSONValue.toJSONString(leaveBlockList);
83
84 }
85
86 }