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