001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.lm.leaveSummary;
017
018 import java.util.ArrayList;
019 import java.util.HashMap;
020 import java.util.List;
021 import java.util.Map;
022
023 import org.apache.commons.lang3.StringUtils;
024 import org.json.simple.JSONValue;
025
026 public class LeaveSummary {
027 private List<LeaveSummaryRow> leaveSummaryRows = new ArrayList<LeaveSummaryRow>();
028 private String ytdDatesString;
029 private String pendingDatesString;
030 private String note;
031 private List<String> approvalHeaders = new ArrayList<String>();
032
033 public LeaveSummary(LeaveSummary leaveSummary) {
034 leaveSummaryRows = leaveSummary.leaveSummaryRows;
035 ytdDatesString = leaveSummary.ytdDatesString;
036 pendingDatesString = leaveSummary.pendingDatesString;
037 note = leaveSummary.note;
038 approvalHeaders = leaveSummary.approvalHeaders;
039 }
040
041 public LeaveSummary() {
042 // TODO Auto-generated constructor stub
043 }
044
045 public List<LeaveSummaryRow> getLeaveSummaryRows() {
046 return leaveSummaryRows;
047 }
048
049 public LeaveSummaryRow getLeaveSummaryRowForAccrualCtgy(String accrualCategory) {
050 for (LeaveSummaryRow row : getLeaveSummaryRows()) {
051 if (StringUtils.equals(row.getAccrualCategory(), accrualCategory)) {
052 return row;
053 }
054 }
055 return null;
056 }
057
058 public void setLeaveSummaryRows(List<LeaveSummaryRow> leaveSummaryRows) {
059 this.leaveSummaryRows = leaveSummaryRows;
060 }
061
062 public String getYtdDatesString() {
063 return ytdDatesString;
064 }
065
066 public void setYtdDatesString(String ytdDatesString) {
067 this.ytdDatesString = ytdDatesString;
068 }
069
070 public String getPendingDatesString() {
071 return pendingDatesString;
072 }
073
074 public void setPendingDatesString(String pendingDatesString) {
075 this.pendingDatesString = pendingDatesString;
076 }
077
078 public String toJsonString() {
079 List<Map<String, Object>> acSections = new ArrayList<Map<String, Object>>();
080 for(LeaveSummaryRow lsr : this.leaveSummaryRows) {
081 Map<String, Object> acs = new HashMap<String, Object>();
082
083 acs.put("accrualCategory", lsr.getAccrualCategory());
084 acs.put("periodUsage", lsr.getPendingLeaveRequests());
085 acs.put("available", lsr.getLeaveBalance());
086 acSections.add(acs);
087 }
088 return JSONValue.toJSONString(acSections);
089 }
090
091 public List<String> getApprovalHeaders() {
092 return approvalHeaders;
093 }
094
095 public void setApprovalHeaders(List<String> approvalHeaders) {
096 this.approvalHeaders = approvalHeaders;
097 }
098
099 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 }