001    /**
002     * Copyright 2004-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.hr.time.approval.web;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.hr.lm.leaveblock.LeaveBlock;
020    import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument;
021    import org.kuali.hr.time.service.base.TkServiceLocator;
022    import org.kuali.hr.time.util.TKContext;
023    import org.kuali.hr.time.util.TkConstants;
024    import org.kuali.rice.kew.api.KewApiConstants;
025    import org.kuali.rice.kew.api.document.DocumentStatus;
026    import org.kuali.rice.kew.api.note.Note;
027    import org.kuali.rice.kew.doctype.SecuritySession;
028    import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
029    import org.kuali.rice.kew.service.KEWServiceLocator;
030    import org.kuali.rice.kim.api.identity.principal.Principal;
031    import org.kuali.rice.kim.api.services.KimApiServiceLocator;
032    
033    import java.io.Serializable;
034    import java.math.BigDecimal;
035    import java.util.*;
036    
037    public class ApprovalLeaveSummaryRow implements Comparable<ApprovalLeaveSummaryRow>, Serializable {
038            private String name;
039            private String principalId;
040            private String documentId;
041            private List<String> warnings = new ArrayList<String>();
042            private String selected = "off";
043            private String approvalStatus;
044    
045        private List<Note> notes = new ArrayList<Note>();
046            private Boolean moreThanOneCalendar = Boolean.FALSE;
047            private String lastApproveMessage;
048            private List<LeaveBlock> leaveBlockList = new ArrayList<LeaveBlock>();
049            private Map<Date, Map<String, BigDecimal>> earnCodeLeaveHours = new LinkedHashMap<Date, Map<String, BigDecimal>>();
050            private Boolean exemptEmployee;
051    
052        public boolean isApprovable() {
053            boolean isApprovable = false;
054    
055            if (DocumentStatus.ENROUTE.getLabel().equals(getApprovalStatus())) {
056                LeaveCalendarDocument leaveCalendarDocument = TkServiceLocator.getLeaveCalendarService().getLeaveCalendarDocument(getDocumentId());
057                if (leaveCalendarDocument != null) {
058                            String leaveCalendarPrincipalId = leaveCalendarDocument.getPrincipalId();
059                            String approverPrincipalId = TKContext.getPrincipalId();
060                            
061                            if (!StringUtils.equals(leaveCalendarPrincipalId, approverPrincipalId) && TkServiceLocator.getLeaveCalendarService().isReadyToApprove(leaveCalendarDocument)) {
062                                    DocumentRouteHeaderValue routeHeader = TkServiceLocator.getTimeApproveService().getRouteHeader(getDocumentId());
063                                boolean authorized = KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(approverPrincipalId, routeHeader, new SecuritySession(approverPrincipalId));
064                                    if (authorized) {
065                                            List<String> approverPrincipalIds = KEWServiceLocator.getActionRequestService().getPrincipalIdsWithPendingActionRequestByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, getDocumentId());
066                                            if (approverPrincipalIds.contains(approverPrincipalId)) {
067                                                    isApprovable = true;
068                                    }
069                                    }
070                            }
071                }
072            }
073            
074            return isApprovable;
075        }
076            
077             
078            public int compareTo(ApprovalLeaveSummaryRow row) {
079            return name.compareToIgnoreCase(row.getName());
080        }
081    
082            public String getName() {
083                    return name;
084            }
085    
086            public void setName(String name) {
087                    this.name = name;
088            }
089    
090            public String getPrincipalId() {
091                    return principalId;
092            }
093    
094            public void setPrincipalId(String principalId) {
095                    this.principalId = principalId;
096            }
097            
098        public String getUserTargetURLParams() {
099            StringBuffer link = new StringBuffer();
100    
101            link.append("methodToCall=changeTargetPerson");
102            link.append("&documentId=").append(this.getDocumentId());
103            Principal person = KimApiServiceLocator.getIdentityService().getPrincipal(this.getPrincipalId());
104            link.append("&principalName=").append(person.getPrincipalName());
105            
106            return link.toString();
107        }
108    
109            public List<LeaveBlock> getLeaveBlockList() {
110                    return leaveBlockList;
111            }
112    
113            public void setLeaveBlockList(List<LeaveBlock> leaveBlockList) {
114                    this.leaveBlockList = leaveBlockList;
115            }
116    
117            public String getDocumentId() {
118                    return documentId;
119            }
120    
121            public void setDocumentId(String documentId) {
122                    this.documentId = documentId;
123            }
124    
125            public List<String> getWarnings() {
126                    return warnings;
127            }
128    
129            public void setWarnings(List<String> warnings) {
130                    this.warnings = warnings;
131            }
132    
133            public String getSelected() {
134                    return selected;
135            }
136    
137            public void setSelected(String selected) {
138                    this.selected = selected;
139            }
140    
141        public List<Note> getNotes() {
142            return notes;
143        }
144    
145        public void setNotes(List<Note> notes) {
146            this.notes = notes;
147        }
148    
149            public String getLastApproveMessage() {
150                    return lastApproveMessage;
151            }
152    
153            public void setLastApproveMessage(String lastApproveMessage) {
154                    this.lastApproveMessage = lastApproveMessage;
155            }
156    
157            public String getApprovalStatus() {
158                    return approvalStatus;
159            }
160    
161            public void setApprovalStatus(String approvalStatus) {
162                    this.approvalStatus = approvalStatus;
163            }
164    
165            public Map<Date, Map<String, BigDecimal>> getEarnCodeLeaveHours() {
166                    return earnCodeLeaveHours;
167            }
168    
169            public void setEarnCodeLeaveHours(Map<Date, Map<String, BigDecimal>> earnCodeLeaveHours) {
170                    this.earnCodeLeaveHours = earnCodeLeaveHours;
171            }
172    
173            public Boolean getMoreThanOneCalendar() {
174                    return moreThanOneCalendar;
175            }
176    
177    
178            public void setMoreThanOneCalendar(Boolean moreThanOneCalendar) {
179                    this.moreThanOneCalendar = moreThanOneCalendar;
180            }
181    
182    
183            public Boolean getExemptEmployee() {
184                    if(this.exemptEmployee == null) {
185                            this.exemptEmployee = TkServiceLocator.getLeaveApprovalService().isActiveAssignmentFoundOnJobFlsaStatus(this.principalId,TkConstants.FLSA_STATUS_EXEMPT, true);
186                    }
187                    return exemptEmployee;
188            }
189    
190    
191            public void setExemptEmployee(Boolean exemptEmployee) {
192                    this.exemptEmployee = exemptEmployee;
193            }
194            
195            
196    }