View Javadoc

1   /**
2    * Copyright 2004-2014 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.kpme.pm.position.web;
17  
18  import java.util.List;
19  import java.util.Map;
20  import java.util.Properties;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.kpme.core.lookup.KPMELookupableImpl;
24  import org.kuali.kpme.core.util.TKUtils;
25  import org.kuali.kpme.pm.position.Position;
26  import org.kuali.kpme.pm.service.base.PmServiceLocator;
27  import org.kuali.rice.core.api.config.property.ConfigContext;
28  import org.kuali.rice.krad.uif.UifConstants;
29  import org.kuali.rice.krad.uif.UifParameters;
30  import org.kuali.rice.krad.uif.element.Action;
31  import org.kuali.rice.krad.uif.util.LookupInquiryUtils;
32  import org.kuali.rice.krad.uif.view.LookupView;
33  import org.kuali.rice.krad.util.KRADConstants;
34  import org.kuali.rice.krad.util.KRADUtils;
35  import org.kuali.rice.krad.util.UrlFactory;
36  import org.kuali.rice.krad.web.form.LookupForm;
37  
38  public class PositionLookupableImpl extends KPMELookupableImpl {
39  
40  	private static final long serialVersionUID = 8658536323175048980L;
41  
42  	@Override
43      protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
44      	String positionNum = searchCriteria.get("positionNumber");
45          String description = searchCriteria.get("description");
46          String workingPositionTitle = searchCriteria.get("workingPositionTitle");
47          String campus = searchCriteria.get("campus");
48          String institution = searchCriteria.get("institution");
49          String classificationTitle = searchCriteria.get("classificationTitle");
50          String positionType = searchCriteria.get("positionType");
51          String poolEligible = searchCriteria.get("poolEligible");
52          String fromEffdt = TKUtils.getFromDateString(searchCriteria.get("effectiveDate"));
53          String toEffdt = TKUtils.getToDateString(searchCriteria.get("effectiveDate"));
54          String active = searchCriteria.get("active");
55          String showHist = searchCriteria.get("history");
56  
57          if (StringUtils.equals(positionNum, "%")) {
58              positionNum = "";
59          }
60          
61          return PmServiceLocator.getPositionService().getPositions(positionNum, description, workingPositionTitle, campus,
62                  institution, classificationTitle, positionType, poolEligible, TKUtils.formatDateString(fromEffdt),
63                  TKUtils.formatDateString(toEffdt), active, showHist);	
64      }  
65  	
66  	@Override
67      protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall, List<String> pkNames) {
68  		if (!StringUtils.equals(methodToCall, "maintenanceEdit")) {
69  			return super.getActionUrlHref(lookupForm, dataObject, methodToCall, pkNames);
70  		} else {
71  			Properties urlParameters = new Properties();
72  
73  	        urlParameters.setProperty(UifParameters.DATA_OBJECT_CLASS_NAME, dataObject.getClass().getName());
74  	        urlParameters.setProperty(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.START);
75  	        
76  	        Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
77  	        for (String primaryKey : primaryKeyValues.keySet()) {
78  	            String primaryKeyValue = primaryKeyValues.get(primaryKey);
79  
80  	            urlParameters.put(primaryKey, primaryKeyValue);
81  	        }
82  	       	        
83  	        String path = ConfigContext.getCurrentContextConfig().getProperty("application.url");
84  	        String hrefPrefix = path + "/portal.do?channelTitle=ProcessMaint&channelUrl=" + path + "/ProcessMaint.do";
85  	        Position aPosition = (Position) dataObject;
86  	        String paramString = "?positionId=" + aPosition.getHrPositionId();
87  	        return (hrefPrefix + paramString);
88  		}
89      }
90  
91      @Override
92      public void initSuppressAction(LookupForm lookupForm) {
93      /*
94       * lookupAuthorizer.canInitiateDocument(lookupForm, user) returns false in this instance, because no
95       * documentTypeName can be obtained within LookupViewAuthorizeBase.canInitiateDocument(LookupForm, Person).
96       */
97          ((LookupView) lookupForm.getView()).setSuppressActions(false);
98      }
99  }