View Javadoc

1   /**
2    * Copyright 2004-2012 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.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  import java.util.Set;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.hr.time.service.base.TkServiceLocator;
27  import org.kuali.hr.time.timeblock.TimeBlock;
28  import org.kuali.hr.time.timesummary.TimeSummary;
29  import org.kuali.hr.time.util.TKContext;
30  import org.kuali.hr.time.util.TkConstants;
31  import org.kuali.rice.kew.api.KewApiConstants;
32  import org.kuali.rice.kew.doctype.SecuritySession;
33  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
34  import org.kuali.rice.kew.service.KEWServiceLocator;
35  import org.kuali.rice.kim.api.identity.Person;
36  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
37  
38  public class ApprovalTimeSummaryRow implements Comparable<ApprovalTimeSummaryRow> {
39      private String name;
40      private List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>();
41      /** A Map (Assignment key) of Mapped totals (pay label mapping) */
42      private Map<String, Map<String, BigDecimal>> approverHoursByAssignment;
43      /** A Map (Assignment key) of Mapped totals (pay label mapping) */
44      private Map<String, Map<String, BigDecimal>> otherHoursByAssignment;
45      /** A String (AssignmentDescriptionKey) to Description mapping for all assignments on this summary row */
46      private Map<String,String> assignmentDescriptions; // could refactor out to action level call
47  
48      private String approvalStatus;
49      private String approvalStatusMessage;
50      private String documentId;
51      private Map<String,BigDecimal> hoursToPayLabelMap = new HashMap<String,BigDecimal>();
52      private String clockStatusMessage;
53      private String payCalendarGroup;
54      private List notes = new ArrayList();
55      private List<String> warnings = new ArrayList<String>();
56      private Set<String> workAreas;
57      private String principalId;
58      private Boolean clockedInOverThreshold = Boolean.FALSE;
59      private String selected = "off";
60      private TimeSummary timeSummary;
61      private BigDecimal periodTotal = BigDecimal.ZERO;
62  
63      public String getApprovalStatusMessage() {
64          return approvalStatusMessage;
65      }
66  
67      public void setApprovalStatusMessage(String approvalStatusMessage) {
68          this.approvalStatusMessage = approvalStatusMessage;
69      }
70  
71      public Map<String, String> getAssignmentDescriptions() {
72          return assignmentDescriptions;
73      }
74  
75      public void setAssignmentDescriptions(Map<String, String> assignmentDescriptions) {
76          this.assignmentDescriptions = assignmentDescriptions;
77      }
78  
79      public Map<String, Map<String, BigDecimal>> getApproverHoursByAssignment() {
80          return approverHoursByAssignment;
81      }
82  
83      public void setApproverHoursByAssignment(Map<String, Map<String, BigDecimal>> approverHoursByAssignment) {
84          this.approverHoursByAssignment = approverHoursByAssignment;
85      }
86  
87      public Map<String, Map<String, BigDecimal>> getOtherHoursByAssignment() {
88          return otherHoursByAssignment;
89      }
90  
91      public void setOtherHoursByAssignment(Map<String, Map<String, BigDecimal>> otherHoursByAssignment) {
92          this.otherHoursByAssignment = otherHoursByAssignment;
93      }
94  
95      public String getName() {
96          return name;
97      }
98      public void setName(String name) {
99          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 setClockStatusMessage(String clockStatusMessage) {
126         this.clockStatusMessage = clockStatusMessage;
127     }
128     public String getClockStatusMessage() {
129         return clockStatusMessage;
130     }
131 
132     public String getPayCalendarGroup() {
133         return payCalendarGroup;
134     }
135 
136     public void setPayCalendarGroup(String payCalendarGroup) {
137         this.payCalendarGroup = payCalendarGroup;
138     }
139 
140     /**
141      * Is this record initiated?
142      * @return true if initiated, false otherwise.
143      */
144     public boolean isRoutable() {
145         return StringUtils.equals(getApprovalStatus(), TkConstants.ROUTE_STATUS.INITIATED);
146     }
147 
148     /**
149      * Is this record ready to be approved?
150      * @return true if a valid TK_APPROVER / TK_PROCESSOR can approve, false otherwise.
151      */
152     public boolean isApprovable() {
153         boolean isEnroute =  StringUtils.equals(getApprovalStatus(), "ENROUTE") ;
154 
155         if(isEnroute){
156         	DocumentRouteHeaderValue routeHeader = TkServiceLocator.getTimeApproveService().getRouteHeader(this.getDocumentId());
157         	boolean authorized = KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(TKContext.getPrincipalId(), routeHeader, new SecuritySession(TKContext.getPrincipalId()));
158         	if(authorized){
159         		List<String> principalsToApprove = KEWServiceLocator.getActionRequestService().getPrincipalIdsWithPendingActionRequestByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, this.getDocumentId());
160         		if(!principalsToApprove.isEmpty() && principalsToApprove.contains(TKContext.getPrincipalId())){
161             		return true;
162             	}
163         	}
164         }
165         return false;
166     }
167 
168     /**
169      * Helper method to grab the URL parameters for setting target mode for a
170      * user/documentID timesheet. Returns a portion simlar to:
171      *
172      * @return parameter portion of a URL, usable to initiate target mode.
173      */
174     public String getTimesheetUserTargetURLParams() {
175         StringBuffer link = new StringBuffer();
176 
177         link.append("methodToCall=changeTargetPerson");
178         link.append("&documentId=").append(this.getDocumentId());
179         Person person = KimApiServiceLocator.getPersonService().getPerson(this.getPrincipalId());
180         link.append("&principalName=").append(person.getPrincipalName());
181 
182         return link.toString();
183     }
184 
185     public List getNotes() {
186         return notes;
187     }
188 
189     public void setNotes(List notes) {
190         this.notes = notes;
191     }
192 
193     public List<String> getWarnings() {
194         return warnings;
195     }
196 
197     public void setWarnings(List<String> warnings) {
198         this.warnings = warnings;
199     }
200 
201     public Set<String> getWorkAreas() {
202         return workAreas;
203     }
204 
205     public void setWorkAreas(Set<String> workAreas) {
206         this.workAreas = workAreas;
207     }
208 
209     public String getPrincipalId() {
210         return principalId;
211     }
212 
213     public void setPrincipalId(String principalId) {
214         this.principalId = principalId;
215     }
216     public Boolean getClockedInOverThreshold() {
217         return clockedInOverThreshold;
218     }
219     public void setClockedInOverThreshold(Boolean clockedInOverThreshold) {
220         this.clockedInOverThreshold = clockedInOverThreshold;
221     }
222     public String getSelected() {
223         return selected;
224     }
225 
226     public void setSelected(String selected) {
227         this.selected = selected;
228     }
229 
230     public TimeSummary getTimeSummary() {
231         return timeSummary;
232     }
233 
234     public void setTimeSummary(TimeSummary timeSummary) {
235         this.timeSummary = timeSummary;
236     }
237 
238     public BigDecimal getPeriodTotal() {
239         return periodTotal;
240     }
241 
242     public void setPeriodTotal(BigDecimal periodTotal) {
243         this.periodTotal = periodTotal;
244     }
245 
246     public int compareTo(ApprovalTimeSummaryRow row) {
247         return name.compareToIgnoreCase(row.getName());
248     }
249 }