Coverage Report - org.kuali.rice.kns.web.spring.controller.InquiryController
 
Classes in this File Line Coverage Branch Coverage Complexity
InquiryController
0%
0/18
0%
0/6
1.8
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/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,
 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.rice.kns.web.spring.controller;
 17  
 
 18  
 import javax.servlet.http.HttpServletRequest;
 19  
 import javax.servlet.http.HttpServletResponse;
 20  
 
 21  
 import org.kuali.rice.core.util.RiceKeyConstants;
 22  
 import org.kuali.rice.kns.inquiry.Inquirable;
 23  
 import org.kuali.rice.kns.util.GlobalVariables;
 24  
 import org.kuali.rice.kns.util.KNSConstants;
 25  
 import org.kuali.rice.kns.web.spring.form.InquiryForm;
 26  
 import org.springframework.stereotype.Controller;
 27  
 import org.springframework.validation.BindingResult;
 28  
 import org.springframework.web.bind.annotation.ModelAttribute;
 29  
 import org.springframework.web.bind.annotation.RequestMapping;
 30  
 import org.springframework.web.servlet.ModelAndView;
 31  
 
 32  
 /**
 33  
  * This class is the handler for inquiries of business objects.
 34  
  * 
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  0
 @Controller
 38  
 @RequestMapping(value = "/inquiry")
 39  0
 public class InquiryController extends UifControllerBase {
 40  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(InquiryController.class);
 41  
         
 42  
         @Override
 43  
     protected InquiryForm createInitialForm(HttpServletRequest request) {
 44  0
         return new InquiryForm();
 45  
     }
 46  
 
 47  
     @RequestMapping(params = "methodToCall=start")
 48  
         public ModelAndView start(@ModelAttribute("KualiForm") InquiryForm inquiryForm, BindingResult result,
 49  
                         HttpServletRequest request, HttpServletResponse response) {
 50  0
                 return continueWithInquiry(inquiryForm, result, request, response);
 51  
         }
 52  
 
 53  
         /**
 54  
          * @param result
 55  
          * @param response
 56  
          */
 57  
         @RequestMapping(params = "methodToCall=continueWithInquiry")
 58  
         public ModelAndView continueWithInquiry(@ModelAttribute("KualiForm") InquiryForm inquiryForm, BindingResult result,
 59  
                         HttpServletRequest request, HttpServletResponse response) {
 60  
 
 61  0
                 Object bo = retrieveBOFromInquirable(inquiryForm);
 62  0
                 checkBO(bo);
 63  
 
 64  0
                 inquiryForm.setBo(bo);
 65  
 
 66  0
                 return getUIFModelAndView(inquiryForm);
 67  
         }
 68  
 
 69  
         /**
 70  
          * throws an exception if BO fails the check.
 71  
          * 
 72  
          * @param bo
 73  
          *            the BusinessObject to check.
 74  
          * @throws UnsupportedOperationException
 75  
          *             if BO is null & no messages have been generated.
 76  
          */
 77  
         private void checkBO(Object bo) {
 78  0
                 if (bo == null && GlobalVariables.getMessageMap().hasNoMessages()) {
 79  0
                         throw new UnsupportedOperationException("The record you have inquired on does not exist.");
 80  
                 }
 81  0
         }
 82  
 
 83  
         protected Object retrieveBOFromInquirable(InquiryForm inquiryForm) {
 84  0
                 Inquirable kualiInquirable = inquiryForm.getInquirable();
 85  
 
 86  
                 // retrieve the business object
 87  0
                 Object  inquiryObject = kualiInquirable.getDataObject(inquiryForm.retrieveInquiryDecryptedPrimaryKeys());
 88  0
                 if (inquiryObject == null) {
 89  0
                         LOG.error("No records found in inquiry action.");
 90  0
                         GlobalVariables.getMessageMap().putError(KNSConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INQUIRY);
 91  
                 }
 92  
 
 93  0
                 return inquiryObject;
 94  
         }
 95  
 
 96  
 }