001    /**
002     * Copyright 2004-2014 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.kpme.tklm.leave.block.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.kpme.core.util.HrConstants;
028    import org.kuali.kpme.tklm.api.leave.block.web.LeaveBlockDisplayContract;
029    import org.kuali.kpme.tklm.common.LMConstants;
030    import org.kuali.kpme.tklm.leave.block.LeaveBlock;
031    import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
032    import org.kuali.kpme.tklm.leave.workflow.LeaveCalendarDocumentHeader;
033    import org.kuali.rice.kew.api.KewApiConstants;
034    
035    public class LeaveBlockDisplay implements Serializable, LeaveBlockDisplayContract {
036    
037            private static final long serialVersionUID = -783887582238022366L;
038            private LeaveBlock leaveBlock;
039            private SortedMap<String, BigDecimal> accrualBalances = new TreeMap<String, BigDecimal>();
040    
041            public LeaveBlockDisplay(LeaveBlock leaveBlock) {
042                    this.leaveBlock = leaveBlock;
043            }
044            
045            public Date getLeaveDate() {
046                    return leaveBlock.getLeaveDate();
047            }
048            
049            public String getDocumentId() {
050                    return leaveBlock.getDocumentId();
051            }
052            
053            public String getCalendarId() {
054                    return leaveBlock.getCalendarId();
055            }
056            
057            public String getEarnCode() {
058                    return leaveBlock.getEarnCode();
059            }
060            
061            public String getDescription() {
062                    if(leaveBlock.getDescription() == null || leaveBlock.getDescription().trim().isEmpty()) {
063                            return retrieveDescriptionAccordingToLeaveType(leaveBlock.getLeaveBlockType());
064                    }
065                    return leaveBlock.getDescription();
066            }
067            
068            public String getRequestStatus() {
069                    String requestStatus = null;
070                    
071                    if (StringUtils.isNotBlank(leaveBlock.getRequestStatus())) {
072                            requestStatus = HrConstants.REQUEST_STATUS_STRINGS.get(leaveBlock.getRequestStatus());
073                    }
074                    
075                    return requestStatus;
076            }
077            
078            public String getDocumentStatus() {
079                    String documentStatus = null;
080                    
081                    if (StringUtils.isNotBlank(leaveBlock.getDocumentId())) {
082                            LeaveCalendarDocumentHeader lcdh = LmServiceLocator.getLeaveCalendarDocumentHeaderService().getDocumentHeader(leaveBlock.getDocumentId());
083                            if (lcdh != null ) {
084                                    documentStatus = KewApiConstants.DOCUMENT_STATUSES.get(lcdh.getDocumentStatus());
085                            }
086                    }
087                    
088                    return documentStatus;
089            }
090            
091            public BigDecimal getLeaveAmount() {
092                    return leaveBlock.getLeaveAmount();
093            }
094            
095            public Timestamp getTimestamp() {
096                    return leaveBlock.getTimestamp();
097            }
098            
099            public String getAssignmentTitle() {
100                    return leaveBlock.getAssignmentTitle();
101            }
102            
103            public String getAccrualCategory() {
104                    return leaveBlock.getAccrualCategory();
105            }
106            
107            public Collection<BigDecimal> getAccrualBalances() {
108                    return accrualBalances.values();
109            }
110    
111            public BigDecimal getAccrualBalance(String accrualCategory) {
112                    return accrualBalances.get(accrualCategory);
113            }
114    
115            public void setAccrualBalance(String accrualCategory, BigDecimal accrualBalance) {
116                    this.accrualBalances.put(accrualCategory, accrualBalance);
117            }
118            
119            private String retrieveDescriptionAccordingToLeaveType(String leaveType) {
120                    String description = null;
121                    description = LMConstants.LEAVE_BLOCK_TYPE_MAP.get(leaveType);
122                    return description;
123            }
124    
125    }