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.Date;
21  import java.util.LinkedHashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.hr.lm.leaveblock.LeaveBlock;
27  import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument;
28  import org.kuali.hr.lm.workflow.LeaveCalendarDocumentHeader;
29  import org.kuali.hr.time.service.base.TkServiceLocator;
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 ApprovalLeaveSummaryRow implements Comparable<ApprovalLeaveSummaryRow> {
41  	private String name;
42  	private String principalId;
43  	private String documentId;
44  	private List<String> warnings = new ArrayList<String>();
45  	private String selected = "off";
46  	private String approvalStatus;
47  
48      private List<Note> notes = new ArrayList<Note>();
49  	private Boolean moreThanOneCalendar = Boolean.FALSE;
50  	private String lastApproveMessage;
51  	private List<LeaveBlock> leaveBlockList = new ArrayList<LeaveBlock>();
52  	private Map<Date, Map<String, BigDecimal>> earnCodeLeaveHours = new LinkedHashMap<Date, Map<String, BigDecimal>>();
53  	private Boolean exemptEmployee;
54  	
55      /**
56       * Is this record ready to be approved?
57       * @return true if a valid TK_APPROVER / TK_PROCESSOR can approve, false otherwise.
58       */
59      public boolean isApprovable() {
60      	boolean isEnroute =  StringUtils.equals(getApprovalStatus(), "ENROUTE") ;
61  
62          if(isEnroute){
63              LeaveCalendarDocument doc = TkServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(this.documentId);
64              //is there a pending bt doc?
65              if (!TkServiceLocator.getLeaveCalendarService().isReadyToApprove(doc)) {
66                  return false;
67              }
68          	DocumentRouteHeaderValue routeHeader = TkServiceLocator.getTimeApproveService().getRouteHeader(this.getDocumentId());
69              // check if there are any pending calendars are there
70          	LeaveCalendarDocumentHeader lcdh = TkServiceLocator.getLeaveCalendarDocumentHeaderService().getMinBeginDatePendingLeaveCalendar(this.principalId);
71              if (lcdh != null){             //if there were any pending document
72                  //check to see if it's before the current document. if it is, then this document is not approvable.
73                  if (TkServiceLocator.getLeaveCalendarDocumentHeaderService().getDocumentHeader(this.documentId).getBeginDate().compareTo(lcdh.getEndDate()) >= 0){
74                      return false;
75                  }
76              }
77              boolean authorized = KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(TKContext.getPrincipalId(), routeHeader, new SecuritySession(TKContext.getPrincipalId()));
78          	if(authorized){
79          		List<String> principalsToApprove = KEWServiceLocator.getActionRequestService().getPrincipalIdsWithPendingActionRequestByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, this.getDocumentId());
80          		if(!principalsToApprove.isEmpty() && principalsToApprove.contains(TKContext.getPrincipalId())){
81              		return true;
82              	}
83          	}
84          }
85          return false;
86      }
87  	
88  	 
89  	public int compareTo(ApprovalLeaveSummaryRow row) {
90          return name.compareToIgnoreCase(row.getName());
91      }
92  
93  	public String getName() {
94  		return name;
95  	}
96  
97  	public void setName(String name) {
98  		this.name = name;
99  	}
100 
101 	public String getPrincipalId() {
102 		return principalId;
103 	}
104 
105 	public void setPrincipalId(String principalId) {
106 		this.principalId = principalId;
107 	}
108 	
109     public String getUserTargetURLParams() {
110         StringBuffer link = new StringBuffer();
111 
112         link.append("methodToCall=changeTargetPerson");
113         link.append("&documentId=").append(this.getDocumentId());
114         Person person = KimApiServiceLocator.getPersonService().getPerson(this.getPrincipalId());
115         link.append("&principalName=").append(person.getPrincipalName());
116         
117         return link.toString();
118     }
119 
120 	public List<LeaveBlock> getLeaveBlockList() {
121 		return leaveBlockList;
122 	}
123 
124 	public void setLeaveBlockList(List<LeaveBlock> leaveBlockList) {
125 		this.leaveBlockList = leaveBlockList;
126 	}
127 
128 	public String getDocumentId() {
129 		return documentId;
130 	}
131 
132 	public void setDocumentId(String documentId) {
133 		this.documentId = documentId;
134 	}
135 
136 	public List<String> getWarnings() {
137 		return warnings;
138 	}
139 
140 	public void setWarnings(List<String> warnings) {
141 		this.warnings = warnings;
142 	}
143 
144 	public String getSelected() {
145 		return selected;
146 	}
147 
148 	public void setSelected(String selected) {
149 		this.selected = selected;
150 	}
151 
152     public List<Note> getNotes() {
153         return notes;
154     }
155 
156     public void setNotes(List<Note> notes) {
157         this.notes = notes;
158     }
159 
160 	public String getLastApproveMessage() {
161 		return lastApproveMessage;
162 	}
163 
164 	public void setLastApproveMessage(String lastApproveMessage) {
165 		this.lastApproveMessage = lastApproveMessage;
166 	}
167 
168 	public String getApprovalStatus() {
169 		return approvalStatus;
170 	}
171 
172 	public void setApprovalStatus(String approvalStatus) {
173 		this.approvalStatus = approvalStatus;
174 	}
175 
176 	public Map<Date, Map<String, BigDecimal>> getEarnCodeLeaveHours() {
177 		return earnCodeLeaveHours;
178 	}
179 
180 	public void setEarnCodeLeaveHours(Map<Date, Map<String, BigDecimal>> earnCodeLeaveHours) {
181 		this.earnCodeLeaveHours = earnCodeLeaveHours;
182 	}
183 
184 	public Boolean getMoreThanOneCalendar() {
185 		return moreThanOneCalendar;
186 	}
187 
188 
189 	public void setMoreThanOneCalendar(Boolean moreThanOneCalendar) {
190 		this.moreThanOneCalendar = moreThanOneCalendar;
191 	}
192 
193 
194 	public Boolean getExemptEmployee() {
195 		if(this.exemptEmployee == null) {
196 			this.exemptEmployee = TkServiceLocator.getLeaveApprovalService().isActiveAssignmentFoundOnJobFlsaStatus(this.principalId,TkConstants.FLSA_STATUS_EXEMPT, true);
197 		}
198 		return exemptEmployee;
199 	}
200 
201 
202 	public void setExemptEmployee(Boolean exemptEmployee) {
203 		this.exemptEmployee = exemptEmployee;
204 	}
205 	
206 	
207 }