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.hr.lm.leavecode.service;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.hr.lm.leavecode.LeaveCode;
23  import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper;
24  import org.kuali.hr.time.util.TKContext;
25  import org.kuali.rice.kns.lookup.HtmlData;
26  import org.kuali.rice.krad.bo.BusinessObject;
27  
28  /**
29   * Used to override lookup functionality for the leave accrual category lookup
30   * 
31   * 
32   */
33  public class LeaveCodeLookupableHelper extends
34  		HrEffectiveDateActiveLookupableHelper {
35  	/**
36  	 * 
37  	 */
38  	private static final long serialVersionUID = 1L;
39  
40  	@Override
41  	public List<HtmlData> getCustomActionUrls(BusinessObject businessObject,
42  			List pkNames) {
43  		List<HtmlData> customActionUrls = super.getCustomActionUrls(
44  				businessObject, pkNames);
45  			List<HtmlData> overrideUrls = new ArrayList<HtmlData>();
46  			for(HtmlData actionUrl : customActionUrls){
47  				if(!StringUtils.equals(actionUrl.getMethodToCall(), "copy")){
48  					overrideUrls.add(actionUrl);
49  				}
50  			}
51  
52  		if (TKContext.getUser().isSystemAdmin()) {
53  			LeaveCode leaveCode = (LeaveCode) businessObject;
54  			final String className = this.getBusinessObjectClass().getName();
55  			final String lmLeaveCodeId = leaveCode
56  					.getLmLeaveCodeId();
57  			HtmlData htmlData = new HtmlData() {
58  
59  				@Override
60  				public String constructCompleteHtmlTag() {
61  					return "<a target=\"_blank\" href=\"inquiry.do?businessObjectClassName="
62  							+ className
63  							+ "&methodToCall=start&lmLeaveCodeId="
64  							+ lmLeaveCodeId + "\">view</a>";
65  				}
66  			};
67  			overrideUrls.add(htmlData);
68  		} else if (overrideUrls.size() != 0) {
69  			overrideUrls.remove(0);
70  		}
71  		return overrideUrls;
72  	}
73  
74  }