View Javadoc

1   /**
2    * Copyright 2004-2012 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      @SuppressWarnings({"unchecked"})
83      @Override
84      public List<? extends BusinessObject> getSearchResults(
85              Map<String, String> fieldValues) {
86  
87          String principalId = fieldValues.get("principalId");
88          String firstName = fieldValues.get("firstName");
89          String lastName = fieldValues.get("lastName");
90          String jobNumber = fieldValues.get("jobNumber");
91          String dept = fieldValues.get("dept");
92          String positionNumber = fieldValues.get("positionNumber");
93          String hrPayType = fieldValues.get("hrPayType");
94          String fromEffdt = fieldValues.get("rangeLowerBoundKeyPrefix_effectiveDate");
95          String toEffdt = StringUtils.isNotBlank(fieldValues.get("effectiveDate")) ? fieldValues.get("effectiveDate").replace("<=", "") : "";
96          String active = fieldValues.get("active");
97          String showHist = fieldValues.get("history");
98  
99          List<Job> jobs = TkServiceLocator.getJobService().getJobs(principalId, firstName, lastName, jobNumber,
100                 dept, positionNumber, hrPayType,
101                 TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt),
102                 active,  showHist);
103 
104         return jobs;
105 
106 
107 //		String firstName = null;
108 //		String lastName = null;
109 //		if (fieldValues.containsKey("firstName")) {
110 //			firstName = fieldValues.get("firstName");
111 //			fieldValues.remove("firstName");
112 //		}
113 //		if (fieldValues.containsKey("lastName")) {
114 //			lastName = fieldValues.get("lastName");
115 //			fieldValues.remove("lastName");
116 //		}
117 
118 
119 //		if(StringUtils.isNotEmpty(firstName) || StringUtils.isNotEmpty(lastName)){
120 //			Map<String, String> fields = new HashMap<String, String>();
121 //			fields.put("firstName", firstName);
122 //			fields.put("lastName", lastName);
123 //			List<Person> listPerson = KIMServiceLocator.getPersonService()
124 //					.findPeople(fields);
125 //			List<Job> objectList = new ArrayList<Job>();
126 //			for(Person p: listPerson){
127 //				fieldValues.put("principalId", p.getPrincipalId());
128 //				objectList.addAll((Collection<? extends Job>) super.getSearchResults(fieldValues));
129 //			}
130 //			//trim if greater than 300 items
131 //			if(objectList.size() > 300){
132 //				objectList = objectList.subList(0, 299);
133 //			}
134 //			return objectList;
135 //		}
136 
137 //        return super.getSearchResults(fieldValues);
138     }
139 
140     @SuppressWarnings("rawtypes")
141     @Override
142     public HtmlData getReturnUrl(BusinessObject businessObject,
143                                  LookupForm lookupForm, List returnKeys,
144                                  BusinessObjectRestrictions businessObjectRestrictions) {
145         if (lookupForm.getFieldConversions().containsKey("effectiveDate")) {
146             lookupForm.getFieldConversions().remove("effectiveDate");
147         }
148         if (returnKeys.contains("effectiveDate")) {
149             returnKeys.remove("effectiveDate");
150         }
151         return super.getReturnUrl(businessObject, lookupForm, returnKeys,
152                 businessObjectRestrictions);
153     }
154 }