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 if(leaveBlock.getBeginTimestamp() != null && leaveBlock.getEndTimestamp() != null) {
58 DateTime start = new DateTime(leaveBlock.getBeginTimestamp().getTime());
59 DateTime end = new DateTime(leaveBlock.getEndTimestamp().getTime());
60 LeaveBlockMap.put("startTimeHourMinute", start.toString(TkConstants.DT_BASIC_TIME_FORMAT));
61 LeaveBlockMap.put("endTimeHourMinute", end.toString(TkConstants.DT_BASIC_TIME_FORMAT));
62 LeaveBlockMap.put("startTime", start.toString(TkConstants.DT_MILITARY_TIME_FORMAT));
63 LeaveBlockMap.put("endTime", end.toString(TkConstants.DT_MILITARY_TIME_FORMAT));
64 }
65
66 WorkArea workArea = TkServiceLocator.getWorkAreaService().getWorkArea(leaveBlock.getWorkArea(), leaveBlock.getLeaveDate());
67 String workAreaDesc = workArea == null ? "" : workArea.getDescription();
68
69 Boolean isAnyApprover = TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isAnyApproverActive();
70 LeaveBlockMap.put("isApprover", isAnyApprover);
71
72 LeaveBlockMap.put("documentId", leaveBlock.getDocumentId());
73 LeaveBlockMap.put("title", workAreaDesc);
74 DateTime dtLeaveDate = new DateTime(leaveBlock.getLeaveDate());
75 LeaveBlockMap.put("leaveDate", dtLeaveDate.toString(TkConstants.DT_BASIC_DATE_FORMAT));
76
77 LeaveBlockMap.put("id", leaveBlock.getLmLeaveBlockId().toString());
78 LeaveBlockMap.put("timezone", timezone);
79 LeaveBlockMap.put("assignment", new AssignmentDescriptionKey(leaveBlock.getJobNumber(), leaveBlock.getWorkArea(), leaveBlock.getTask()).toAssignmentKeyString());
80 LeaveBlockMap.put("lmLeaveBlockId", leaveBlock.getLmLeaveBlockId() != null ? leaveBlock.getLmLeaveBlockId() : "");
81 LeaveBlockMap.put("earnCode", leaveBlock.getEarnCode());
82 LeaveBlockMap.put("leaveAmount", leaveBlock.getLeaveAmount());
83 LeaveBlockMap.put("description", leaveBlock.getDescription());
84 LeaveBlockMap.put("leaveBlockType", leaveBlock.getLeaveBlockType());
85 LeaveBlockMap.put("editable", leaveBlock.isEditable());
86 LeaveBlockMap.put("requestStatus", leaveBlock.getRequestStatus());
87 LeaveBlockMap.put("canTransfer", TkServiceLocator.getPermissionsService().canTransferSSTOUsage(leaveBlock));
88 leaveBlockList.add(LeaveBlockMap);
89 }
90
91
92 return JSONValue.toJSONString(leaveBlockList);
93
94 }
95
96 }