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