1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.summary;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.json.simple.JSONValue;
26 import org.kuali.kpme.tklm.api.leave.summary.LeaveSummaryContract;
27
28 public class LeaveSummary implements Serializable, LeaveSummaryContract {
29
30 private static final long serialVersionUID = -2080172473960132754L;
31 private List<LeaveSummaryRow> leaveSummaryRows = new ArrayList<LeaveSummaryRow>();
32 private String ytdDatesString;
33 private String pendingDatesString;
34 private String note;
35 private boolean usageLimit;
36 private List<String> approvalHeaders = new ArrayList<String>();
37
38 public LeaveSummary(LeaveSummary leaveSummary) {
39 leaveSummaryRows = leaveSummary.leaveSummaryRows;
40 ytdDatesString = leaveSummary.ytdDatesString;
41 pendingDatesString = leaveSummary.pendingDatesString;
42 note = leaveSummary.note;
43 approvalHeaders = leaveSummary.approvalHeaders;
44 }
45
46 public LeaveSummary() {
47
48 }
49
50 public List<LeaveSummaryRow> getLeaveSummaryRows() {
51 return leaveSummaryRows;
52 }
53
54 public LeaveSummaryRow getLeaveSummaryRowForAccrualCtgy(String accrualCategory) {
55 for (LeaveSummaryRow row : getLeaveSummaryRows()) {
56 if (StringUtils.equals(row.getAccrualCategory(), accrualCategory)) {
57 return row;
58 }
59 }
60 return null;
61 }
62
63 public void setLeaveSummaryRows(List<LeaveSummaryRow> leaveSummaryRows) {
64 this.leaveSummaryRows = leaveSummaryRows;
65 }
66
67 public String getYtdDatesString() {
68 return ytdDatesString;
69 }
70
71 public void setYtdDatesString(String ytdDatesString) {
72 this.ytdDatesString = ytdDatesString;
73 }
74
75 public String getPendingDatesString() {
76 return pendingDatesString;
77 }
78
79 public void setPendingDatesString(String pendingDatesString) {
80 this.pendingDatesString = pendingDatesString;
81 }
82
83 public String toJsonString() {
84 List<Map<String, Object>> acSections = new ArrayList<Map<String, Object>>();
85 for(LeaveSummaryRow lsr : this.leaveSummaryRows) {
86 Map<String, Object> acs = new HashMap<String, Object>();
87
88 acs.put("accrualCategory", lsr.getAccrualCategory());
89 acs.put("periodUsage", lsr.getPendingLeaveRequests());
90 acs.put("available", lsr.getLeaveBalance());
91 acSections.add(acs);
92 }
93 return JSONValue.toJSONString(acSections);
94 }
95
96 public List<String> getApprovalHeaders() {
97 return approvalHeaders;
98 }
99
100 public void setApprovalHeaders(List<String> approvalHeaders) {
101 this.approvalHeaders = approvalHeaders;
102 }
103
104 public LeaveSummaryRow getLeaveSummaryRowForAccrualCategory(
105 String accrualCategoryId) {
106 for(LeaveSummaryRow lsr : leaveSummaryRows) {
107 if(StringUtils.equals(lsr.getAccrualCategoryId(),accrualCategoryId)) {
108 return lsr;
109 }
110 }
111 return null;
112 }
113
114 public String getNote() {
115 return note == null ? "" : note;
116 }
117
118 public void setNote(String note) {
119 this.note = note;
120 }
121
122 public boolean isUsageLimit() {
123 return usageLimit;
124 }
125
126 public void setUsageLimit(boolean usageLimit) {
127 this.usageLimit = usageLimit;
128 }
129
130
131 }