| 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 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
@Override |
| 53 | |
protected InquiryForm createInitialForm(HttpServletRequest request) { |
| 54 | 0 | return new InquiryForm(); |
| 55 | |
} |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
@RequestMapping(params = "methodToCall=start") |
| 72 | |
@Override |
| 73 | |
public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 74 | |
HttpServletRequest request, HttpServletResponse response) { |
| 75 | 0 | InquiryForm inquiryForm = (InquiryForm) form; |
| 76 | |
|
| 77 | |
|
| 78 | |
try { |
| 79 | 0 | inquiryForm.getInquirable().setDataObjectClass(Class.forName(inquiryForm.getDataObjectClassName())); |
| 80 | 0 | } catch (ClassNotFoundException e) { |
| 81 | 0 | LOG.error("Unable to get new instance for object class: " + inquiryForm.getDataObjectClassName(), e); |
| 82 | 0 | throw new RuntimeException( |
| 83 | |
"Unable to get new instance for object class: " + inquiryForm.getDataObjectClassName(), e); |
| 84 | 0 | } |
| 85 | |
|
| 86 | |
|
| 87 | 0 | Object dataObject = inquiryForm.getInquirable() |
| 88 | |
.retrieveDataObject(KRADUtils.translateRequestParameterMap(request.getParameterMap())); |
| 89 | |
|
| 90 | 0 | if (dataObject == null && GlobalVariables.getMessageMap().hasNoMessages()) { |
| 91 | 0 | LOG.error("The record you have inquired on does not exist."); |
| 92 | 0 | inquiryForm.setView(getViewService().getViewById("InquiryNoResultView")); |
| 93 | |
|
| 94 | |
} |
| 95 | 0 | inquiryForm.setDataObject(dataObject); |
| 96 | |
|
| 97 | 0 | return getUIFModelAndView(inquiryForm); |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
@RequestMapping(params = "methodToCall=export") |
| 104 | |
public ModelAndView export(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
| 105 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 106 | 0 | InquiryForm inquiryForm = (InquiryForm) form; |
| 107 | |
|
| 108 | 0 | Object dataObject = inquiryForm.getDataObject(); |
| 109 | |
|
| 110 | 0 | if (dataObject != null) { |
| 111 | 0 | DataObjectEntry dataObjectEntry = KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDataObjectEntry(inquiryForm.getDataObjectClassName()); |
| 112 | 0 | Class<? extends Exporter> exporterClass = dataObjectEntry.getExporterClass(); |
| 113 | 0 | if (exporterClass != null) { |
| 114 | 0 | Exporter exporter = exporterClass.newInstance(); |
| 115 | 0 | response.setContentType(KRADConstants.XML_MIME_TYPE); |
| 116 | 0 | response.setHeader("Content-disposition", "attachment; filename=export.xml"); |
| 117 | 0 | exporter.export(dataObjectEntry.getDataObjectClass(), Collections.singletonList(dataObject), KRADConstants.XML_FORMAT, response.getOutputStream()); |
| 118 | |
} |
| 119 | |
} |
| 120 | |
|
| 121 | 0 | return null; |
| 122 | |
} |
| 123 | |
} |