View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 1.0 (the
5    * "License"); 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/ecl1.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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package org.kuali.student.enrollment.class1.check.controller;
17  
18  import org.apache.commons.lang.BooleanUtils;
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.krad.datadictionary.DataObjectEntry;
21  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22  import org.kuali.rice.krad.uif.UifConstants;
23  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
24  import org.kuali.rice.krad.util.KRADConstants;
25  import org.kuali.rice.krad.web.controller.LookupController;
26  import org.kuali.rice.krad.web.form.LookupForm;
27  import org.kuali.student.enrollment.uif.view.KSLookupView;
28  import org.springframework.stereotype.Controller;
29  import org.springframework.validation.BindingResult;
30  import org.springframework.web.bind.annotation.ModelAttribute;
31  import org.springframework.web.bind.annotation.RequestMapping;
32  import org.springframework.web.servlet.ModelAndView;
33  
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.http.HttpServletResponse;
36  import java.util.List;
37  import java.util.Properties;
38  /**
39   * This controller handles all the request from Academic calendar UI.
40   *
41   * @author Kuali Student Team
42   */
43  
44  @Controller
45  @RequestMapping(value = "/checkLookup")
46  public class CheckInfolookupController extends LookupController {
47  
48          private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CheckInfolookupController.class);
49  
50          /**
51           * Overrides the KRAD search functionality to perform redirect on single search result.
52           */
53          @RequestMapping(params = "methodToCall=search")
54          public ModelAndView search(@ModelAttribute("KualiForm") LookupForm lookupForm, BindingResult result,
55                                     HttpServletRequest request, HttpServletResponse response) {
56              lookupForm.setRenderedInLightBox(true);
57              ModelAndView modelAndView = super.search(lookupForm,result,request,response);
58  
59              if(lookupForm.getPostedView() instanceof KSLookupView){
60                  KSLookupView ksLookupView = (KSLookupView)lookupForm.getPostedView();
61                  String defaultAction = ksLookupView.getDefaultSingleLookupResultAction();
62                  if (StringUtils.isNotBlank(defaultAction) && lookupForm.getLookupResults() != null && lookupForm.getLookupResults().size() == 1){
63                      Object object = lookupForm.getLookupResults().iterator().next();
64  
65                      Properties props = new Properties();
66  
67                      DataObjectEntry ddEntry = KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDataObjectEntry(lookupForm.getDataObjectClassName());
68  
69                      List<String> pkKeys = ddEntry.getPrimaryKeys();
70                      for (String pkKey : pkKeys) {
71                          props.put(pkKey,ObjectPropertyUtils.getPropertyValue(object, pkKey));
72                      }
73  
74                      if(StringUtils.equals(defaultAction,KRADConstants.PARAM_MAINTENANCE_VIEW_MODE_MAINTENANCE)){
75                          props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.Maintenance.METHOD_TO_CALL_EDIT);
76                      }  else{
77                          props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, UifConstants.MethodToCallNames.START);
78                      }
79                      props.put(UifConstants.UrlParams.SHOW_HISTORY, BooleanUtils.toStringTrueFalse(false));
80                      props.put(UifConstants.UrlParams.SHOW_HOME,BooleanUtils.toStringTrueFalse(false));
81                      props.put(KRADConstants.DATA_OBJECT_CLASS_ATTRIBUTE,lookupForm.getDataObjectClassName());
82  
83                      return performRedirect(lookupForm,defaultAction,props );
84                  }
85              }
86  
87              return modelAndView;
88          }
89  
90      }