View Javadoc

1   /**
2    * Copyright 2004-2013 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.assignment;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.kuali.hr.time.service.base.TkServiceLocator;
23  import org.kuali.hr.time.timesheet.TimesheetDocument;
24  import org.kuali.hr.time.util.TKContext;
25  import org.kuali.hr.time.util.TkConstants;
26  import org.kuali.rice.core.api.util.ConcreteKeyValue;
27  import org.kuali.rice.core.api.util.KeyValue;
28  import org.kuali.rice.kns.web.struts.form.KualiForm;
29  import org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm;
30  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
31  
32  /**
33   * AssignmentValuesFinder provides the values for the MissedPunch maintenance
34   * document's Assignment selection.
35   *
36   * NOTE: Clock only assignments.
37   */
38  public class AssignmentValuesFinder extends KeyValuesBase {
39  
40      @Override
41      /**
42       * The KeyLabelPair values returned match up with the data the current
43       * user would get if they were selecting assignments from their clock.
44       *
45       * NOTE: These are Clock-Only assignments.
46       */
47      public List getKeyValues() {
48          List<KeyValue> labels = new ArrayList<KeyValue>();
49  
50          // We need the current timesheet document id. depending on where this
51          // was set up, we may need to look in two different places. Primarily
52          // we look directly at the context's function.
53          
54          String tdocId = TKContext.getCurrentTimesheetDocumentId();
55          if (tdocId == null) {
56              tdocId = TKContext.getHttpServletRequest().getParameter(TkConstants.TIMESHEET_DOCUMENT_ID_REQUEST_NAME);
57          }
58          if(tdocId == null){
59          	KualiForm kualiForm = (KualiForm)TKContext.getHttpServletRequest().getAttribute("KualiForm");
60          	if(kualiForm instanceof KualiMaintenanceForm){
61          		tdocId = ((KualiMaintenanceForm)kualiForm).getDocId();
62          	}
63          }
64          
65          
66          if (tdocId != null) {
67              TimesheetDocument tdoc = TkServiceLocator.getTimesheetService().getTimesheetDocument(tdocId);
68              Map<String,String> adMap = TkServiceLocator.getAssignmentService().getAssignmentDescriptions(tdoc, true); // Grab clock only assignments
69  
70              for (Map.Entry entry : adMap.entrySet()) {
71                  labels.add(new ConcreteKeyValue((String)entry.getKey(), (String)entry.getValue()));
72              }
73          } 
74  
75          return labels;
76      }
77  }