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.io.Serializable; 019 import java.util.ArrayList; 020 import java.util.HashMap; 021 import java.util.List; 022 import java.util.Map; 023 024 import org.apache.commons.lang3.StringUtils; 025 import org.json.simple.JSONValue; 026 027 public class LeaveSummary implements Serializable { 028 private List<LeaveSummaryRow> leaveSummaryRows = new ArrayList<LeaveSummaryRow>(); 029 private String ytdDatesString; 030 private String pendingDatesString; 031 private String note; 032 private List<String> approvalHeaders = new ArrayList<String>(); 033 034 public LeaveSummary(LeaveSummary leaveSummary) { 035 leaveSummaryRows = leaveSummary.leaveSummaryRows; 036 ytdDatesString = leaveSummary.ytdDatesString; 037 pendingDatesString = leaveSummary.pendingDatesString; 038 note = leaveSummary.note; 039 approvalHeaders = leaveSummary.approvalHeaders; 040 } 041 042 public LeaveSummary() { 043 // TODO Auto-generated constructor stub 044 } 045 046 public List<LeaveSummaryRow> getLeaveSummaryRows() { 047 return leaveSummaryRows; 048 } 049 050 public LeaveSummaryRow getLeaveSummaryRowForAccrualCtgy(String accrualCategory) { 051 for (LeaveSummaryRow row : getLeaveSummaryRows()) { 052 if (StringUtils.equals(row.getAccrualCategory(), accrualCategory)) { 053 return row; 054 } 055 } 056 return null; 057 } 058 059 public void setLeaveSummaryRows(List<LeaveSummaryRow> leaveSummaryRows) { 060 this.leaveSummaryRows = leaveSummaryRows; 061 } 062 063 public String getYtdDatesString() { 064 return ytdDatesString; 065 } 066 067 public void setYtdDatesString(String ytdDatesString) { 068 this.ytdDatesString = ytdDatesString; 069 } 070 071 public String getPendingDatesString() { 072 return pendingDatesString; 073 } 074 075 public void setPendingDatesString(String pendingDatesString) { 076 this.pendingDatesString = pendingDatesString; 077 } 078 079 public String toJsonString() { 080 List<Map<String, Object>> acSections = new ArrayList<Map<String, Object>>(); 081 for(LeaveSummaryRow lsr : this.leaveSummaryRows) { 082 Map<String, Object> acs = new HashMap<String, Object>(); 083 084 acs.put("accrualCategory", lsr.getAccrualCategory()); 085 acs.put("periodUsage", lsr.getPendingLeaveRequests()); 086 acs.put("available", lsr.getLeaveBalance()); 087 acSections.add(acs); 088 } 089 return JSONValue.toJSONString(acSections); 090 } 091 092 public List<String> getApprovalHeaders() { 093 return approvalHeaders; 094 } 095 096 public void setApprovalHeaders(List<String> approvalHeaders) { 097 this.approvalHeaders = approvalHeaders; 098 } 099 100 public LeaveSummaryRow getLeaveSummaryRowForAccrualCategory( 101 String accrualCategoryId) { 102 for(LeaveSummaryRow lsr : leaveSummaryRows) { 103 if(StringUtils.equals(lsr.getAccrualCategoryId(),accrualCategoryId)) { 104 return lsr; 105 } 106 } 107 return null; 108 } 109 110 public String getNote() { 111 return note == null ? "" : note; 112 } 113 114 public void setNote(String note) { 115 this.note = note; 116 } 117 118 119 120 }