View Javadoc
1   /**
2    * Copyright 2004-2014 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.kpme.tklm.leave.block.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.kpme.core.util.HrConstants;
28  import org.kuali.kpme.tklm.api.leave.block.LeaveBlock;
29  import org.kuali.kpme.tklm.api.leave.block.LeaveBlockDisplayContract;
30  import org.kuali.kpme.tklm.common.LMConstants;
31  import org.kuali.kpme.tklm.leave.block.LeaveBlockBo;
32  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
33  import org.kuali.kpme.tklm.leave.workflow.LeaveCalendarDocumentHeader;
34  import org.kuali.rice.kew.api.KewApiConstants;
35  
36  public class LeaveBlockDisplay implements Serializable, LeaveBlockDisplayContract {
37  
38  	private static final long serialVersionUID = -783887582238022366L;
39  	private LeaveBlock leaveBlock;
40  	private SortedMap<String, BigDecimal> accrualBalances = new TreeMap<String, BigDecimal>();
41  
42  	public LeaveBlockDisplay(LeaveBlock leaveBlock) {
43  		this.leaveBlock = leaveBlock;
44  	}
45  	
46  	public Date getLeaveDate() {
47  		return leaveBlock.getLeaveDateTime().toDate();
48  	}
49  	
50  	public String getDocumentId() {
51  		return leaveBlock.getDocumentId();
52  	}
53  	
54  	public String getCalendarId() {
55  		return leaveBlock.getCalendarId();
56  	}
57  	
58  	public String getEarnCode() {
59  		return leaveBlock.getEarnCode();
60  	}
61  	
62  	public String getDescription() {
63  		if(leaveBlock.getDescription() == null || leaveBlock.getDescription().trim().isEmpty()) {
64  			return retrieveDescriptionAccordingToLeaveType(leaveBlock.getLeaveBlockType());
65  		}
66  		return leaveBlock.getDescription();
67  	}
68  	
69  	public String getRequestStatus() {
70  		String requestStatus = null;
71  		
72  		if (StringUtils.isNotBlank(leaveBlock.getRequestStatus())) {
73  			requestStatus = HrConstants.REQUEST_STATUS_STRINGS.get(leaveBlock.getRequestStatus());
74  		}
75  		
76  		return requestStatus;
77  	}
78  	
79  	public String getDocumentStatus() {
80  		String documentStatus = null;
81  		
82  		if (StringUtils.isNotBlank(leaveBlock.getDocumentId())) {
83  			LeaveCalendarDocumentHeader lcdh = LmServiceLocator.getLeaveCalendarDocumentHeaderService().getDocumentHeader(leaveBlock.getDocumentId());
84  			if (lcdh != null ) {
85  				documentStatus = KewApiConstants.DOCUMENT_STATUSES.get(lcdh.getDocumentStatus());
86  			}
87  		}
88  		
89  		return documentStatus;
90  	}
91  	
92  	public BigDecimal getLeaveAmount() {
93  		return leaveBlock.getLeaveAmount();
94  	}
95  	
96  	public Timestamp getTimestamp() {
97  		return new Timestamp(leaveBlock.getCreateTime().getMillis());
98  	}
99  	
100 	public String getAssignmentTitle() {
101 		return leaveBlock.getAssignmentTitle();
102 	}
103 	
104 	public String getAccrualCategory() {
105 		return leaveBlock.getAccrualCategory();
106 	}
107 	
108 	public Collection<BigDecimal> getAccrualBalances() {
109 		return accrualBalances.values();
110 	}
111 
112 	public BigDecimal getAccrualBalance(String accrualCategory) {
113 		return accrualBalances.get(accrualCategory);
114 	}
115 
116 	public void setAccrualBalance(String accrualCategory, BigDecimal accrualBalance) {
117 		this.accrualBalances.put(accrualCategory, accrualBalance);
118 	}
119 	
120 	private String retrieveDescriptionAccordingToLeaveType(String leaveType) {
121 		String description = null;
122 		description = LMConstants.LEAVE_BLOCK_TYPE_MAP.get(leaveType);
123 		return description;
124 	}
125 
126 }