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.time.department.service;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.Properties;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper;
25  import org.kuali.hr.time.department.Department;
26  import org.kuali.hr.time.service.base.TkServiceLocator;
27  import org.kuali.hr.time.util.TKContext;
28  import org.kuali.hr.time.util.TKUtils;
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  public class DepartmentLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
36  	
37  	private static final long serialVersionUID = 566277764259830850L;
38  
39  	@Override
40  	public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
41  		List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
42  		
43  		List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
44  		
45  		Department departmentObj = (Department) businessObject;
46  		String hrDeptId = departmentObj.getHrDeptId();
47          Department dept = TkServiceLocator.getDepartmentService().getDepartment(departmentObj.getDept(), TKUtils.getCurrentDate());
48  		String location = dept == null ? null : dept.getLocation();
49  		String department = departmentObj.getDept();
50  		
51  		boolean systemAdmin = TKContext.getUser().isSystemAdmin();
52  		boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location);
53  		boolean departmentAdmin = TKContext.getUser().getDepartmentAdminAreas().contains(department);
54  		
55  		for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
56  			if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
57  				if (systemAdmin || locationAdmin || departmentAdmin) {
58  					customActionUrls.add(defaultCustomActionUrl);
59  				}
60  			} else {
61  				customActionUrls.add(defaultCustomActionUrl);
62  			}
63  		}
64  
65  		Properties params = new Properties();
66  		params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
67  		params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
68  		params.put("hrDeptId", hrDeptId);
69  		AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
70  		viewUrl.setDisplayText("view");
71  		viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
72  		customActionUrls.add(viewUrl);
73  		
74  		return customActionUrls;
75  	}
76  
77      @SuppressWarnings({"unchecked"})
78      @Override
79      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
80          String dept = fieldValues.get("dept");
81          String location = fieldValues.get("location");
82          String descr = fieldValues.get("description");
83          String active = fieldValues.get("active");
84  
85          List<Department> departments = TkServiceLocator.getDepartmentService().getDepartments(dept, location, descr, active);
86  
87          return departments;
88      }
89  }