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.task.service;
17  
18  import java.util.List;
19  import java.util.Map;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.hr.time.authorization.TkAuthorizedLookupableHelperBase;
23  import org.kuali.hr.time.service.base.TkServiceLocator;
24  import org.kuali.hr.time.task.Task;
25  import org.kuali.hr.time.util.TKUtils;
26  import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
27  import org.kuali.rice.kns.lookup.HtmlData;
28  import org.kuali.rice.kns.web.struts.form.LookupForm;
29  import org.kuali.rice.kns.web.ui.Field;
30  import org.kuali.rice.kns.web.ui.Row;
31  import org.kuali.rice.krad.bo.BusinessObject;
32  
33  public class TaskLookupableHelper extends TkAuthorizedLookupableHelperBase {
34      /**
35       *
36       */
37      private static final long serialVersionUID = 1L;
38  
39      @SuppressWarnings({"unchecked"})
40      @Override
41      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
42  
43          String task = fieldValues.get("task");
44          String description = fieldValues.get("description");
45          String workArea = fieldValues.get("workArea");
46          String workAreaDescription = fieldValues.get("workAreaDescription");
47          String fromEffdt = fieldValues.get("rangeLowerBoundKeyPrefix_effectiveDate");
48          String toEffdt = StringUtils.isNotBlank(fieldValues.get("effectiveDate")) ? fieldValues.get("effectiveDate").replace("<=", "") : "";
49  
50          List<Task> tasks = TkServiceLocator.getTaskService().getTasks(task, description, workArea, workAreaDescription,
51                  TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt));
52  
53          return tasks;
54  //		List finalList = new ArrayList<Task>();
55  //		String wad = "";
56  //		String wa = "";
57  //		List<String> taskFound = new ArrayList<String>();
58  //		if (fieldValues.containsKey("workAreaDescription") && !fieldValues.get("workAreaDescription").isEmpty()) {
59  //			wad = fieldValues.get("workAreaDescription");
60  //			fieldValues.remove("workAreaDescription");
61  //		}
62  //		if(fieldValues.containsKey("workArea") && !fieldValues.get("workArea").isEmpty()) {
63  //			wa = fieldValues.get("workArea");
64  //			fieldValues.remove("workArea");
65  //		}
66  //		List aList = super.getSearchResults(fieldValues);
67  //
68  //		for(int i = 0; i< aList.size(); i++) {
69  //			Task aTask = (Task) aList.get(i);
70  //			if(aTask.getTkWorkAreaId() != null) {
71  //				WorkArea aWorkArea = TkServiceLocator.getWorkAreaService().getWorkArea(aTask.getTkWorkAreaId());
72  //				if(aWorkArea != null) {
73  //					if( (StringUtils.isBlank(wa) || aWorkArea.getWorkArea().toString().equals(wa))
74  //							|| (StringUtils.isBlank(wad) || aWorkArea.getDescription().equals(wad))) {
75  //						if(!taskFound.contains(aWorkArea.getWorkArea() + "_"+aTask.getTask())   ){
76  //							finalList.add(aTask);
77  //							taskFound.add(aWorkArea.getWorkArea() +"_"+aTask.getTask());
78  //						}
79  //					}
80  //				}
81  //			}
82  //		}
83  
84  //        return finalList;
85      }
86  
87      @SuppressWarnings("rawtypes")
88      @Override
89      public HtmlData getReturnUrl(BusinessObject businessObject,
90                                   LookupForm lookupForm, List returnKeys,
91                                   BusinessObjectRestrictions businessObjectRestrictions) {
92          if (lookupForm.getFieldConversions().containsKey("effectiveDate")) {
93              lookupForm.getFieldConversions().remove("effectiveDate");
94          }
95          if (returnKeys.contains("effectiveDate")) {
96              returnKeys.remove("effectiveDate");
97          }
98          if (lookupForm.getFieldConversions().containsKey("workArea")) {
99              lookupForm.getFieldConversions().remove("workArea");
100         }
101         if (returnKeys.contains("workArea")) {
102             returnKeys.remove("workArea");
103         }
104 
105         return super.getReturnUrl(businessObject, lookupForm, returnKeys,
106                 businessObjectRestrictions);
107     }
108 
109     @Override
110     // remove the default value for Task for lookup
111     public List<Row> getRows() {
112         List<Row> rowList = super.getRows();
113         for (Row aRow : rowList) {
114             List<Field> fields = aRow.getFields();
115             for (Field aField : fields) {
116                 if (aField.getFieldLabel() != null && aField.getFieldLabel().equals("Task")) {
117                     if (aField.getPropertyValue() != null && aField.getPropertyValue().equals("0")) {
118                         aField.setPropertyValue("");
119                     }
120                 }
121             }
122         }
123         return rowList;
124     }
125 
126     @Override
127     public boolean shouldShowBusinessObject(BusinessObject bo) {
128         return true;
129     }
130 }