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