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.leave.web;
17  
18  import java.io.Serializable;
19  import java.math.BigDecimal;
20  import java.sql.Timestamp;
21  import java.util.Collection;
22  import java.util.Date;
23  import java.util.SortedMap;
24  import java.util.TreeMap;
25  
26  import org.apache.commons.lang.StringUtils;
27  import org.kuali.hr.lm.LMConstants;
28  import org.kuali.hr.lm.leaveblock.LeaveBlock;
29  import org.kuali.hr.lm.workflow.LeaveCalendarDocumentHeader;
30  import org.kuali.hr.time.service.base.TkServiceLocator;
31  import org.kuali.rice.kew.api.KewApiConstants;
32  
33  public class LeaveBlockDisplay implements Serializable {
34  	
35  	private LeaveBlock leaveBlock;
36  	private SortedMap<String, BigDecimal> accrualBalances = new TreeMap<String, BigDecimal>();
37  
38  	public LeaveBlockDisplay(LeaveBlock leaveBlock) {
39  		this.leaveBlock = leaveBlock;
40  	}
41  	
42  	public Date getLeaveDate() {
43  		return leaveBlock.getLeaveDate();
44  	}
45  	
46  	public String getDocumentId() {
47  		return leaveBlock.getDocumentId();
48  	}
49  	
50  	public String getCalendarId() {
51  		return leaveBlock.getCalendarId();
52  	}
53  	
54  	public String getEarnCode() {
55  		return leaveBlock.getEarnCode();
56  	}
57  	
58  	public String getDescription() {
59  		if(leaveBlock.getDescription() == null || leaveBlock.getDescription().trim().isEmpty()) {
60  			return retrieveDescriptionAccordingToLeaveType(leaveBlock.getLeaveBlockType());
61  		}
62  		return leaveBlock.getDescription();
63  	}
64  	
65  	public String getRequestStatus() {
66  		String requestStatus = null;
67  		
68  		if (StringUtils.isNotBlank(leaveBlock.getRequestStatus())) {
69  			requestStatus = LMConstants.REQUEST_STATUS_STRINGS.get(leaveBlock.getRequestStatus());
70  		}
71  		
72  		return requestStatus;
73  	}
74  	
75  	public String getDocumentStatus() {
76  		String documentStatus = null;
77  		
78  		if (StringUtils.isNotBlank(leaveBlock.getDocumentId())) {
79  			LeaveCalendarDocumentHeader lcdh = TkServiceLocator.getLeaveCalendarDocumentHeaderService().getDocumentHeader(leaveBlock.getDocumentId());
80  			if (lcdh != null ) {
81  				documentStatus = KewApiConstants.DOCUMENT_STATUSES.get(lcdh.getDocumentStatus());
82  			}
83  		}
84  		
85  		return documentStatus;
86  	}
87  	
88  	public BigDecimal getLeaveAmount() {
89  		return leaveBlock.getLeaveAmount();
90  	}
91  	
92  	public Timestamp getTimestamp() {
93  		return leaveBlock.getTimestamp();
94  	}
95  	
96  	public String getAssignmentTitle() {
97  		return leaveBlock.getAssignmentTitle();
98  	}
99  	
100 	public String getAccrualCategory() {
101 		return leaveBlock.getAccrualCategory();
102 	}
103 	
104 	public Collection<BigDecimal> getAccrualBalances() {
105 		return accrualBalances.values();
106 	}
107 
108 	public BigDecimal getAccrualBalance(String accrualCategory) {
109 		return accrualBalances.get(accrualCategory);
110 	}
111 
112 	public void setAccrualBalance(String accrualCategory, BigDecimal accrualBalance) {
113 		this.accrualBalances.put(accrualCategory, accrualBalance);
114 	}
115 	
116 	private String retrieveDescriptionAccordingToLeaveType(String leaveType) {
117 		String description = null;
118 		description = LMConstants.LEAVE_BLOCK_TYPE_MAP.get(leaveType);
119 		return description;
120 	}
121 
122 }