View Javadoc
1   package org.kuali.ole.deliver.lookup;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.deliver.calendar.bo.OleCalendar;
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: asham
24   * Date: 8/20/13
25   * Time: 4:37 PM
26   * To change this template use File | Settings | File Templates.
27   */
28  public class OleCalendarLookupableImpl extends LookupableImpl {
29      @Override
30      protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
31          List<?> searchResults;
32          List<OleCalendar> finalSearchResult = new ArrayList<OleCalendar>();
33          List<OleCalendar> oleCalendar = new ArrayList<OleCalendar>();
34          oleCalendar = (List<OleCalendar>) super.getSearchResults(form, searchCriteria, unbounded);
35          finalSearchResult.addAll(oleCalendar);
36  
37          searchResults = finalSearchResult;
38          if (searchResults.size() == 0) {
39              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
40          }
41          sortSearchResults(form, searchResults);
42          return searchResults;
43      }
44  
45      @Override
46      protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall,
47                                        List<String> pkNames) {
48  //        LOG.debug("Inside getActionUrlHref()");
49          LookupView lookupView = (LookupView) lookupForm.getView();
50  
51          Properties props = new Properties();
52          props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
53          Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
54          for (String primaryKey : primaryKeyValues.keySet()) {
55              String primaryKeyValue = primaryKeyValues.get(primaryKey);
56  
57              props.put(primaryKey, primaryKeyValue);
58          }
59  
60          if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
61              props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
62          }
63  
64          props.put(UifParameters.DATA_OBJECT_CLASS_NAME, OleCalendar.class.getName());
65          props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
66  
67          String maintenanceMapping = OLEConstants.CALENDAR_MAINTENANCE_ACTION_LINK;
68  
69          return UrlFactory.parameterizeUrl(maintenanceMapping, props);
70      }
71  }