001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.job.service;
017
018 import java.util.ArrayList;
019 import java.util.List;
020 import java.util.Map;
021 import java.util.Properties;
022
023 import org.apache.commons.lang.StringUtils;
024 import org.kuali.hr.job.Job;
025 import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper;
026 import org.kuali.hr.time.service.base.TkServiceLocator;
027 import org.kuali.hr.time.util.TKContext;
028 import org.kuali.hr.time.util.TKUtils;
029 import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
030 import org.kuali.rice.kns.lookup.HtmlData;
031 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
032 import org.kuali.rice.kns.web.struts.form.LookupForm;
033 import org.kuali.rice.krad.bo.BusinessObject;
034 import org.kuali.rice.krad.util.KRADConstants;
035 import org.kuali.rice.krad.util.UrlFactory;
036
037 public class JobLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
038
039 private static final long serialVersionUID = 3233495722838070429L;
040
041 @Override
042 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
043 List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
044
045 List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
046
047 Job job = (Job) businessObject;
048 String hrJobId = job.getHrJobId();
049 String jobNumber = String.valueOf(job.getJobNumber());
050 String principalId = job.getPrincipalId();
051 String location = job.getLocation();
052 String department = job.getDept();
053
054 boolean systemAdmin = TKContext.getUser().isSystemAdmin();
055 boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location);
056 boolean departmentAdmin = TKContext.getUser().getDepartmentAdminAreas().contains(department);
057
058 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
059 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
060 if (systemAdmin || locationAdmin || departmentAdmin) {
061 customActionUrls.add(defaultCustomActionUrl);
062 }
063 } else {
064 customActionUrls.add(defaultCustomActionUrl);
065 }
066 }
067
068 Properties params = new Properties();
069 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
070 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
071 params.put("hrJobId", hrJobId);
072 params.put("jobNumber", jobNumber);
073 params.put("principalId", principalId);
074 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
075 viewUrl.setDisplayText("view");
076 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
077 customActionUrls.add(viewUrl);
078
079 return customActionUrls;
080 }
081
082 @Override
083 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
084 String principalId = fieldValues.get("principalId");
085 String firstName = fieldValues.get("firstName");
086 String lastName = fieldValues.get("lastName");
087 String jobNumber = fieldValues.get("jobNumber");
088 String dept = fieldValues.get("dept");
089 String positionNumber = fieldValues.get("positionNumber");
090 String hrPayType = fieldValues.get("hrPayType");
091 String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
092 String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
093 String active = fieldValues.get("active");
094 String showHist = fieldValues.get("history");
095
096 return TkServiceLocator.getJobService().getJobs(principalId, firstName, lastName, jobNumber, dept, positionNumber, hrPayType,
097 TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt), active, showHist);
098 }
099
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 }