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.job.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.job.Job;
25  import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper;
26  import org.kuali.hr.time.service.base.TkServiceLocator;
27  import org.kuali.hr.time.util.TKContext;
28  import org.kuali.hr.time.util.TKUser;
29  import org.kuali.hr.time.util.TKUtils;
30  import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
31  import org.kuali.rice.kns.lookup.HtmlData;
32  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
33  import org.kuali.rice.kns.web.struts.form.LookupForm;
34  import org.kuali.rice.krad.bo.BusinessObject;
35  import org.kuali.rice.krad.util.KRADConstants;
36  import org.kuali.rice.krad.util.UrlFactory;
37  
38  public class JobLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
39  
40  	private static final long serialVersionUID = 3233495722838070429L;
41  
42  	@Override
43      public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
44      	List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
45  		
46  		List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
47          
48  		Job job = (Job) businessObject;
49          String hrJobId = job.getHrJobId();
50          String jobNumber = String.valueOf(job.getJobNumber());
51          String principalId = job.getPrincipalId();
52          String location = job.getLocation();
53          String department = job.getDept();
54          
55          boolean systemAdmin = TKUser.isSystemAdmin();
56  		boolean locationAdmin = TKUser.getLocationAdminAreas().contains(location);
57  		boolean departmentAdmin = TKUser.getDepartmentAdminAreas().contains(department);
58  		
59  		for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
60  			if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
61  				if (systemAdmin || locationAdmin || departmentAdmin) {
62  					customActionUrls.add(defaultCustomActionUrl);
63  				}
64  			} else {
65  				customActionUrls.add(defaultCustomActionUrl);
66  			}
67  		}
68  		
69  		Properties params = new Properties();
70  		params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
71  		params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
72  		params.put("hrJobId", hrJobId);
73  		params.put("jobNumber", jobNumber);
74  		params.put("principalId", principalId);
75  		AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
76  		viewUrl.setDisplayText("view");
77  		viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
78  		customActionUrls.add(viewUrl);
79  		
80  		return customActionUrls;
81      }
82  
83      @Override
84      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
85          String principalId = fieldValues.get("principalId");
86          String firstName = fieldValues.get("firstName");
87          String lastName = fieldValues.get("lastName");
88          String jobNumber = fieldValues.get("jobNumber");
89          String dept = fieldValues.get("dept");
90          String positionNumber = fieldValues.get("positionNumber");
91          String hrPayType = fieldValues.get("hrPayType");
92          String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
93          String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
94          String active = fieldValues.get("active");
95          String showHist = fieldValues.get("history");
96  
97          return TkServiceLocator.getJobService().getJobs(principalId, firstName, lastName, jobNumber, dept, positionNumber, hrPayType, 
98          		TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt), active, showHist);
99      }
100 
101     @SuppressWarnings("rawtypes")
102     @Override
103     public HtmlData getReturnUrl(BusinessObject businessObject,
104                                  LookupForm lookupForm, List returnKeys,
105                                  BusinessObjectRestrictions businessObjectRestrictions) {
106         if (lookupForm.getFieldConversions().containsKey("effectiveDate")) {
107             lookupForm.getFieldConversions().remove("effectiveDate");
108         }
109         if (returnKeys.contains("effectiveDate")) {
110             returnKeys.remove("effectiveDate");
111         }
112         return super.getReturnUrl(businessObject, lookupForm, returnKeys,
113                 businessObjectRestrictions);
114     }
115 }