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.task.service;
17  
18  import java.util.List;
19  import java.util.Map;
20  
21  import org.kuali.hr.time.authorization.TkAuthorizedLookupableHelperBase;
22  import org.kuali.hr.time.service.base.TkServiceLocator;
23  import org.kuali.hr.time.util.TKUtils;
24  import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
25  import org.kuali.rice.kns.lookup.HtmlData;
26  import org.kuali.rice.kns.web.struts.form.LookupForm;
27  import org.kuali.rice.kns.web.ui.Field;
28  import org.kuali.rice.kns.web.ui.Row;
29  import org.kuali.rice.krad.bo.BusinessObject;
30  
31  public class TaskLookupableHelper extends TkAuthorizedLookupableHelperBase {
32  
33  	private static final long serialVersionUID = 7525044777337159013L;
34  
35  	@Override
36      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
37          String task = fieldValues.get("task");
38          String description = fieldValues.get("description");
39          String workArea = fieldValues.get("workArea");
40          String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
41          String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
42  
43          return TkServiceLocator.getTaskService().getTasks(task, description, workArea, TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt));
44      }
45  
46      @SuppressWarnings("rawtypes")
47      @Override
48      public HtmlData getReturnUrl(BusinessObject businessObject,
49                                   LookupForm lookupForm, List returnKeys,
50                                   BusinessObjectRestrictions businessObjectRestrictions) {
51          if (lookupForm.getFieldConversions().containsKey("effectiveDate")) {
52              lookupForm.getFieldConversions().remove("effectiveDate");
53          }
54          if (returnKeys.contains("effectiveDate")) {
55              returnKeys.remove("effectiveDate");
56          }
57          if (lookupForm.getFieldConversions().containsKey("workArea")) {
58              lookupForm.getFieldConversions().remove("workArea");
59          }
60          if (returnKeys.contains("workArea")) {
61              returnKeys.remove("workArea");
62          }
63  
64          return super.getReturnUrl(businessObject, lookupForm, returnKeys,
65                  businessObjectRestrictions);
66      }
67  
68      @Override
69      // remove the default value for Task for lookup
70      public List<Row> getRows() {
71          List<Row> rowList = super.getRows();
72          for (Row aRow : rowList) {
73              List<Field> fields = aRow.getFields();
74              for (Field aField : fields) {
75                  if (aField.getFieldLabel() != null && aField.getFieldLabel().equals("Task")) {
76                      if (aField.getPropertyValue() != null && aField.getPropertyValue().equals("0")) {
77                          aField.setPropertyValue("");
78                      }
79                  }
80              }
81          }
82          return rowList;
83      }
84  
85      @Override
86      public boolean shouldShowBusinessObject(BusinessObject bo) {
87          return true;
88      }
89  }