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