View Javadoc
1   package org.kuali.ole.describe.lookup;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.describe.bo.OleShelvingScheme;
6   import org.kuali.rice.krad.lookup.LookupableImpl;
7   import org.kuali.rice.krad.uif.UifConstants;
8   import org.kuali.rice.krad.uif.UifParameters;
9   import org.kuali.rice.krad.uif.view.LookupView;
10  import org.kuali.rice.krad.util.GlobalVariables;
11  import org.kuali.rice.krad.util.KRADConstants;
12  import org.kuali.rice.krad.util.KRADUtils;
13  import org.kuali.rice.krad.util.UrlFactory;
14  import org.kuali.rice.krad.web.form.LookupForm;
15  
16  import java.util.ArrayList;
17  import java.util.List;
18  import java.util.Map;
19  import java.util.Properties;
20  
21  /**
22   * Created with IntelliJ IDEA.
23   * User: ?
24   * Date: 1/24/13
25   * Time: 5:58 PM
26   * To change this template use File | Settings | File Templates.
27   */
28  public class OleShelvingSchemeLookupableImpl extends LookupableImpl {
29      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleInstanceItemTypeLookupableImpl.class);
30  
31  
32      /**
33       * Generates a URL to perform a maintenance action on the given result data object
34       * <p/>
35       * <p>
36       * Will build a URL containing keys of the data object to invoke the given maintenance action method
37       * within the maintenance controller
38       * </p>
39       *
40       * @param dataObject   - data object instance for the line to build the maintenance action link for
41       * @param methodToCall - method name on the maintenance controller that should be invoked
42       * @param pkNames      - list of primary key field names for the data object whose key/value pairs will be added to
43       *                     the maintenance link
44       * @return String URL link for the maintenance action
45       */
46      protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall,
47                                        List<String> pkNames) {
48          LookupView lookupView = (LookupView) lookupForm.getView();
49          Properties props = new Properties();
50          props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
51  
52          Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
53          for (String primaryKey : primaryKeyValues.keySet()) {
54              String primaryKeyValue = primaryKeyValues.get(primaryKey);
55  
56              props.put(primaryKey, primaryKeyValue);
57          }
58  
59          if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
60              props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
61          }
62  
63          props.put(UifParameters.DATA_OBJECT_CLASS_NAME, lookupForm.getDataObjectClassName());
64          props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
65  
66          String maintenanceMapping = "shelvingSchemeMaintenance";
67  
68          return UrlFactory.parameterizeUrl(maintenanceMapping, props);
69      }
70  
71      @Override
72      protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
73          List<?> searchResults;
74          List<OleShelvingScheme> finalSearchResult = new ArrayList<OleShelvingScheme>();
75          List<OleShelvingScheme> oleShelvingScheme = new ArrayList<OleShelvingScheme>();
76  
77  
78          oleShelvingScheme = (List<OleShelvingScheme>) super.getSearchResults(form, searchCriteria, unbounded);
79          finalSearchResult.addAll(oleShelvingScheme);
80  
81          searchResults = finalSearchResult;
82          if (searchResults.size() == 0) {
83              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
84          }
85          sortSearchResults(form, searchResults);
86          return searchResults;
87      }
88  }