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