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.tklm.time.rules.timecollection.web;
17  
18  import java.math.BigDecimal;
19  import java.util.ArrayList;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.Properties;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.kuali.kpme.core.lookup.KPMELookupableHelperServiceImpl;
26  import org.kuali.kpme.core.util.TKUtils;
27  import org.kuali.kpme.tklm.time.rules.timecollection.TimeCollectionRule;
28  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
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 TimeCollectionRuleLookupableHelperServiceImpl extends KPMELookupableHelperServiceImpl {
38  
39  	private static final long serialVersionUID = -1690980961895784168L;
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  		TimeCollectionRule timeCollectionRule = (TimeCollectionRule) businessObject;
47  		String tkTimeCollectionRuleId = timeCollectionRule.getTkTimeCollectionRuleId();
48  		
49  		Properties params = new Properties();
50  		params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
51  		params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
52  		
53  		params.put("tkTimeCollectionRuleId", tkTimeCollectionRuleId);
54  		
55  		AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
56  		viewUrl.setDisplayText("view");
57  		viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
58  		customActionUrls.add(viewUrl);
59  		
60  		return customActionUrls;
61  	}
62  
63  	@Override
64  	public List<? extends BusinessObject> getSearchResults( Map<String, String> fieldValues) {
65          String workArea = fieldValues.get("workArea");
66          String dept = fieldValues.get("dept");
67          String payType = fieldValues.get("payType");
68          String active = fieldValues.get("active");
69          String history = fieldValues.get("history");
70  
71          String workAreaValue = null;
72          if (StringUtils.equals(workArea,"%") || StringUtils.equals(workArea,"*")){
73              workArea = "";
74          } else {
75          	if(workArea != null && StringUtils.isNotBlank(workArea)) {
76  	        	BigDecimal value = TKUtils.cleanNumeric(workArea);
77  	        	if(value != null) {
78  	        		workAreaValue = value.toString(); 
79  	        	} else {
80  	        		return new ArrayList<TimeCollectionRule>();
81  	        	}
82          	}
83          }
84          
85          return TkServiceLocator.getTimeCollectionRuleService().getTimeCollectionRules(GlobalVariables.getUserSession().getPrincipalId(), dept, workAreaValue, payType, active, history);
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  }