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 java.io.Serializable;
019    import java.math.BigDecimal;
020    import java.util.ArrayList;
021    import java.util.HashMap;
022    import java.util.List;
023    import java.util.Map;
024    import java.util.Set;
025    
026    import org.apache.commons.lang.StringUtils;
027    import org.kuali.hr.time.service.base.TkServiceLocator;
028    import org.kuali.hr.time.timeblock.TimeBlock;
029    import org.kuali.hr.time.timesheet.TimesheetDocument;
030    import org.kuali.hr.time.timesummary.TimeSummary;
031    import org.kuali.hr.time.util.TKContext;
032    import org.kuali.hr.time.util.TkConstants;
033    import org.kuali.rice.kew.api.KewApiConstants;
034    import org.kuali.rice.kew.api.document.DocumentStatus;
035    import org.kuali.rice.kew.api.note.Note;
036    import org.kuali.rice.kew.doctype.SecuritySession;
037    import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
038    import org.kuali.rice.kew.service.KEWServiceLocator;
039    import org.kuali.rice.kim.api.identity.principal.Principal;
040    import org.kuali.rice.kim.api.services.KimApiServiceLocator;
041    
042    public class ApprovalTimeSummaryRow implements Comparable<ApprovalTimeSummaryRow>, Serializable {
043            private String name;
044            private List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>();
045        /** A Map (Assignment key) of Mapped totals (pay label mapping) */
046        private Map<String, Map<String, BigDecimal>> approverHoursByAssignment;
047        /** A Map (Assignment key) of Mapped totals (pay label mapping) */
048        private Map<String, Map<String, BigDecimal>> otherHoursByAssignment;
049        /** A String (AssignmentDescriptionKey) to Description mapping for all assignments on this summary row */
050        private Map<String,String> assignmentDescriptions; // could refactor out to action level call
051    
052            private String approvalStatus;
053            private String approvalStatusMessage;
054            private String documentId;
055            private Map<String,BigDecimal> hoursToPayLabelMap = new HashMap<String,BigDecimal>();
056        private Map<String,BigDecimal> hoursToFlsaPayLabelMap = new HashMap<String,BigDecimal>();
057            private String clockStatusMessage;
058        private String payCalendarGroup;
059        private List<Note> notes = new ArrayList<Note>();
060        private List<String> warnings = new ArrayList<String>();
061        private Set<String> workAreas;
062        private String principalId;
063        private Boolean clockedInOverThreshold = Boolean.FALSE;    
064        private String selected = "off";
065        private TimeSummary timeSummary;
066        private BigDecimal periodTotal = BigDecimal.ZERO;
067        
068        public String getApprovalStatusMessage() {
069                    return approvalStatusMessage;
070            }
071    
072            public void setApprovalStatusMessage(String approvalStatusMessage) {
073                    this.approvalStatusMessage = approvalStatusMessage;
074            }
075    
076            public Map<String, String> getAssignmentDescriptions() {
077            return assignmentDescriptions;
078        }
079    
080        public void setAssignmentDescriptions(Map<String, String> assignmentDescriptions) {
081            this.assignmentDescriptions = assignmentDescriptions;
082        }
083    
084        public Map<String, Map<String, BigDecimal>> getApproverHoursByAssignment() {
085            return approverHoursByAssignment;
086        }
087    
088        public void setApproverHoursByAssignment(Map<String, Map<String, BigDecimal>> approverHoursByAssignment) {
089            this.approverHoursByAssignment = approverHoursByAssignment;
090        }
091    
092        public Map<String, Map<String, BigDecimal>> getOtherHoursByAssignment() {
093            return otherHoursByAssignment;
094        }
095    
096        public void setOtherHoursByAssignment(Map<String, Map<String, BigDecimal>> otherHoursByAssignment) {
097            this.otherHoursByAssignment = otherHoursByAssignment;
098        }
099    
100        public String getName() {
101                    return name;
102            }
103        public void setName(String name) {
104                    this.name = name;
105            }
106        public List<TimeBlock> getLstTimeBlocks() {
107                    return lstTimeBlocks;
108            }
109            public void setLstTimeBlocks(List<TimeBlock> lstTimeBlocks) {
110                    this.lstTimeBlocks = lstTimeBlocks;
111            }
112            public String getApprovalStatus() {
113                    return approvalStatus;
114            }
115            public void setApprovalStatus(String approvalStatus) {
116                    this.approvalStatus = approvalStatus;
117            }
118            public void setDocumentId(String documentId) {
119                    this.documentId = documentId;
120            }
121            public String getDocumentId() {
122                    return documentId;
123            }
124            public void setHoursToPayLabelMap(Map<String,BigDecimal> hoursToPayLabelMap) {
125                    this.hoursToPayLabelMap = hoursToPayLabelMap;
126            }
127            public Map<String,BigDecimal> getHoursToPayLabelMap() {
128                    return hoursToPayLabelMap;
129            }
130        public void setHoursToFlsaPayLabelMap(Map<String,BigDecimal> hoursToFlsaPayLabelMap) {
131            this.hoursToFlsaPayLabelMap = hoursToFlsaPayLabelMap;
132        }
133        public Map<String,BigDecimal> getHoursToFlsaPayLabelMap() {
134            return hoursToFlsaPayLabelMap;
135        }
136            public void setClockStatusMessage(String clockStatusMessage) {
137                    this.clockStatusMessage = clockStatusMessage;
138            }
139            public String getClockStatusMessage() {
140                    return clockStatusMessage;
141            }
142    
143        public String getPayCalendarGroup() {
144            return payCalendarGroup;
145        }
146    
147        public void setPayCalendarGroup(String payCalendarGroup) {
148            this.payCalendarGroup = payCalendarGroup;
149        }
150    
151        /**
152         * Is this record initiated?
153         * @return true if initiated, false otherwise.
154         */
155        public boolean isRoutable() {
156            return StringUtils.equals(getApprovalStatus(), TkConstants.ROUTE_STATUS.INITIATED);
157        }
158    
159        public boolean isApprovable() {
160            boolean isApprovable = false;
161            
162            if (DocumentStatus.ENROUTE.getLabel().equals(getApprovalStatus())) {
163                    TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService().getTimesheetDocument(getDocumentId());
164                    if (timesheetDocument != null) {
165                            String timesheetPrincipalId = timesheetDocument.getPrincipalId();
166                            String approverPrincipalId = TKContext.getPrincipalId();
167                            
168                            if (!StringUtils.equals(timesheetPrincipalId, approverPrincipalId) && TkServiceLocator.getTimesheetService().isReadyToApprove(timesheetDocument)) {
169                            DocumentRouteHeaderValue routeHeader = TkServiceLocator.getTimeApproveService().getRouteHeader(getDocumentId());
170                            boolean authorized = KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(approverPrincipalId, routeHeader, new SecuritySession(approverPrincipalId));
171                            if (authorized) {
172                                    List<String> approverPrincipalIds = KEWServiceLocator.getActionRequestService().getPrincipalIdsWithPendingActionRequestByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, getDocumentId());
173                                    if (approverPrincipalIds.contains(approverPrincipalId)) {
174                                            isApprovable = true;
175                                    }
176                            }
177                            }
178                    }
179            }
180            
181            return isApprovable;
182        }
183    
184        /**
185         * Helper method to grab the URL parameters for setting target mode for a
186         * user/documentID timesheet. Returns a portion simlar to:
187         *
188         * @return parameter portion of a URL, usable to initiate target mode.
189         */
190        public String getTimesheetUserTargetURLParams() {
191            StringBuffer link = new StringBuffer();
192    
193            link.append("methodToCall=changeTargetPerson");
194            link.append("&documentId=").append(this.getDocumentId());
195            Principal person = KimApiServiceLocator.getIdentityService().getPrincipal(this.getPrincipalId());
196            link.append("&principalName=").append(person.getPrincipalName());
197    
198            return link.toString();
199        }
200    
201        public List<Note> getNotes() {
202            return notes;
203        }
204    
205        public void setNotes(List<Note> notes) {
206            this.notes = notes;
207        }
208    
209        public List<String> getWarnings() {
210            return warnings;
211        }
212    
213        public void setWarnings(List<String> warnings) {
214            this.warnings = warnings;
215        }
216    
217        public Set<String> getWorkAreas() {
218            return workAreas;
219        }
220    
221        public void setWorkAreas(Set<String> workAreas) {
222            this.workAreas = workAreas;
223        }
224    
225        public String getPrincipalId() {
226            return principalId;
227        }
228    
229        public void setPrincipalId(String principalId) {
230            this.principalId = principalId;
231        }
232            public Boolean getClockedInOverThreshold() {
233                    return clockedInOverThreshold;
234            }
235            public void setClockedInOverThreshold(Boolean clockedInOverThreshold) {
236                    this.clockedInOverThreshold = clockedInOverThreshold;
237            }
238            public String getSelected() {
239                    return selected;
240            }
241    
242            public void setSelected(String selected) {
243                    this.selected = selected;
244            }
245    
246        public TimeSummary getTimeSummary() {
247            return timeSummary;
248        }
249    
250        public void setTimeSummary(TimeSummary timeSummary) {
251            this.timeSummary = timeSummary;
252        }
253    
254        public BigDecimal getPeriodTotal() {
255            return periodTotal;
256        }
257    
258        public void setPeriodTotal(BigDecimal periodTotal) {
259            this.periodTotal = periodTotal;
260        }
261        
262        public int compareTo(ApprovalTimeSummaryRow row) {
263            return name.compareToIgnoreCase(row.getName());
264        }
265    }