1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.calendar.web;
17
18 import java.util.LinkedHashMap;
19 import java.util.LinkedList;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.joda.time.DateTime;
24 import org.json.simple.JSONValue;
25 import org.kuali.kpme.core.assignment.AssignmentDescriptionKey;
26 import org.kuali.kpme.core.service.HrServiceLocator;
27 import org.kuali.kpme.core.util.HrConstants;
28 import org.kuali.kpme.core.util.HrContext;
29 import org.kuali.kpme.core.workarea.WorkArea;
30 import org.kuali.kpme.tklm.common.TkConstants;
31 import org.kuali.kpme.tklm.leave.block.LeaveBlock;
32 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
33
34 public class LeaveActionFormUtils {
35
36
37
38
39
40
41
42
43 public static String getLeaveBlocksJson(List<LeaveBlock> leaveBlocks) {
44
45 if (leaveBlocks == null || leaveBlocks.size() == 0) {
46 return "";
47 }
48
49 List<Map<String, Object>> leaveBlockList = new LinkedList<Map<String, Object>>();
50 String timezone = HrServiceLocator.getTimezoneService().getUserTimezone();
51
52 for (LeaveBlock leaveBlock : leaveBlocks) {
53 Map<String, Object> LeaveBlockMap = new LinkedHashMap<String, Object>();
54
55 if(leaveBlock.getBeginTimestamp() != null && leaveBlock.getEndTimestamp() != null) {
56 DateTime start = leaveBlock.getBeginDateTime();
57 DateTime end = leaveBlock.getEndDateTime();
58 LeaveBlockMap.put("startTimeHourMinute", start.toString(TkConstants.DT_BASIC_TIME_FORMAT));
59 LeaveBlockMap.put("endTimeHourMinute", end.toString(TkConstants.DT_BASIC_TIME_FORMAT));
60 LeaveBlockMap.put("startTime", start.toString(TkConstants.DT_MILITARY_TIME_FORMAT));
61 LeaveBlockMap.put("endTime", end.toString(TkConstants.DT_MILITARY_TIME_FORMAT));
62 }
63
64 WorkArea workArea = HrServiceLocator.getWorkAreaService().getWorkAreaWithoutRoles(leaveBlock.getWorkArea(), leaveBlock.getLeaveLocalDate());
65 String workAreaDesc = workArea == null ? "" : workArea.getDescription();
66
67 Boolean getAnyApprover = HrContext.isAnyApprover();
68 LeaveBlockMap.put("isApprover", getAnyApprover);
69
70 LeaveBlockMap.put("documentId", leaveBlock.getDocumentId());
71 LeaveBlockMap.put("title", workAreaDesc);
72 DateTime dtLeaveDate = leaveBlock.getLeaveLocalDate().toDateTimeAtStartOfDay();
73 LeaveBlockMap.put("leaveDate", dtLeaveDate.toString(HrConstants.DT_BASIC_DATE_FORMAT));
74
75 LeaveBlockMap.put("id", leaveBlock.getLmLeaveBlockId().toString());
76 LeaveBlockMap.put("timezone", timezone);
77 LeaveBlockMap.put("assignment", new AssignmentDescriptionKey(leaveBlock.getJobNumber(), leaveBlock.getWorkArea(), leaveBlock.getTask()).toAssignmentKeyString());
78 LeaveBlockMap.put("lmLeaveBlockId", leaveBlock.getLmLeaveBlockId() != null ? leaveBlock.getLmLeaveBlockId() : "");
79 LeaveBlockMap.put("earnCode", leaveBlock.getEarnCode());
80 LeaveBlockMap.put("leaveAmount", leaveBlock.getLeaveAmount());
81 LeaveBlockMap.put("description", leaveBlock.getDescription());
82 LeaveBlockMap.put("leaveBlockType", leaveBlock.getLeaveBlockType());
83 LeaveBlockMap.put("editable", leaveBlock.isEditable());
84 LeaveBlockMap.put("requestStatus", leaveBlock.getRequestStatus());
85 LeaveBlockMap.put("canTransfer", LmServiceLocator.getLMPermissionService().canTransferSSTOUsage(leaveBlock));
86 leaveBlockList.add(LeaveBlockMap);
87 }
88
89
90 return JSONValue.toJSONString(leaveBlockList);
91
92 }
93
94 }