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