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.leave.web;
017    
018    import java.io.Serializable;
019    import java.math.BigDecimal;
020    import java.sql.Timestamp;
021    import java.util.Collection;
022    import java.util.Date;
023    import java.util.SortedMap;
024    import java.util.TreeMap;
025    
026    import org.apache.commons.lang.StringUtils;
027    import org.kuali.hr.lm.LMConstants;
028    import org.kuali.hr.lm.leaveblock.LeaveBlock;
029    import org.kuali.hr.lm.workflow.LeaveCalendarDocumentHeader;
030    import org.kuali.hr.time.service.base.TkServiceLocator;
031    import org.kuali.rice.kew.api.KewApiConstants;
032    
033    public class LeaveBlockDisplay implements Serializable {
034            
035            private LeaveBlock leaveBlock;
036            private SortedMap<String, BigDecimal> accrualBalances = new TreeMap<String, BigDecimal>();
037    
038            public LeaveBlockDisplay(LeaveBlock leaveBlock) {
039                    this.leaveBlock = leaveBlock;
040            }
041            
042            public Date getLeaveDate() {
043                    return leaveBlock.getLeaveDate();
044            }
045            
046            public String getDocumentId() {
047                    return leaveBlock.getDocumentId();
048            }
049            
050            public String getCalendarId() {
051                    return leaveBlock.getCalendarId();
052            }
053            
054            public String getEarnCode() {
055                    return leaveBlock.getEarnCode();
056            }
057            
058            public String getDescription() {
059                    if(leaveBlock.getDescription() == null || leaveBlock.getDescription().trim().isEmpty()) {
060                            return retrieveDescriptionAccordingToLeaveType(leaveBlock.getLeaveBlockType());
061                    }
062                    return leaveBlock.getDescription();
063            }
064            
065            public String getRequestStatus() {
066                    String requestStatus = null;
067                    
068                    if (StringUtils.isNotBlank(leaveBlock.getRequestStatus())) {
069                            requestStatus = LMConstants.REQUEST_STATUS_STRINGS.get(leaveBlock.getRequestStatus());
070                    }
071                    
072                    return requestStatus;
073            }
074            
075            public String getDocumentStatus() {
076                    String documentStatus = null;
077                    
078                    if (StringUtils.isNotBlank(leaveBlock.getDocumentId())) {
079                            LeaveCalendarDocumentHeader lcdh = TkServiceLocator.getLeaveCalendarDocumentHeaderService().getDocumentHeader(leaveBlock.getDocumentId());
080                            if (lcdh != null ) {
081                                    documentStatus = KewApiConstants.DOCUMENT_STATUSES.get(lcdh.getDocumentStatus());
082                            }
083                    }
084                    
085                    return documentStatus;
086            }
087            
088            public BigDecimal getLeaveAmount() {
089                    return leaveBlock.getLeaveAmount();
090            }
091            
092            public Timestamp getTimestamp() {
093                    return leaveBlock.getTimestamp();
094            }
095            
096            public String getAssignmentTitle() {
097                    return leaveBlock.getAssignmentTitle();
098            }
099            
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    }