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