Coverage Report - org.kuali.rice.krad.web.controller.InquiryController
 
Classes in this File Line Coverage Branch Coverage Complexity
InquiryController
0%
0/27
0%
0/8
3.333
 
 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.krad.web.controller;
 17  
 
 18  
 import java.util.Collections;
 19  
 
 20  
 import javax.servlet.http.HttpServletRequest;
 21  
 import javax.servlet.http.HttpServletResponse;
 22  
 
 23  
 import org.kuali.rice.krad.bo.Exporter;
 24  
 import org.kuali.rice.krad.datadictionary.DataObjectEntry;
 25  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 26  
 import org.kuali.rice.krad.util.GlobalVariables;
 27  
 import org.kuali.rice.krad.util.KRADConstants;
 28  
 import org.kuali.rice.krad.util.KRADUtils;
 29  
 import org.kuali.rice.krad.web.form.InquiryForm;
 30  
 import org.kuali.rice.krad.web.form.UifFormBase;
 31  
 import org.springframework.stereotype.Controller;
 32  
 import org.springframework.validation.BindingResult;
 33  
 import org.springframework.web.bind.annotation.ModelAttribute;
 34  
 import org.springframework.web.bind.annotation.RequestMapping;
 35  
 import org.springframework.web.servlet.ModelAndView;
 36  
 
 37  
 /**
 38  
  * Controller for <code>InquiryView</code> screens which handle
 39  
  * initial requests for the inquiry and actions coming from the
 40  
  * inquiry view such as export
 41  
  *
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  */
 44  0
 @Controller
 45  
 @RequestMapping(value = "/inquiry")
 46  0
 public class InquiryController extends UifControllerBase {
 47  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(InquiryController.class);
 48  
 
 49  
     @Override
 50  
     protected InquiryForm createInitialForm(HttpServletRequest request) {
 51  0
         return new InquiryForm();
 52  
     }
 53  
 
 54  
     /**
 55  
      * Invoked to display the inquiry view for a data object record
 56  
      *
 57  
      * <p>
 58  
      * Data object class name and values for a primary or alternate key set must
 59  
      * be sent in the request
 60  
      * </p>
 61  
      *
 62  
      * <p>
 63  
      * Invokes the inquirable to perform the query for the data object record, if not found
 64  
      * an exception will be thrown. If found the object is set on the form and then the view
 65  
      * is rendered
 66  
      * </p>
 67  
      */
 68  
     @RequestMapping(params = "methodToCall=start")
 69  
     @Override
 70  
     public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
 71  
             HttpServletRequest request, HttpServletResponse response) {
 72  0
         InquiryForm inquiryForm = (InquiryForm) form;
 73  
 
 74  
         // initialize data object class in inquirable
 75  
         try {
 76  0
             inquiryForm.getInquirable().setDataObjectClass(Class.forName(inquiryForm.getDataObjectClassName()));
 77  0
         } catch (ClassNotFoundException e) {
 78  0
             LOG.error("Unable to get new instance for object class: " + inquiryForm.getDataObjectClassName(), e);
 79  0
             throw new RuntimeException(
 80  
                     "Unable to get new instance for object class: " + inquiryForm.getDataObjectClassName(), e);
 81  0
         }
 82  
 
 83  
         // invoke inquirable to retrieve inquiry data object
 84  0
         Object dataObject = inquiryForm.getInquirable()
 85  
                 .retrieveDataObject(KRADUtils.translateRequestParameterMap(request.getParameterMap()));
 86  
 
 87  0
         if (dataObject == null && GlobalVariables.getMessageMap().hasNoMessages()) {
 88  0
             LOG.error("The record you have inquired on does not exist.");
 89  0
             throw new UnsupportedOperationException("The record you have inquired on does not exist.");
 90  
         }
 91  0
         inquiryForm.setDataObject(dataObject);
 92  
 
 93  0
         return getUIFModelAndView(inquiryForm);
 94  
     }
 95  
     
 96  
     /**
 97  
      * Handles exporting the BusinessObject for this Inquiry to XML if it has a custom XML exporter available.
 98  
      */
 99  
     @RequestMapping(params = "methodToCall=export")
 100  
     public ModelAndView export(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
 101  
             HttpServletRequest request, HttpServletResponse response) throws Exception  {
 102  0
         InquiryForm inquiryForm = (InquiryForm) form;
 103  
         
 104  0
         Object dataObject = inquiryForm.getDataObject();
 105  
         
 106  0
         if (dataObject != null) {
 107  0
             DataObjectEntry dataObjectEntry = KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDataObjectEntry(inquiryForm.getDataObjectClassName());
 108  0
             Class<? extends Exporter> exporterClass = dataObjectEntry.getExporterClass();
 109  0
             if (exporterClass != null) {
 110  0
                 Exporter exporter = exporterClass.newInstance();
 111  0
                 response.setContentType(KRADConstants.XML_MIME_TYPE);
 112  0
                 response.setHeader("Content-disposition", "attachment; filename=export.xml");
 113  0
                 exporter.export(dataObjectEntry.getDataObjectClass(), Collections.singletonList(dataObject), KRADConstants.XML_FORMAT, response.getOutputStream());
 114  
             }
 115  
         }
 116  
         
 117  0
          return null;
 118  
     }
 119  
 }