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.time.approval.web; 017 018 import java.math.BigDecimal; 019 import java.util.ArrayList; 020 import java.util.Date; 021 import java.util.LinkedHashMap; 022 import java.util.List; 023 import java.util.Map; 024 025 import org.apache.commons.lang.StringUtils; 026 import org.kuali.hr.lm.leaveblock.LeaveBlock; 027 import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument; 028 import org.kuali.hr.lm.workflow.LeaveCalendarDocumentHeader; 029 import org.kuali.hr.time.service.base.TkServiceLocator; 030 import org.kuali.hr.time.util.TKContext; 031 import org.kuali.hr.time.util.TkConstants; 032 import org.kuali.rice.kew.api.KewApiConstants; 033 import org.kuali.rice.kew.api.note.Note; 034 import org.kuali.rice.kew.doctype.SecuritySession; 035 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; 036 import org.kuali.rice.kew.service.KEWServiceLocator; 037 import org.kuali.rice.kim.api.identity.Person; 038 import org.kuali.rice.kim.api.services.KimApiServiceLocator; 039 040 public class ApprovalLeaveSummaryRow implements Comparable<ApprovalLeaveSummaryRow> { 041 private String name; 042 private String principalId; 043 private String documentId; 044 private List<String> warnings = new ArrayList<String>(); 045 private String selected = "off"; 046 private String approvalStatus; 047 048 private List<Note> notes = new ArrayList<Note>(); 049 private Boolean moreThanOneCalendar = Boolean.FALSE; 050 private String lastApproveMessage; 051 private List<LeaveBlock> leaveBlockList = new ArrayList<LeaveBlock>(); 052 private Map<Date, Map<String, BigDecimal>> earnCodeLeaveHours = new LinkedHashMap<Date, Map<String, BigDecimal>>(); 053 private Boolean exemptEmployee; 054 055 /** 056 * Is this record ready to be approved? 057 * @return true if a valid TK_APPROVER / TK_PROCESSOR can approve, false otherwise. 058 */ 059 public boolean isApprovable() { 060 boolean isEnroute = StringUtils.equals(getApprovalStatus(), "ENROUTE") ; 061 062 if(isEnroute){ 063 LeaveCalendarDocument doc = TkServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(this.documentId); 064 //is there a pending bt doc? 065 if (!TkServiceLocator.getLeaveCalendarService().isReadyToApprove(doc)) { 066 return false; 067 } 068 DocumentRouteHeaderValue routeHeader = TkServiceLocator.getTimeApproveService().getRouteHeader(this.getDocumentId()); 069 // check if there are any pending calendars are there 070 LeaveCalendarDocumentHeader lcdh = TkServiceLocator.getLeaveCalendarDocumentHeaderService().getMinBeginDatePendingLeaveCalendar(this.principalId); 071 if (lcdh != null){ //if there were any pending document 072 //check to see if it's before the current document. if it is, then this document is not approvable. 073 if (TkServiceLocator.getLeaveCalendarDocumentHeaderService().getDocumentHeader(this.documentId).getBeginDate().compareTo(lcdh.getEndDate()) >= 0){ 074 return false; 075 } 076 } 077 boolean authorized = KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(TKContext.getPrincipalId(), routeHeader, new SecuritySession(TKContext.getPrincipalId())); 078 if(authorized){ 079 List<String> principalsToApprove = KEWServiceLocator.getActionRequestService().getPrincipalIdsWithPendingActionRequestByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, this.getDocumentId()); 080 if(!principalsToApprove.isEmpty() && principalsToApprove.contains(TKContext.getPrincipalId())){ 081 return true; 082 } 083 } 084 } 085 return false; 086 } 087 088 089 public int compareTo(ApprovalLeaveSummaryRow row) { 090 return name.compareToIgnoreCase(row.getName()); 091 } 092 093 public String getName() { 094 return name; 095 } 096 097 public void setName(String name) { 098 this.name = name; 099 } 100 101 public String getPrincipalId() { 102 return principalId; 103 } 104 105 public void setPrincipalId(String principalId) { 106 this.principalId = principalId; 107 } 108 109 public String getUserTargetURLParams() { 110 StringBuffer link = new StringBuffer(); 111 112 link.append("methodToCall=changeTargetPerson"); 113 link.append("&documentId=").append(this.getDocumentId()); 114 Person person = KimApiServiceLocator.getPersonService().getPerson(this.getPrincipalId()); 115 link.append("&principalName=").append(person.getPrincipalName()); 116 117 return link.toString(); 118 } 119 120 public List<LeaveBlock> getLeaveBlockList() { 121 return leaveBlockList; 122 } 123 124 public void setLeaveBlockList(List<LeaveBlock> leaveBlockList) { 125 this.leaveBlockList = leaveBlockList; 126 } 127 128 public String getDocumentId() { 129 return documentId; 130 } 131 132 public void setDocumentId(String documentId) { 133 this.documentId = documentId; 134 } 135 136 public List<String> getWarnings() { 137 return warnings; 138 } 139 140 public void setWarnings(List<String> warnings) { 141 this.warnings = warnings; 142 } 143 144 public String getSelected() { 145 return selected; 146 } 147 148 public void setSelected(String selected) { 149 this.selected = selected; 150 } 151 152 public List<Note> getNotes() { 153 return notes; 154 } 155 156 public void setNotes(List<Note> notes) { 157 this.notes = notes; 158 } 159 160 public String getLastApproveMessage() { 161 return lastApproveMessage; 162 } 163 164 public void setLastApproveMessage(String lastApproveMessage) { 165 this.lastApproveMessage = lastApproveMessage; 166 } 167 168 public String getApprovalStatus() { 169 return approvalStatus; 170 } 171 172 public void setApprovalStatus(String approvalStatus) { 173 this.approvalStatus = approvalStatus; 174 } 175 176 public Map<Date, Map<String, BigDecimal>> getEarnCodeLeaveHours() { 177 return earnCodeLeaveHours; 178 } 179 180 public void setEarnCodeLeaveHours(Map<Date, Map<String, BigDecimal>> earnCodeLeaveHours) { 181 this.earnCodeLeaveHours = earnCodeLeaveHours; 182 } 183 184 public Boolean getMoreThanOneCalendar() { 185 return moreThanOneCalendar; 186 } 187 188 189 public void setMoreThanOneCalendar(Boolean moreThanOneCalendar) { 190 this.moreThanOneCalendar = moreThanOneCalendar; 191 } 192 193 194 public Boolean getExemptEmployee() { 195 if(this.exemptEmployee == null) { 196 this.exemptEmployee = TkServiceLocator.getLeaveApprovalService().isActiveAssignmentFoundOnJobFlsaStatus(this.principalId,TkConstants.FLSA_STATUS_EXEMPT, true); 197 } 198 return exemptEmployee; 199 } 200 201 202 public void setExemptEmployee(Boolean exemptEmployee) { 203 this.exemptEmployee = exemptEmployee; 204 } 205 206 207 }