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