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 import java.util.Map;
20 import java.util.Properties;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import org.kuali.rice.core.api.exception.RiceRuntimeException;
26 import org.kuali.rice.krad.bo.Exporter;
27 import org.kuali.rice.krad.datadictionary.DataObjectEntry;
28 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
29 import org.kuali.rice.krad.service.ModuleService;
30 import org.kuali.rice.krad.uif.UifParameters;
31 import org.kuali.rice.krad.util.GlobalVariables;
32 import org.kuali.rice.krad.util.KRADConstants;
33 import org.kuali.rice.krad.util.KRADUtils;
34 import org.kuali.rice.krad.web.form.InquiryForm;
35 import org.kuali.rice.krad.web.form.UifFormBase;
36 import org.springframework.stereotype.Controller;
37 import org.springframework.validation.BindingResult;
38 import org.springframework.web.bind.annotation.ModelAttribute;
39 import org.springframework.web.bind.annotation.RequestMapping;
40 import org.springframework.web.servlet.ModelAndView;
41
42
43
44
45
46
47
48 @Controller
49 @RequestMapping(value = "/inquiry")
50 public class InquiryController extends UifControllerBase {
51 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(InquiryController.class);
52
53
54
55
56 @Override
57 protected InquiryForm createInitialForm(HttpServletRequest request) {
58 return new InquiryForm();
59 }
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 @Override
81 @MethodAccessible
82 @RequestMapping(params = "methodToCall=start")
83 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, HttpServletRequest request,
84 HttpServletResponse response) {
85 InquiryForm inquiryForm = (InquiryForm) form;
86
87
88 if (!inquiryForm.isRedirectedInquiry()) {
89 Class<?> inquiryObjectClass;
90 try {
91 inquiryObjectClass = Class.forName(inquiryForm.getDataObjectClassName());
92 } catch (ClassNotFoundException e) {
93 throw new RiceRuntimeException("Unable to get class for name: " + inquiryForm.getDataObjectClassName(),
94 e);
95 }
96
97 ModuleService responsibleModuleService =
98 KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(inquiryObjectClass);
99 if (responsibleModuleService != null && responsibleModuleService.isExternalizable(inquiryObjectClass)) {
100 String inquiryUrl = responsibleModuleService.getExternalizableDataObjectInquiryUrl(inquiryObjectClass,
101 KRADUtils.convertRequestMapToProperties(request.getParameterMap()));
102
103 Properties redirectUrlProps = new Properties();
104 redirectUrlProps.put(UifParameters.REDIRECTED_INQUIRY, "true");
105
106
107 GlobalVariables.getUifFormManager().removeSessionForm(form);
108
109 return performRedirect(form, inquiryUrl, redirectUrlProps);
110 }
111 }
112
113
114 Object dataObject = inquiryForm.getInquirable().retrieveDataObject(KRADUtils.translateRequestParameterMap(
115 request.getParameterMap()));
116
117 inquiryForm.setDataObject(dataObject);
118
119 return super.start(form, request, response);
120 }
121
122
123
124
125 @RequestMapping(params = "methodToCall=export")
126 public ModelAndView export(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
127 HttpServletRequest request, HttpServletResponse response) throws Exception {
128 InquiryForm inquiryForm = (InquiryForm) form;
129
130 Object dataObject = inquiryForm.getDataObject();
131 if (dataObject != null) {
132 DataObjectEntry dataObjectEntry =
133 KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDataObjectEntry(
134 inquiryForm.getDataObjectClassName());
135
136 Class<? extends Exporter> exporterClass = dataObjectEntry.getExporterClass();
137 if (exporterClass != null) {
138 Exporter exporter = exporterClass.newInstance();
139
140 response.setContentType(KRADConstants.XML_MIME_TYPE);
141 response.setHeader("Content-disposition", "attachment; filename=export.xml");
142 exporter.export(dataObjectEntry.getDataObjectClass(), Collections.singletonList(dataObject),
143 KRADConstants.XML_FORMAT, response.getOutputStream());
144 }
145 }
146
147 return null;
148 }
149 }