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.missedpunch;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.hr.time.service.base.TkServiceLocator;
24  import org.kuali.hr.time.timesheet.TimesheetDocument;
25  import org.kuali.hr.time.util.TKContext;
26  import org.kuali.hr.time.util.TkConstants;
27  import org.kuali.rice.core.api.util.ConcreteKeyValue;
28  import org.kuali.rice.core.api.util.KeyValue;
29  import org.kuali.rice.kns.web.struts.form.KualiForm;
30  import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
31  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
32  
33  public class MissedPunchAssignmentFinder extends KeyValuesBase {
34  
35      @Override
36      /**
37       * The KeyLabelPair values returned match up with the data the current
38       * user would get if they were selecting assignments from their clock.
39       *
40       * NOTE: These are Clock-Only assignments.
41       */
42      public List getKeyValues() {
43          List<KeyValue> labels = new ArrayList<KeyValue>();
44          String tdocId = "";
45          String mpDocId = (String)TKContext.getHttpServletRequest().getParameter(TkConstants.DOCUMENT_ID_REQUEST_NAME);
46          if(StringUtils.isBlank(mpDocId)){
47          	KualiForm kualiForm = (KualiForm)TKContext.getHttpServletRequest().getAttribute("KualiForm");
48          	if(kualiForm instanceof KualiTransactionalDocumentFormBase){
49          		mpDocId = ((KualiTransactionalDocumentFormBase)kualiForm).getDocId();
50          	}
51          }
52          
53          if(StringUtils.isBlank(mpDocId)){
54             tdocId = TKContext.getHttpServletRequest().getParameter(TkConstants.TIMESHEET_DOCUMENT_ID_REQUEST_NAME);   
55          }
56          
57          if(StringUtils.isNotBlank(mpDocId)){
58          	MissedPunchDocument mp = TkServiceLocator.getMissedPunchService().getMissedPunchByRouteHeader(mpDocId);
59          	if(mp != null) {
60          		tdocId = mp.getTimesheetDocumentId();
61          	}
62          }
63          
64          mpDocId = (String)TKContext.getHttpServletRequest().getParameter("docId");
65          if(StringUtils.isNotBlank(mpDocId)){
66          	MissedPunchDocument mp = TkServiceLocator.getMissedPunchService().getMissedPunchByRouteHeader(mpDocId);
67          	if(mp != null) {
68          		tdocId = mp.getTimesheetDocumentId();
69          	}
70          }
71          
72          if(StringUtils.isBlank(tdocId)) {
73          	tdocId = (String) TKContext.getHttpServletRequest().getAttribute(TkConstants.TIMESHEET_DOCUMENT_ID_REQUEST_NAME);   
74          }
75          
76          if (tdocId != null) {
77              TimesheetDocument tdoc = TkServiceLocator.getTimesheetService().getTimesheetDocument(tdocId);
78              Map<String,String> adMap = TkServiceLocator.getAssignmentService().getAssignmentDescriptions(tdoc, true); // Grab clock only assignments
79  
80              for (Map.Entry entry : adMap.entrySet()) {
81                  labels.add(new ConcreteKeyValue((String)entry.getKey(), (String)entry.getValue()));
82              }
83          } 
84  
85          return labels;
86      }
87  }
88