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 @RequestMapping(params = "methodToCall=start")
81 @Override
82 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
83 HttpServletRequest request, HttpServletResponse response) {
84 InquiryForm inquiryForm = (InquiryForm) form;
85
86
87 if (!inquiryForm.isRedirectedInquiry()) {
88 Class inquiryObjectClass = null;
89 try {
90 inquiryObjectClass = Class.forName(inquiryForm.getDataObjectClassName());
91 } catch (ClassNotFoundException e) {
92 throw new RiceRuntimeException("Unable to get class for name: " + inquiryForm.getDataObjectClassName());
93 }
94
95 ModuleService responsibleModuleService =
96 KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(inquiryObjectClass);
97 if (responsibleModuleService != null && responsibleModuleService.isExternalizable(inquiryObjectClass)) {
98 String inquiryUrl = responsibleModuleService.getExternalizableDataObjectInquiryUrl(inquiryObjectClass,
99 KRADUtils.convertRequestMapToProperties(request.getParameterMap()));
100
101 Properties redirectUrlProps = new Properties();
102 redirectUrlProps.put(UifParameters.REDIRECTED_INQUIRY, "true");
103
104
105 GlobalVariables.getUifFormManager().removeSessionForm(form);
106
107 return performRedirect(form, inquiryUrl, redirectUrlProps);
108 }
109 }
110
111
112 try {
113 inquiryForm.getInquirable().setDataObjectClass(Class.forName(inquiryForm.getDataObjectClassName()));
114 } catch (ClassNotFoundException e) {
115 LOG.error("Unable to get new instance for object class: " + inquiryForm.getDataObjectClassName(), e);
116 throw new RuntimeException(
117 "Unable to get new instance for object class: " + inquiryForm.getDataObjectClassName(), e);
118 }
119
120
121 Object dataObject = inquiryForm.getInquirable().retrieveDataObject(KRADUtils.translateRequestParameterMap(
122 request.getParameterMap()));
123
124 inquiryForm.setDataObject(dataObject);
125
126 return super.start(form, result, request, response);
127 }
128
129
130
131
132 @RequestMapping(params = "methodToCall=export")
133 public ModelAndView export(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
134 HttpServletRequest request, HttpServletResponse response) throws Exception {
135 InquiryForm inquiryForm = (InquiryForm) form;
136
137 Object dataObject = inquiryForm.getDataObject();
138 if (dataObject != null) {
139 DataObjectEntry dataObjectEntry =
140 KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDataObjectEntry(
141 inquiryForm.getDataObjectClassName());
142
143 Class<? extends Exporter> exporterClass = dataObjectEntry.getExporterClass();
144 if (exporterClass != null) {
145 Exporter exporter = exporterClass.newInstance();
146
147 response.setContentType(KRADConstants.XML_MIME_TYPE);
148 response.setHeader("Content-disposition", "attachment; filename=export.xml");
149 exporter.export(dataObjectEntry.getDataObjectClass(), Collections.singletonList(dataObject),
150 KRADConstants.XML_FORMAT, response.getOutputStream());
151 }
152 }
153
154 return null;
155 }
156 }