|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  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 |     | 
     | 
  |  39 |     | 
     | 
  |  40 |     | 
     | 
  |  41 |     | 
     | 
  |  42 |     | 
     | 
  |  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 |     | 
     | 
  |  56 |     | 
     | 
  |  57 |     | 
     | 
  |  58 |     | 
     | 
  |  59 |     | 
     | 
  |  60 |     | 
     | 
  |  61 |     | 
     | 
  |  62 |     | 
     | 
  |  63 |     | 
     | 
  |  64 |     | 
     | 
  |  65 |     | 
     | 
  |  66 |     | 
     | 
  |  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 |     | 
             | 
  |  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 |     | 
             | 
  |  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 |     | 
     | 
  |  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 |     | 
   }  |