View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.lm.leaveSummary;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.apache.commons.lang3.StringUtils;
24  import org.json.simple.JSONValue;
25  
26  public class LeaveSummary {
27  	private List<LeaveSummaryRow> leaveSummaryRows = new ArrayList<LeaveSummaryRow>();
28  	private String ytdDatesString;
29  	private String pendingDatesString;
30      private String note;
31  	private List<String> approvalHeaders = new ArrayList<String>();
32  
33  	public LeaveSummary(LeaveSummary leaveSummary) {
34  		leaveSummaryRows = leaveSummary.leaveSummaryRows;
35  		ytdDatesString = leaveSummary.ytdDatesString;
36  		pendingDatesString = leaveSummary.pendingDatesString;
37  		note = leaveSummary.note;
38  		approvalHeaders = leaveSummary.approvalHeaders;
39  	}
40  
41  	public LeaveSummary() {
42  		// TODO Auto-generated constructor stub
43  	}
44  
45  	public List<LeaveSummaryRow> getLeaveSummaryRows() {
46  		return leaveSummaryRows;
47  	}
48  
49      public LeaveSummaryRow getLeaveSummaryRowForAccrualCtgy(String accrualCategory) {
50          for (LeaveSummaryRow row : getLeaveSummaryRows()) {
51              if (StringUtils.equals(row.getAccrualCategory(), accrualCategory)) {
52                  return row;
53              }
54          }
55          return null;
56      }
57  
58  	public void setLeaveSummaryRows(List<LeaveSummaryRow> leaveSummaryRows) {
59  		this.leaveSummaryRows = leaveSummaryRows;
60  	}
61  
62  	public String getYtdDatesString() {
63  		return ytdDatesString;
64  	}
65  
66  	public void setYtdDatesString(String ytdDatesString) {
67  		this.ytdDatesString = ytdDatesString;
68  	}
69  
70  	public String getPendingDatesString() {
71  		return pendingDatesString;
72  	}
73  
74  	public void setPendingDatesString(String pendingDatesString) {
75  		this.pendingDatesString = pendingDatesString;
76  	}
77  
78  	 public String toJsonString() {
79          List<Map<String, Object>> acSections = new ArrayList<Map<String, Object>>();
80          for(LeaveSummaryRow lsr : this.leaveSummaryRows) {
81          	 Map<String, Object> acs = new HashMap<String, Object>();
82          	 
83          	 acs.put("accrualCategory", lsr.getAccrualCategory());
84          	 acs.put("periodUsage", lsr.getPendingLeaveRequests());
85          	 acs.put("available", lsr.getLeaveBalance());
86          	 acSections.add(acs);
87          }
88          return JSONValue.toJSONString(acSections);
89  	}
90  
91  	public List<String> getApprovalHeaders() {
92  		return approvalHeaders;
93  	}
94  
95  	public void setApprovalHeaders(List<String> approvalHeaders) {
96  		this.approvalHeaders = approvalHeaders;
97  	}
98  
99  	public LeaveSummaryRow getLeaveSummaryRowForAccrualCategory(
100 			String accrualCategoryId) {
101 		for(LeaveSummaryRow lsr : leaveSummaryRows) {
102 			if(StringUtils.equals(lsr.getAccrualCategoryId(),accrualCategoryId)) {
103 				return lsr;
104 			}
105 		}
106 		return null;
107 	}
108 
109     public String getNote() {
110         return note == null ? "" : note;
111     }
112 
113     public void setNote(String note) {
114         this.note = note;
115     }
116 	
117 	
118 	
119 }