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.core.lookup;
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.bo.HrBusinessObject;
24  import org.kuali.kpme.core.util.HrContext;
25  import org.kuali.rice.kns.lookup.HtmlData;
26  import org.kuali.rice.krad.lookup.LookupableImpl;
27  import org.kuali.rice.krad.uif.UifConstants;
28  import org.kuali.rice.krad.uif.UifParameters;
29  import org.kuali.rice.krad.util.KRADConstants;
30  import org.kuali.rice.krad.util.KRADUtils;
31  import org.kuali.rice.krad.util.UrlFactory;
32  import org.kuali.rice.krad.web.form.LookupForm;
33  
34  public class KPMELookupableImpl extends LookupableImpl {
35  
36  	private static final long serialVersionUID = 7098170370881970354L;
37  
38  	@Override
39      protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall, List<String> pkNames) {
40  		if (!StringUtils.equals(methodToCall, "maintenanceView")) {
41  			return super.getActionUrlHref(lookupForm, dataObject, methodToCall, pkNames);
42  		} else {
43  			Properties urlParameters = new Properties();
44  
45  	        urlParameters.setProperty(UifParameters.DATA_OBJECT_CLASS_NAME, dataObject.getClass().getName());
46  	        urlParameters.setProperty(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.START);
47  	        
48  	        Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
49  	        for (String primaryKey : primaryKeyValues.keySet()) {
50  	            String primaryKeyValue = primaryKeyValues.get(primaryKey);
51  
52  	            urlParameters.put(primaryKey, primaryKeyValue);
53  	        }
54  	        
55  	        return UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, urlParameters);
56  		}
57      }
58  
59      // KPME-2699 editing inactive records is only allowed for admins
60      @Override
61      public boolean allowsMaintenanceEditAction(Object dataObject) {
62          boolean allowsEdit = super.allowsMaintenanceEditAction(dataObject);
63          if (dataObject instanceof HrBusinessObject) {
64              HrBusinessObject bo = (HrBusinessObject) dataObject;
65              if (!bo.isActive()) {
66                  if (!HrContext.canEditInactiveRecords()) {
67                      allowsEdit = false;
68                  }
69              }
70          }
71          return allowsEdit;
72      }
73  }