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