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.HashMap; 021 import java.util.List; 022 import java.util.Map; 023 import java.util.Set; 024 025 import org.apache.commons.lang.StringUtils; 026 import org.kuali.hr.time.service.base.TkServiceLocator; 027 import org.kuali.hr.time.timeblock.TimeBlock; 028 import org.kuali.hr.time.timesummary.TimeSummary; 029 import org.kuali.hr.time.util.TKContext; 030 import org.kuali.hr.time.util.TkConstants; 031 import org.kuali.rice.kew.api.KewApiConstants; 032 import org.kuali.rice.kew.doctype.SecuritySession; 033 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; 034 import org.kuali.rice.kew.service.KEWServiceLocator; 035 import org.kuali.rice.kim.api.identity.Person; 036 import org.kuali.rice.kim.api.services.KimApiServiceLocator; 037 038 public class ApprovalTimeSummaryRow implements Comparable<ApprovalTimeSummaryRow> { 039 private String name; 040 private List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>(); 041 /** A Map (Assignment key) of Mapped totals (pay label mapping) */ 042 private Map<String, Map<String, BigDecimal>> approverHoursByAssignment; 043 /** A Map (Assignment key) of Mapped totals (pay label mapping) */ 044 private Map<String, Map<String, BigDecimal>> otherHoursByAssignment; 045 /** A String (AssignmentDescriptionKey) to Description mapping for all assignments on this summary row */ 046 private Map<String,String> assignmentDescriptions; // could refactor out to action level call 047 048 private String approvalStatus; 049 private String approvalStatusMessage; 050 private String documentId; 051 private Map<String,BigDecimal> hoursToPayLabelMap = new HashMap<String,BigDecimal>(); 052 private Map<String,BigDecimal> hoursToFlsaPayLabelMap = new HashMap<String,BigDecimal>(); 053 private String clockStatusMessage; 054 private String payCalendarGroup; 055 private List notes = new ArrayList(); 056 private List<String> warnings = new ArrayList<String>(); 057 private Set<String> workAreas; 058 private String principalId; 059 private Boolean clockedInOverThreshold = Boolean.FALSE; 060 private String selected = "off"; 061 private TimeSummary timeSummary; 062 private BigDecimal periodTotal = BigDecimal.ZERO; 063 064 public String getApprovalStatusMessage() { 065 return approvalStatusMessage; 066 } 067 068 public void setApprovalStatusMessage(String approvalStatusMessage) { 069 this.approvalStatusMessage = approvalStatusMessage; 070 } 071 072 public Map<String, String> getAssignmentDescriptions() { 073 return assignmentDescriptions; 074 } 075 076 public void setAssignmentDescriptions(Map<String, String> assignmentDescriptions) { 077 this.assignmentDescriptions = assignmentDescriptions; 078 } 079 080 public Map<String, Map<String, BigDecimal>> getApproverHoursByAssignment() { 081 return approverHoursByAssignment; 082 } 083 084 public void setApproverHoursByAssignment(Map<String, Map<String, BigDecimal>> approverHoursByAssignment) { 085 this.approverHoursByAssignment = approverHoursByAssignment; 086 } 087 088 public Map<String, Map<String, BigDecimal>> getOtherHoursByAssignment() { 089 return otherHoursByAssignment; 090 } 091 092 public void setOtherHoursByAssignment(Map<String, Map<String, BigDecimal>> otherHoursByAssignment) { 093 this.otherHoursByAssignment = otherHoursByAssignment; 094 } 095 096 public String getName() { 097 return name; 098 } 099 public void setName(String name) { 100 this.name = name; 101 } 102 public List<TimeBlock> getLstTimeBlocks() { 103 return lstTimeBlocks; 104 } 105 public void setLstTimeBlocks(List<TimeBlock> lstTimeBlocks) { 106 this.lstTimeBlocks = lstTimeBlocks; 107 } 108 public String getApprovalStatus() { 109 return approvalStatus; 110 } 111 public void setApprovalStatus(String approvalStatus) { 112 this.approvalStatus = approvalStatus; 113 } 114 public void setDocumentId(String documentId) { 115 this.documentId = documentId; 116 } 117 public String getDocumentId() { 118 return documentId; 119 } 120 public void setHoursToPayLabelMap(Map<String,BigDecimal> hoursToPayLabelMap) { 121 this.hoursToPayLabelMap = hoursToPayLabelMap; 122 } 123 public Map<String,BigDecimal> getHoursToPayLabelMap() { 124 return hoursToPayLabelMap; 125 } 126 public void setHoursToFlsaPayLabelMap(Map<String,BigDecimal> hoursToFlsaPayLabelMap) { 127 this.hoursToFlsaPayLabelMap = hoursToFlsaPayLabelMap; 128 } 129 public Map<String,BigDecimal> getHoursToFlsaPayLabelMap() { 130 return hoursToFlsaPayLabelMap; 131 } 132 public void setClockStatusMessage(String clockStatusMessage) { 133 this.clockStatusMessage = clockStatusMessage; 134 } 135 public String getClockStatusMessage() { 136 return clockStatusMessage; 137 } 138 139 public String getPayCalendarGroup() { 140 return payCalendarGroup; 141 } 142 143 public void setPayCalendarGroup(String payCalendarGroup) { 144 this.payCalendarGroup = payCalendarGroup; 145 } 146 147 /** 148 * Is this record initiated? 149 * @return true if initiated, false otherwise. 150 */ 151 public boolean isRoutable() { 152 return StringUtils.equals(getApprovalStatus(), TkConstants.ROUTE_STATUS.INITIATED); 153 } 154 155 /** 156 * Is this record ready to be approved? 157 * @return true if a valid TK_APPROVER / TK_PROCESSOR can approve, false otherwise. 158 */ 159 public boolean isApprovable() { 160 boolean isEnroute = StringUtils.equals(getApprovalStatus(), "ENROUTE") ; 161 162 if(isEnroute){ 163 DocumentRouteHeaderValue routeHeader = TkServiceLocator.getTimeApproveService().getRouteHeader(this.getDocumentId()); 164 boolean authorized = KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(TKContext.getPrincipalId(), routeHeader, new SecuritySession(TKContext.getPrincipalId())); 165 if(authorized){ 166 List<String> principalsToApprove = KEWServiceLocator.getActionRequestService().getPrincipalIdsWithPendingActionRequestByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, this.getDocumentId()); 167 if(!principalsToApprove.isEmpty() && principalsToApprove.contains(TKContext.getPrincipalId())){ 168 return true; 169 } 170 } 171 } 172 return false; 173 } 174 175 /** 176 * Helper method to grab the URL parameters for setting target mode for a 177 * user/documentID timesheet. Returns a portion simlar to: 178 * 179 * @return parameter portion of a URL, usable to initiate target mode. 180 */ 181 public String getTimesheetUserTargetURLParams() { 182 StringBuffer link = new StringBuffer(); 183 184 link.append("methodToCall=changeTargetPerson"); 185 link.append("&documentId=").append(this.getDocumentId()); 186 Person person = KimApiServiceLocator.getPersonService().getPerson(this.getPrincipalId()); 187 link.append("&principalName=").append(person.getPrincipalName()); 188 189 return link.toString(); 190 } 191 192 public List getNotes() { 193 return notes; 194 } 195 196 public void setNotes(List notes) { 197 this.notes = notes; 198 } 199 200 public List<String> getWarnings() { 201 return warnings; 202 } 203 204 public void setWarnings(List<String> warnings) { 205 this.warnings = warnings; 206 } 207 208 public Set<String> getWorkAreas() { 209 return workAreas; 210 } 211 212 public void setWorkAreas(Set<String> workAreas) { 213 this.workAreas = workAreas; 214 } 215 216 public String getPrincipalId() { 217 return principalId; 218 } 219 220 public void setPrincipalId(String principalId) { 221 this.principalId = principalId; 222 } 223 public Boolean getClockedInOverThreshold() { 224 return clockedInOverThreshold; 225 } 226 public void setClockedInOverThreshold(Boolean clockedInOverThreshold) { 227 this.clockedInOverThreshold = clockedInOverThreshold; 228 } 229 public String getSelected() { 230 return selected; 231 } 232 233 public void setSelected(String selected) { 234 this.selected = selected; 235 } 236 237 public TimeSummary getTimeSummary() { 238 return timeSummary; 239 } 240 241 public void setTimeSummary(TimeSummary timeSummary) { 242 this.timeSummary = timeSummary; 243 } 244 245 public BigDecimal getPeriodTotal() { 246 return periodTotal; 247 } 248 249 public void setPeriodTotal(BigDecimal periodTotal) { 250 this.periodTotal = periodTotal; 251 } 252 253 public int compareTo(ApprovalTimeSummaryRow row) { 254 return name.compareToIgnoreCase(row.getName()); 255 } 256 }