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