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.hr.time.approval.web;
17  
18  import java.math.BigDecimal;
19  import java.util.ArrayList;
20  import java.util.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  import java.util.Set;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.hr.time.service.base.TkServiceLocator;
27  import org.kuali.hr.time.timeblock.TimeBlock;
28  import org.kuali.hr.time.timesheet.TimesheetDocument;
29  import org.kuali.hr.time.timesummary.TimeSummary;
30  import org.kuali.hr.time.util.TKContext;
31  import org.kuali.hr.time.util.TkConstants;
32  import org.kuali.rice.kew.api.KewApiConstants;
33  import org.kuali.rice.kew.api.note.Note;
34  import org.kuali.rice.kew.doctype.SecuritySession;
35  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
36  import org.kuali.rice.kew.service.KEWServiceLocator;
37  import org.kuali.rice.kim.api.identity.Person;
38  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
39  
40  public class ApprovalTimeSummaryRow implements Comparable<ApprovalTimeSummaryRow> {
41  	private String name;
42  	private List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>();
43      /** A Map (Assignment key) of Mapped totals (pay label mapping) */
44      private Map<String, Map<String, BigDecimal>> approverHoursByAssignment;
45      /** A Map (Assignment key) of Mapped totals (pay label mapping) */
46      private Map<String, Map<String, BigDecimal>> otherHoursByAssignment;
47      /** A String (AssignmentDescriptionKey) to Description mapping for all assignments on this summary row */
48      private Map<String,String> assignmentDescriptions; // could refactor out to action level call
49  
50  	private String approvalStatus;
51  	private String approvalStatusMessage;
52  	private String documentId;
53  	private Map<String,BigDecimal> hoursToPayLabelMap = new HashMap<String,BigDecimal>();
54      private Map<String,BigDecimal> hoursToFlsaPayLabelMap = new HashMap<String,BigDecimal>();
55  	private String clockStatusMessage;
56      private String payCalendarGroup;
57      private List<Note> notes = new ArrayList<Note>();
58      private List<String> warnings = new ArrayList<String>();
59      private Set<String> workAreas;
60      private String principalId;
61      private Boolean clockedInOverThreshold = Boolean.FALSE;    
62      private String selected = "off";
63      private TimeSummary timeSummary;
64      private BigDecimal periodTotal = BigDecimal.ZERO;
65      
66      public String getApprovalStatusMessage() {
67  		return approvalStatusMessage;
68  	}
69  
70  	public void setApprovalStatusMessage(String approvalStatusMessage) {
71  		this.approvalStatusMessage = approvalStatusMessage;
72  	}
73  
74  	public Map<String, String> getAssignmentDescriptions() {
75          return assignmentDescriptions;
76      }
77  
78      public void setAssignmentDescriptions(Map<String, String> assignmentDescriptions) {
79          this.assignmentDescriptions = assignmentDescriptions;
80      }
81  
82      public Map<String, Map<String, BigDecimal>> getApproverHoursByAssignment() {
83          return approverHoursByAssignment;
84      }
85  
86      public void setApproverHoursByAssignment(Map<String, Map<String, BigDecimal>> approverHoursByAssignment) {
87          this.approverHoursByAssignment = approverHoursByAssignment;
88      }
89  
90      public Map<String, Map<String, BigDecimal>> getOtherHoursByAssignment() {
91          return otherHoursByAssignment;
92      }
93  
94      public void setOtherHoursByAssignment(Map<String, Map<String, BigDecimal>> otherHoursByAssignment) {
95          this.otherHoursByAssignment = otherHoursByAssignment;
96      }
97  
98      public String getName() {
99  		return name;
100 	}
101     public void setName(String name) {
102 		this.name = name;
103 	}
104     public List<TimeBlock> getLstTimeBlocks() {
105 		return lstTimeBlocks;
106 	}
107 	public void setLstTimeBlocks(List<TimeBlock> lstTimeBlocks) {
108 		this.lstTimeBlocks = lstTimeBlocks;
109 	}
110 	public String getApprovalStatus() {
111 		return approvalStatus;
112 	}
113 	public void setApprovalStatus(String approvalStatus) {
114 		this.approvalStatus = approvalStatus;
115 	}
116 	public void setDocumentId(String documentId) {
117 		this.documentId = documentId;
118 	}
119 	public String getDocumentId() {
120 		return documentId;
121 	}
122 	public void setHoursToPayLabelMap(Map<String,BigDecimal> hoursToPayLabelMap) {
123 		this.hoursToPayLabelMap = hoursToPayLabelMap;
124 	}
125 	public Map<String,BigDecimal> getHoursToPayLabelMap() {
126 		return hoursToPayLabelMap;
127 	}
128     public void setHoursToFlsaPayLabelMap(Map<String,BigDecimal> hoursToFlsaPayLabelMap) {
129         this.hoursToFlsaPayLabelMap = hoursToFlsaPayLabelMap;
130     }
131     public Map<String,BigDecimal> getHoursToFlsaPayLabelMap() {
132         return hoursToFlsaPayLabelMap;
133     }
134 	public void setClockStatusMessage(String clockStatusMessage) {
135 		this.clockStatusMessage = clockStatusMessage;
136 	}
137 	public String getClockStatusMessage() {
138 		return clockStatusMessage;
139 	}
140 
141     public String getPayCalendarGroup() {
142         return payCalendarGroup;
143     }
144 
145     public void setPayCalendarGroup(String payCalendarGroup) {
146         this.payCalendarGroup = payCalendarGroup;
147     }
148 
149     /**
150      * Is this record initiated?
151      * @return true if initiated, false otherwise.
152      */
153     public boolean isRoutable() {
154         return StringUtils.equals(getApprovalStatus(), TkConstants.ROUTE_STATUS.INITIATED);
155     }
156 
157     /**
158      * Is this record ready to be approved?
159      * @return true if a valid TK_APPROVER / TK_PROCESSOR can approve, false otherwise.
160      */
161     public boolean isApprovable() {
162     	boolean isEnroute =  StringUtils.equals(getApprovalStatus(), "ENROUTE") ;
163 
164         if(isEnroute){
165         
166         	TimesheetDocument doc = TkServiceLocator.getTimesheetService().getTimesheetDocument(this.documentId);
167         	//is there a pending bt doc?
168         	if (!TkServiceLocator.getTimesheetService().isReadyToApprove(doc)) {
169         		return false;
170         	}
171         	
172         	DocumentRouteHeaderValue routeHeader = TkServiceLocator.getTimeApproveService().getRouteHeader(this.getDocumentId());
173         	boolean authorized = KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(TKContext.getPrincipalId(), routeHeader, new SecuritySession(TKContext.getPrincipalId()));
174         	if(authorized){
175         		List<String> principalsToApprove = KEWServiceLocator.getActionRequestService().getPrincipalIdsWithPendingActionRequestByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, this.getDocumentId());
176         		if(!principalsToApprove.isEmpty() && principalsToApprove.contains(TKContext.getPrincipalId())){
177             		return true;
178             	}
179         	}
180         }
181         return false;
182     }
183 
184     /**
185      * Helper method to grab the URL parameters for setting target mode for a
186      * user/documentID timesheet. Returns a portion simlar to:
187      *
188      * @return parameter portion of a URL, usable to initiate target mode.
189      */
190     public String getTimesheetUserTargetURLParams() {
191         StringBuffer link = new StringBuffer();
192 
193         link.append("methodToCall=changeTargetPerson");
194         link.append("&documentId=").append(this.getDocumentId());
195         Person person = KimApiServiceLocator.getPersonService().getPerson(this.getPrincipalId());
196         link.append("&principalName=").append(person.getPrincipalName());
197 
198         return link.toString();
199     }
200 
201     public List<Note> getNotes() {
202         return notes;
203     }
204 
205     public void setNotes(List<Note> notes) {
206         this.notes = notes;
207     }
208 
209     public List<String> getWarnings() {
210         return warnings;
211     }
212 
213     public void setWarnings(List<String> warnings) {
214         this.warnings = warnings;
215     }
216 
217     public Set<String> getWorkAreas() {
218         return workAreas;
219     }
220 
221     public void setWorkAreas(Set<String> workAreas) {
222         this.workAreas = workAreas;
223     }
224 
225     public String getPrincipalId() {
226         return principalId;
227     }
228 
229     public void setPrincipalId(String principalId) {
230         this.principalId = principalId;
231     }
232 	public Boolean getClockedInOverThreshold() {
233 		return clockedInOverThreshold;
234 	}
235 	public void setClockedInOverThreshold(Boolean clockedInOverThreshold) {
236 		this.clockedInOverThreshold = clockedInOverThreshold;
237 	}
238 	public String getSelected() {
239 		return selected;
240 	}
241 
242 	public void setSelected(String selected) {
243 		this.selected = selected;
244 	}
245 
246     public TimeSummary getTimeSummary() {
247         return timeSummary;
248     }
249 
250     public void setTimeSummary(TimeSummary timeSummary) {
251         this.timeSummary = timeSummary;
252     }
253 
254     public BigDecimal getPeriodTotal() {
255         return periodTotal;
256     }
257 
258     public void setPeriodTotal(BigDecimal periodTotal) {
259         this.periodTotal = periodTotal;
260     }
261     
262     public int compareTo(ApprovalTimeSummaryRow row) {
263         return name.compareToIgnoreCase(row.getName());
264     }
265 }