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.kpme.core.location.web;
17  
18  import java.util.List;
19  import java.util.Map;
20  import java.util.Properties;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.joda.time.DateTime;
24  import org.kuali.kpme.core.KPMENamespace;
25  import org.kuali.kpme.core.location.Location;
26  import org.kuali.kpme.core.lookup.KPMELookupableHelper;
27  import org.kuali.kpme.core.role.KPMERole;
28  import org.kuali.kpme.core.service.HrServiceLocator;
29  import org.kuali.rice.kns.lookup.HtmlData;
30  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
31  import org.kuali.rice.krad.bo.BusinessObject;
32  import org.kuali.rice.krad.util.GlobalVariables;
33  import org.kuali.rice.krad.util.KRADConstants;
34  import org.kuali.rice.krad.util.UrlFactory;
35  
36  @SuppressWarnings("deprecation")
37  public class LocationLookupableHelper extends KPMELookupableHelper {
38  
39  	private static final long serialVersionUID = 1285833127534968764L;
40  
41  	@Override
42  	@SuppressWarnings("rawtypes")
43  	public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
44  		List<HtmlData> customActionUrls = super.getCustomActionUrls(businessObject, pkNames);
45  
46  		Location locationObj = (Location) businessObject;
47  		String hrLocationId = locationObj.getHrLocationId();
48  		Properties params = new Properties();
49  		params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
50  		params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
51  		params.put("hrLocationId", hrLocationId);
52  		AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
53  		viewUrl.setDisplayText("view");
54  		viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
55  		customActionUrls.add(viewUrl);
56  		
57  		return customActionUrls;
58  	}
59  
60      @Override
61      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
62          String location = fieldValues.get("location");
63          String descr = fieldValues.get("description");
64          String active = fieldValues.get("active");
65          String showHist = fieldValues.get("history");
66  
67          if (StringUtils.contains(location, "*")) {
68          	location = "";
69  		}
70  		
71          return HrServiceLocator.getLocationService().searchLocations(GlobalVariables.getUserSession().getPrincipalId(), location, descr, active, showHist);
72      }
73      
74      @Override
75  	protected void validateSearchParameterWildcardAndOperators(
76  			String attributeName, String attributeValue) {
77  		if (!StringUtils.equals(attributeValue, "*")) {
78  			super.validateSearchParameterWildcardAndOperators(attributeName,
79  					attributeValue);
80  		}
81  	}
82      
83  }