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.institution.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.LocalDate;
24  import org.kuali.kpme.core.bo.HrEffectiveDateActiveLookupableHelper;
25  import org.kuali.kpme.core.institution.Institution;
26  import org.kuali.kpme.core.job.Job;
27  import org.kuali.kpme.core.lookup.KPMELookupableHelper;
28  import org.kuali.kpme.core.service.HrServiceLocator;
29  import org.kuali.kpme.core.util.TKUtils;
30  import org.kuali.rice.kns.lookup.HtmlData;
31  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
32  import org.kuali.rice.krad.bo.BusinessObject;
33  import org.kuali.rice.krad.util.KRADConstants;
34  import org.kuali.rice.krad.util.UrlFactory;
35  
36  @SuppressWarnings("deprecation")
37  public class InstitutionLookupableHelper extends HrEffectiveDateActiveLookupableHelper{
38  
39  	/**
40  	 * 
41  	 */
42  	private static final long serialVersionUID = 5277378871669021091L;
43  
44  	@Override
45  	public List<? extends BusinessObject> getSearchResults(
46  			Map<String, String> fieldValues) {
47  		if (StringUtils.contains(fieldValues.get("institutionCode"), "*")) {
48  			fieldValues.put("institutionCode","");			
49  		}
50  		
51  		String institutionCode = fieldValues.get("institutionCode");
52          String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
53          String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
54          String active = fieldValues.get("active");
55          String showHistory = fieldValues.get("history");
56          
57  		return HrServiceLocator.getInstitutionService().getInstitutions(TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt), institutionCode, active, showHistory);
58  	}
59  
60  	@Override
61  	public List<HtmlData> getCustomActionUrls(BusinessObject businessObject,
62  			List pkNames) {
63      	List<HtmlData> customActionUrls = super.getCustomActionUrls(businessObject, pkNames);
64  
65  		Institution institution = (Institution) businessObject;
66          String pmInstitutionId = institution.getPmInstitutionId();
67  		
68  		Properties params = new Properties();
69  		params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
70  		params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
71  		
72  		params.put("pmInstitutionId", pmInstitutionId);
73  		
74  		AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
75  		viewUrl.setDisplayText("view");
76  		viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
77  		customActionUrls.add(viewUrl);
78  		
79  		return customActionUrls;
80  	}
81  
82  	@Override
83  	protected void validateSearchParameterWildcardAndOperators(
84  			String attributeName, String attributeValue) {
85  		if (!StringUtils.equals(attributeValue, "*")) {
86  			super.validateSearchParameterWildcardAndOperators(attributeName,
87  					attributeValue);
88  		}
89  	}
90  	
91  
92  }