View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.tklm.time.approval.summaryrow;
17  
18  import java.io.Serializable;
19  import java.math.BigDecimal;
20  import java.util.ArrayList;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.Set;
25  
26  import org.apache.commons.lang.StringUtils;
27  import org.kuali.kpme.core.util.HrConstants;
28  import org.kuali.kpme.core.util.HrContext;
29  import org.kuali.kpme.tklm.api.time.approval.summaryrow.ApprovalTimeSummaryRowContract;
30  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
31  import org.kuali.kpme.tklm.time.timeblock.TimeBlock;
32  import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
33  import org.kuali.kpme.tklm.time.timesummary.TimeSummary;
34  import org.kuali.rice.kew.api.KewApiConstants;
35  import org.kuali.rice.kew.api.KewApiServiceLocator;
36  import org.kuali.rice.kew.api.action.ActionRequest;
37  import org.kuali.rice.kew.api.document.DocumentStatus;
38  import org.kuali.rice.kew.api.note.Note;
39  import org.kuali.rice.kew.doctype.SecuritySession;
40  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
41  import org.kuali.rice.kew.service.KEWServiceLocator;
42  import org.kuali.rice.kim.api.identity.principal.Principal;
43  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
44  
45  public class ApprovalTimeSummaryRow implements Comparable<ApprovalTimeSummaryRow>, Serializable, ApprovalTimeSummaryRowContract {
46  
47  	private static final long serialVersionUID = -2005933528843934641L;
48  	private String name;
49  	private List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>();
50      /** A Map (Assignment key) of Mapped totals (pay label mapping) */
51      private Map<String, Map<String, BigDecimal>> approverHoursByAssignment;
52      /** A Map (Assignment key) of Mapped totals (pay label mapping) */
53      private Map<String, Map<String, BigDecimal>> otherHoursByAssignment;
54      /** A String (AssignmentDescriptionKey) to Description mapping for all assignments on this summary row */
55      private Map<String,String> assignmentDescriptions; // could refactor out to action level call
56  
57  	private String approvalStatus;
58  	private String approvalStatusMessage;
59  	private String documentId;
60      private Map<String, String> roleNames;
61  	private Map<String,BigDecimal> hoursToPayLabelMap = new HashMap<String,BigDecimal>();
62      private Map<String,BigDecimal> hoursToFlsaPayLabelMap = new HashMap<String,BigDecimal>();
63  	private String clockStatusMessage;
64      private String payCalendarGroup;
65      private List<Note> notes = new ArrayList<Note>();
66      private List<String> warnings = new ArrayList<String>();
67      private Set<String> workAreas;
68      private String principalId;
69      private Boolean clockedInOverThreshold = Boolean.FALSE;    
70      private String selected = "off";
71      private TimeSummary timeSummary;
72      private BigDecimal periodTotal = BigDecimal.ZERO;
73      private String outputString;
74      private String color;
75      /** A Map (Weeks) of Mapped totals (week total mapping) */
76      private Map<String, BigDecimal> weekTotalMap;
77      
78      public String getApprovalStatusMessage() {
79  		return approvalStatusMessage;
80  	}
81  
82  	public void setApprovalStatusMessage(String approvalStatusMessage) {
83  		this.approvalStatusMessage = approvalStatusMessage;
84  	}
85  
86  	public Map<String, String> getAssignmentDescriptions() {
87          return assignmentDescriptions;
88      }
89  
90      public void setAssignmentDescriptions(Map<String, String> assignmentDescriptions) {
91          this.assignmentDescriptions = assignmentDescriptions;
92      }
93  
94      public Map<String, Map<String, BigDecimal>> getApproverHoursByAssignment() {
95          return approverHoursByAssignment;
96      }
97  
98      public void setApproverHoursByAssignment(Map<String, Map<String, BigDecimal>> approverHoursByAssignment) {
99          this.approverHoursByAssignment = approverHoursByAssignment;
100     }
101 
102     public Map<String, Map<String, BigDecimal>> getOtherHoursByAssignment() {
103         return otherHoursByAssignment;
104     }
105 
106     public void setOtherHoursByAssignment(Map<String, Map<String, BigDecimal>> otherHoursByAssignment) {
107         this.otherHoursByAssignment = otherHoursByAssignment;
108     }
109 
110     public String getName() {
111 		return name;
112 	}
113     public void setName(String name) {
114 		this.name = name;
115 	}
116     public List<TimeBlock> getLstTimeBlocks() {
117 		return lstTimeBlocks;
118 	}
119 	public void setLstTimeBlocks(List<TimeBlock> lstTimeBlocks) {
120 		this.lstTimeBlocks = lstTimeBlocks;
121 	}
122 	public String getApprovalStatus() {
123 		return approvalStatus;
124 	}
125 	public void setApprovalStatus(String approvalStatus) {
126 		this.approvalStatus = approvalStatus;
127 	}
128 	public void setDocumentId(String documentId) {
129 		this.documentId = documentId;
130 	}
131 	public String getDocumentId() {
132 		return documentId;
133 	}
134 	public void setHoursToPayLabelMap(Map<String,BigDecimal> hoursToPayLabelMap) {
135 		this.hoursToPayLabelMap = hoursToPayLabelMap;
136 	}
137 	public Map<String,BigDecimal> getHoursToPayLabelMap() {
138 		return hoursToPayLabelMap;
139 	}
140     public void setHoursToFlsaPayLabelMap(Map<String,BigDecimal> hoursToFlsaPayLabelMap) {
141         this.hoursToFlsaPayLabelMap = hoursToFlsaPayLabelMap;
142     }
143     public Map<String,BigDecimal> getHoursToFlsaPayLabelMap() {
144         return hoursToFlsaPayLabelMap;
145     }
146 	public void setClockStatusMessage(String clockStatusMessage) {
147 		this.clockStatusMessage = clockStatusMessage;
148 	}
149 	public String getClockStatusMessage() {
150 		return clockStatusMessage;
151 	}
152 
153     public String getPayCalendarGroup() {
154         return payCalendarGroup;
155     }
156 
157     public void setPayCalendarGroup(String payCalendarGroup) {
158         this.payCalendarGroup = payCalendarGroup;
159     }
160 
161     /**
162      * Is this record initiated?
163      * @return true if initiated, false otherwise.
164      */
165     public boolean isRoutable() {
166         return StringUtils.equals(getApprovalStatus(), HrConstants.ROUTE_STATUS.INITIATED);
167     }
168 
169     /**
170      * Is this record ready to be approved?
171      * @return true if a valid TK_APPROVER / TK_PROCESSOR can approve, false otherwise.
172      */
173     public boolean isApprovable() {
174     	boolean isApprovable = false;
175 
176     	if (DocumentStatus.ENROUTE.getLabel().equals(getApprovalStatus())) {
177     		TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService().getTimesheetDocument(getDocumentId());
178     		if (timesheetDocument != null) {
179     			String timesheetPrincipalId = timesheetDocument.getPrincipalId();
180     			String approverPrincipalId = HrContext.getPrincipalId();
181 
182     			if (!StringUtils.equals(timesheetPrincipalId, approverPrincipalId) && TkServiceLocator.getTimesheetService().isReadyToApprove(timesheetDocument)) {
183     				DocumentRouteHeaderValue routeHeader = TkServiceLocator.getTimeApproveService().getRouteHeader(getDocumentId());
184     				boolean authorized = KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(approverPrincipalId, routeHeader, new SecuritySession(approverPrincipalId));
185     				if (authorized) {
186     					List<String> approverPrincipalIds = KEWServiceLocator.getActionRequestService().getPrincipalIdsWithPendingActionRequestByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, getDocumentId());
187     					if (approverPrincipalIds.contains(approverPrincipalId)) {
188     						isApprovable = true;
189     					}
190     				}
191     			}
192     		}
193     	}
194     	
195         return isApprovable;
196     }
197 
198     /**
199      * Helper method to grab the URL parameters for setting target mode for a
200      * user/documentID timesheet. Returns a portion simlar to:
201      *
202      * @return parameter portion of a URL, usable to initiate target mode.
203      */
204     public String getTimesheetUserTargetURLParams() {
205         StringBuffer link = new StringBuffer();
206 
207         link.append("methodToCall=changeTargetPerson");
208         link.append("&documentId=").append(this.getDocumentId());
209         Principal person = KimApiServiceLocator.getIdentityService().getPrincipal(this.getPrincipalId());
210         link.append("&principalName=").append(person.getPrincipalName());
211 
212         return link.toString();
213     }
214 
215     public List<Note> getNotes() {
216         return notes;
217     }
218 
219     public void setNotes(List<Note> notes) {
220         this.notes = notes;
221     }
222 
223     public List<String> getWarnings() {
224         return warnings;
225     }
226 
227     public void setWarnings(List<String> warnings) {
228         this.warnings = warnings;
229     }
230 
231     public Set<String> getWorkAreas() {
232         return workAreas;
233     }
234 
235     public void setWorkAreas(Set<String> workAreas) {
236         this.workAreas = workAreas;
237     }
238 
239     public String getPrincipalId() {
240         return principalId;
241     }
242 
243     public void setPrincipalId(String principalId) {
244         this.principalId = principalId;
245     }
246 	public Boolean getClockedInOverThreshold() {
247 		return clockedInOverThreshold;
248 	}
249 	public void setClockedInOverThreshold(Boolean clockedInOverThreshold) {
250 		this.clockedInOverThreshold = clockedInOverThreshold;
251 	}
252 	public String getSelected() {
253 		return selected;
254 	}
255 
256 	public void setSelected(String selected) {
257 		this.selected = selected;
258 	}
259 
260     public TimeSummary getTimeSummary() {
261         return timeSummary;
262     }
263 
264     public void setTimeSummary(TimeSummary timeSummary) {
265         this.timeSummary = timeSummary;
266     }
267 
268     public BigDecimal getPeriodTotal() {
269         return periodTotal;
270     }
271 
272     public void setPeriodTotal(BigDecimal periodTotal) {
273         this.periodTotal = periodTotal;
274     }
275     
276     public int compareTo(ApprovalTimeSummaryRow row) {
277         return name.compareToIgnoreCase(row.getName());
278     }
279 
280 	/**
281 	 * @return the outputString
282 	 */
283 	public String getOutputString() {
284 		return outputString;
285 	}
286 
287 	/**
288 	 * @param outputString the outputString to set
289 	 */
290 	public void setOutputString(String outputString) {
291 		this.outputString = outputString;
292 	}
293 
294 	/**
295 	 * @return the color
296 	 */
297 	public String getColor() {
298 		return color;
299 	}
300 
301 	/**
302 	 * @param color the color to set
303 	 */
304 	public void setColor(String color) {
305 		this.color = color;
306 	}
307 
308 	/**
309 	 * @return the weekTotalMap
310 	 */
311 	public Map<String, BigDecimal> getWeekTotalMap() {
312 		return weekTotalMap;
313 	}
314 
315 	/**
316 	 * @param weekTotalMap the weekTotalMap to set
317 	 */
318 	public void setWeekTotalMap(Map<String, BigDecimal> weekTotalMap) {
319 		this.weekTotalMap = weekTotalMap;
320 	}
321 
322     public Map<String, String> getRoleNames() {
323     	//get role name for action request if available
324         if (StringUtils.isNotBlank(documentId)) {
325             List<ActionRequest> actionRequests = KewApiServiceLocator.getWorkflowDocumentService().getPendingActionRequests(documentId);
326             Map<String, String> roleNames = new HashMap<String, String>();
327             for (ActionRequest ar : actionRequests) {
328                 roleNames.put(ar.getPrincipalId(), ar.getQualifiedRoleNameLabel());
329             }
330             this.setRoleNames(roleNames);
331         }
332         return roleNames;
333     }
334 
335     public void setRoleNames(Map<String, String> roleNames) {
336         this.roleNames = roleNames;
337     }
338 
339     public String getRoleName() {
340         return getRoleNames().get(HrContext.getPrincipalId());
341     }
342 	
343 }