View Javadoc
1   /**
2    * Copyright 2004-2014 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.leave.approval.web;
17  
18  import java.io.Serializable;
19  import java.math.BigDecimal;
20  import java.util.ArrayList;
21  import java.util.Date;
22  import java.util.LinkedHashMap;
23  import java.util.LinkedList;
24  import java.util.List;
25  import java.util.Map;
26  import java.util.Set;
27  
28  import org.apache.commons.lang.StringUtils;
29  import org.kuali.kpme.core.util.HrConstants;
30  import org.kuali.kpme.core.util.HrContext;
31  import org.kuali.kpme.tklm.api.leave.approval.web.ApprovalLeaveSummaryRowContract;
32  import org.kuali.kpme.tklm.leave.block.LeaveBlock;
33  import org.kuali.kpme.tklm.leave.calendar.LeaveCalendarDocument;
34  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
35  import org.kuali.kpme.tklm.leave.summary.LeaveSummary;
36  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
37  import org.kuali.rice.kew.api.KewApiConstants;
38  import org.kuali.rice.kew.api.document.DocumentStatus;
39  import org.kuali.rice.kew.api.note.Note;
40  import org.kuali.rice.kew.doctype.SecuritySession;
41  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
42  import org.kuali.rice.kew.service.KEWServiceLocator;
43  import org.kuali.rice.kim.api.identity.principal.Principal;
44  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
45  
46  public class ApprovalLeaveSummaryRow implements Comparable<ApprovalLeaveSummaryRow>, Serializable, ApprovalLeaveSummaryRowContract {
47  
48  	private static final long serialVersionUID = -1573234630744940098L;
49  	private String name;
50  	private String principalId;
51  	private String documentId;
52      private Map<String, String> roleNames;
53  	private List<String> warnings = new ArrayList<String>();
54  	private String selected = "off";
55  	private String approvalStatus;
56  
57      private List<Note> notes = new ArrayList<Note>();
58  	private Boolean moreThanOneCalendar = Boolean.FALSE;
59  	private Map<String, Boolean> enableWeekDetails = new LinkedHashMap<String, Boolean>();	
60  	private String lastApproveMessage;
61  	private List<LeaveBlock> leaveBlockList = new ArrayList<LeaveBlock>();
62  	private Map<Integer, String> weeklyDistribution = new LinkedHashMap<Integer, String>();
63  	private Map<String, String> weekDates = new LinkedHashMap<String, String>();
64  	private Map<Date, Map<String, BigDecimal>> earnCodeLeaveHours = new LinkedHashMap<Date, Map<String, BigDecimal>>();
65  	private Map<String, Set<Date>> weekDateList = new LinkedHashMap<String, Set<Date>>();
66  	private Boolean exemptEmployee;
67  	private String color;
68  	private Map<String,List<Map<String, Object>>> detailMap = new LinkedHashMap<String, List<Map<String,Object>>>();
69  	private LeaveSummary leaveSummary;
70  	
71      public LeaveSummary getLeaveSummary() {
72  		return leaveSummary;
73  	}
74  
75  	public void setLeaveSummary(LeaveSummary leaveSummary) {
76  		this.leaveSummary = leaveSummary;
77  	}
78  
79  
80  	/**
81       * Is this record ready to be approved?
82       * @return true if a valid TK_APPROVER / TK_PROCESSOR can approve, false otherwise.
83       */
84      public boolean isApprovable() {
85      	boolean isApprovable = false;
86  
87      	if (DocumentStatus.ENROUTE.getLabel().equals(getApprovalStatus())) {
88      		LeaveCalendarDocument leaveCalendarDocument = LmServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(getDocumentId());
89      		if (leaveCalendarDocument != null) {
90      			String leaveCalendarPrincipalId = leaveCalendarDocument.getPrincipalId();
91      			String approverPrincipalId = HrContext.getPrincipalId();
92  
93      			if (!StringUtils.equals(leaveCalendarPrincipalId, approverPrincipalId) && LmServiceLocator.getLeaveCalendarService().isReadyToApprove(leaveCalendarDocument)) {
94      				DocumentRouteHeaderValue routeHeader = TkServiceLocator.getTimeApproveService().getRouteHeader(getDocumentId());
95      				boolean authorized = KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(approverPrincipalId, routeHeader, new SecuritySession(approverPrincipalId));
96      				if (authorized) {
97      					List<String> approverPrincipalIds = KEWServiceLocator.getActionRequestService().getPrincipalIdsWithPendingActionRequestByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, getDocumentId());
98      					if (approverPrincipalIds.contains(approverPrincipalId)) {
99      						isApprovable = true;
100     					}
101     				}
102     			}
103     		}
104     	}
105 	 	 	 	
106         return isApprovable;
107     }
108 	
109 	 
110 	public int compareTo(ApprovalLeaveSummaryRow row) {
111         return name.compareToIgnoreCase(row.getName());
112     }
113 
114 	public String getName() {
115 		return name;
116 	}
117 
118 	public void setName(String name) {
119 		this.name = name;
120 	}
121 
122 	public String getPrincipalId() {
123 		return principalId;
124 	}
125 
126 	public void setPrincipalId(String principalId) {
127 		this.principalId = principalId;
128 	}
129 	
130     public String getUserTargetURLParams() {
131         StringBuffer link = new StringBuffer();
132 
133         link.append("methodToCall=changeTargetPerson");
134         link.append("&documentId=").append(this.getDocumentId());
135         Principal person = KimApiServiceLocator.getIdentityService().getPrincipal(this.getPrincipalId());
136         link.append("&principalName=").append(person.getPrincipalName());
137         
138         return link.toString();
139     }
140 
141 	public List<LeaveBlock> getLeaveBlockList() {
142 		return leaveBlockList;
143 	}
144 
145 	public void setLeaveBlockList(List<LeaveBlock> leaveBlockList) {
146 		this.leaveBlockList = leaveBlockList;
147 	}
148 
149 	public String getDocumentId() {
150 		return documentId;
151 	}
152 
153 	public void setDocumentId(String documentId) {
154 		this.documentId = documentId;
155 	}
156 
157 	public List<String> getWarnings() {
158 		return warnings;
159 	}
160 
161 	public void setWarnings(List<String> warnings) {
162 		this.warnings = warnings;
163 	}
164 
165 	public String getSelected() {
166 		return selected;
167 	}
168 
169 	public void setSelected(String selected) {
170 		this.selected = selected;
171 	}
172 
173     public List<Note> getNotes() {
174         return notes;
175     }
176 
177     public void setNotes(List<Note> notes) {
178         this.notes = notes;
179     }
180 
181 	public String getLastApproveMessage() {
182 		return lastApproveMessage;
183 	}
184 
185 	public void setLastApproveMessage(String lastApproveMessage) {
186 		this.lastApproveMessage = lastApproveMessage;
187 	}
188 
189 	public String getApprovalStatus() {
190 		return approvalStatus;
191 	}
192 
193 	public void setApprovalStatus(String approvalStatus) {
194 		this.approvalStatus = approvalStatus;
195 	}
196 
197 	public Map<Date, Map<String, BigDecimal>> getEarnCodeLeaveHours() {
198 		return earnCodeLeaveHours;
199 	}
200 
201 	public void setEarnCodeLeaveHours(Map<Date, Map<String, BigDecimal>> earnCodeLeaveHours) {
202 		this.earnCodeLeaveHours = earnCodeLeaveHours;
203 	}
204 
205 	
206 	public Map<Integer, String> getWeeklyDistribution() {
207 		return weeklyDistribution;
208 	}
209 
210 
211 	public void setWeeklyDistribution(Map<Integer, String> weeklyDistribution) {
212 		this.weeklyDistribution = weeklyDistribution;
213 	}
214 	
215 	public Map<String, String> getWeekDates() {
216 		return weekDates;
217 	}
218 
219 
220 	public void setWeekDates(Map<String, String> weekDates) {
221 		this.weekDates = weekDates;
222 	}
223 
224 
225 	public Boolean getMoreThanOneCalendar() {
226 		return moreThanOneCalendar;
227 	}
228 
229 
230 	public void setMoreThanOneCalendar(Boolean moreThanOneCalendar) {
231 		this.moreThanOneCalendar = moreThanOneCalendar;
232 	}
233 
234 
235 	public Boolean getExemptEmployee() {
236 		if(this.exemptEmployee == null) {
237 			this.exemptEmployee = LmServiceLocator.getLeaveApprovalService().isActiveAssignmentFoundOnJobFlsaStatus(this.principalId,HrConstants.FLSA_STATUS_EXEMPT, true);
238 		}
239 		return exemptEmployee;
240 	}
241 
242 
243 	public void setExemptEmployee(Boolean exemptEmployee) {
244 		this.exemptEmployee = exemptEmployee;
245 	}
246 
247 
248 	/**
249 	 * @return the color
250 	 */
251 	public String getColor() {
252 		return color;
253 	}
254 
255 
256 	/**
257 	 * @param color the color to set
258 	 */
259 	public void setColor(String color) {
260 		this.color = color;
261 	}
262 
263     public Map<String, String> getRoleNames() {
264         return roleNames;
265     }
266 
267     public void setRoleNames(Map<String, String> roleNames) {
268         this.roleNames = roleNames;
269     }
270 
271     public String getRoleName() {
272         return getRoleNames().get(HrContext.getPrincipalId());
273     }
274 
275 
276 	public Map<String, Set<Date>> getWeekDateList() {
277 		return weekDateList;
278 	}
279 
280 
281 	public void setWeekDateList(Map<String, Set<Date>> weekDateList) {
282 		this.weekDateList = weekDateList;
283 	}
284 
285 
286 	public Map<String, List<Map<String, Object>>> getDetailMap() {
287 		return detailMap;
288 	}
289 
290 
291 	public void setDetailMap(Map<String, List<Map<String, Object>>> detailMap) {
292 		this.detailMap = detailMap;
293 	}
294 
295 
296 	public Map<String, Boolean> getEnableWeekDetails() {
297 		return enableWeekDetails;
298 	}
299 
300 
301 	public void setEnableWeekDetails(Map<String, Boolean> enableWeekDetails) {
302 		this.enableWeekDetails = enableWeekDetails;
303 	}	
304     
305 }