1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.web.spring.controller; |
17 | |
|
18 | |
import javax.servlet.http.HttpServletRequest; |
19 | |
import javax.servlet.http.HttpServletResponse; |
20 | |
|
21 | |
import org.apache.commons.lang.ArrayUtils; |
22 | |
import org.apache.log4j.Logger; |
23 | |
import org.kuali.rice.kew.util.KEWConstants; |
24 | |
import org.kuali.rice.kns.bo.PersistableAttachment; |
25 | |
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
26 | |
import org.kuali.rice.kns.datadictionary.DocumentEntry; |
27 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
28 | |
import org.kuali.rice.kns.exception.ValidationException; |
29 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
30 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
31 | |
import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService; |
32 | |
import org.kuali.rice.kns.service.MaintenanceDocumentService; |
33 | |
import org.kuali.rice.kns.util.GlobalVariables; |
34 | |
import org.kuali.rice.kns.util.KNSConstants; |
35 | |
import org.kuali.rice.kns.util.MaintenanceUtils; |
36 | |
import org.kuali.rice.kns.web.spring.form.DocumentFormBase; |
37 | |
import org.kuali.rice.kns.web.spring.form.MaintenanceForm; |
38 | |
import org.kuali.rice.kns.web.spring.form.UifFormBase; |
39 | |
import org.springframework.stereotype.Controller; |
40 | |
import org.springframework.validation.BindingResult; |
41 | |
import org.springframework.web.bind.annotation.ModelAttribute; |
42 | |
import org.springframework.web.bind.annotation.RequestMapping; |
43 | |
import org.springframework.web.servlet.ModelAndView; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | @Controller |
52 | |
@RequestMapping(value = "/maintenance") |
53 | 0 | public class MaintenanceDocumentController extends DocumentControllerBase { |
54 | 0 | protected static final Logger LOG = Logger.getLogger(MaintenanceDocumentController.class); |
55 | |
|
56 | |
public static final String REQUEST_MAPPING_MAINTENANCE = "maintenance"; |
57 | |
public static final String METHOD_TO_CALL_NEW = "start"; |
58 | |
public static final String METHOD_TO_CALL_NEW_WITH_EXISTING = "maintenanceNewWithExisting"; |
59 | |
public static final String METHOD_TO_CALL_EDIT = "maintenanceEdit"; |
60 | |
public static final String METHOD_TO_CALL_COPY = "maintenanceCopy"; |
61 | |
public static final String METHOD_TO_CALL_DELETE = "maintenanceDelete"; |
62 | |
|
63 | |
@Override |
64 | |
public MaintenanceForm createInitialForm(HttpServletRequest request) { |
65 | 0 | return new MaintenanceForm(); |
66 | |
} |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
@Override |
72 | |
@RequestMapping(params = "methodToCall=docHandler") |
73 | |
public ModelAndView docHandler(@ModelAttribute("KualiForm") DocumentFormBase formBase, BindingResult result, HttpServletRequest request, |
74 | |
HttpServletResponse response) throws Exception { |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | 0 | MaintenanceForm form = (MaintenanceForm)formBase; |
81 | |
|
82 | |
|
83 | 0 | if (ArrayUtils.contains(DOCUMENT_LOAD_COMMANDS, form.getCommand()) && form.getDocId() != null) { |
84 | 0 | loadDocument(form); |
85 | |
} |
86 | 0 | else if (KEWConstants.INITIATE_COMMAND.equals(form.getCommand())) { |
87 | 0 | createDocument(form); |
88 | |
} |
89 | |
else { |
90 | 0 | LOG.error("docHandler called with invalid parameters"); |
91 | 0 | throw new IllegalStateException("docHandler called with invalid parameters"); |
92 | |
} |
93 | |
|
94 | |
|
95 | 0 | if (KEWConstants.ACTIONLIST_COMMAND.equals(form.getCommand()) |
96 | |
|| KEWConstants.DOCSEARCH_COMMAND.equals(form.getCommand()) |
97 | |
|| KEWConstants.SUPERUSER_COMMAND.equals(form.getCommand()) |
98 | |
|| KEWConstants.HELPDESK_ACTIONLIST_COMMAND.equals(form.getCommand()) && form.getDocId() != null) { |
99 | |
|
100 | |
|
101 | 0 | form.setMaintenanceAction((form.getDocument()).getNewMaintainableObject().getMaintenanceAction()); |
102 | |
|
103 | |
|
104 | 0 | Maintainable tmpMaintainable = form.getDocument().getNewMaintainableObject(); |
105 | 0 | if (tmpMaintainable.getDataObject() instanceof PersistableAttachment) { |
106 | 0 | PersistableAttachment bo = (PersistableAttachment) getBusinessObjectService().retrieve( |
107 | |
(PersistableBusinessObject) tmpMaintainable.getDataObject()); |
108 | 0 | if (bo != null) { |
109 | 0 | request.setAttribute("fileName", bo.getFileName()); |
110 | |
} |
111 | |
} |
112 | 0 | } |
113 | 0 | else if (KEWConstants.INITIATE_COMMAND.equals(form.getCommand())) { |
114 | |
|
115 | 0 | setupMaintenance(form, request, KNSConstants.MAINTENANCE_NEW_ACTION); |
116 | |
} |
117 | |
else { |
118 | 0 | LOG.error("We should never have gotten to here"); |
119 | 0 | throw new IllegalStateException("docHandler called with invalid parameters"); |
120 | |
} |
121 | |
|
122 | 0 | return getUIFModelAndView(form); |
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
@RequestMapping(params = "methodToCall=" + METHOD_TO_CALL_NEW) |
130 | |
@Override |
131 | |
public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
132 | |
HttpServletRequest request, HttpServletResponse response) { |
133 | 0 | MaintenanceForm maintenanceForm = (MaintenanceForm) form; |
134 | |
|
135 | 0 | setupMaintenance(maintenanceForm, request, KNSConstants.MAINTENANCE_NEW_ACTION); |
136 | |
|
137 | 0 | return getUIFModelAndView(maintenanceForm); |
138 | |
} |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
@RequestMapping(params = "methodToCall=" + METHOD_TO_CALL_EDIT) |
145 | |
public ModelAndView maintenanceEdit(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result, |
146 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
147 | |
|
148 | 0 | setupMaintenance(form, request, KNSConstants.MAINTENANCE_EDIT_ACTION); |
149 | |
|
150 | 0 | return getUIFModelAndView(form); |
151 | |
} |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
@RequestMapping(params = "methodToCall=" + METHOD_TO_CALL_COPY) |
158 | |
public ModelAndView maintenanceCopy(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result, |
159 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
160 | |
|
161 | 0 | setupMaintenance(form, request, KNSConstants.MAINTENANCE_COPY_ACTION); |
162 | |
|
163 | 0 | return getUIFModelAndView(form); |
164 | |
} |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
@RequestMapping(params = "methodToCall=" + METHOD_TO_CALL_NEW_WITH_EXISTING) |
171 | |
public ModelAndView maintenanceNewWithExisting(@ModelAttribute("KualiForm") MaintenanceForm form, |
172 | |
BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception { |
173 | |
|
174 | 0 | setupMaintenance(form, request, KNSConstants.MAINTENANCE_NEWWITHEXISTING_ACTION); |
175 | |
|
176 | 0 | return getUIFModelAndView(form); |
177 | |
} |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
protected void setupMaintenance(MaintenanceForm form, HttpServletRequest request, String maintenanceAction) { |
198 | 0 | MaintenanceDocument document = form.getDocument(); |
199 | |
|
200 | |
|
201 | 0 | if (document == null) { |
202 | 0 | document = getMaintenanceDocumentService().setupNewMaintenanceDocument(form.getDataObjectClassName(), |
203 | |
form.getDocTypeName(), maintenanceAction); |
204 | |
|
205 | 0 | form.setDocument(document); |
206 | 0 | form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentType()); |
207 | |
} |
208 | |
|
209 | |
|
210 | 0 | form.setMaintenanceAction(maintenanceAction); |
211 | |
|
212 | |
|
213 | 0 | document.getNewMaintainableObject().setupMaintenanceObject(document, maintenanceAction, |
214 | |
request.getParameterMap()); |
215 | |
|
216 | |
|
217 | |
|
218 | 0 | if (KNSConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction)) { |
219 | 0 | MaintenanceUtils.checkForLockingDocument(document.getNewMaintainableObject(), false); |
220 | |
} |
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | 0 | DocumentEntry entry = getMaintenanceDocumentDictionaryService().getMaintenanceDocumentEntry( |
226 | |
document.getDocumentHeader().getWorkflowDocument().getDocumentType()); |
227 | 0 | document.setDisplayTopicFieldInNotes(entry.getDisplayTopicFieldInNotes()); |
228 | 0 | } |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
@Override |
237 | |
@RequestMapping(params = "methodToCall=route") |
238 | |
public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, HttpServletRequest request, |
239 | |
HttpServletResponse response) throws Exception { |
240 | |
|
241 | |
ModelAndView modelAndView; |
242 | |
|
243 | |
try { |
244 | 0 | modelAndView = super.route(form, result, request, response); |
245 | |
|
246 | 0 | MaintenanceDocument document = (MaintenanceDocument) form.getDocument(); |
247 | 0 | if (document.getNewMaintainableObject().getDataObject() instanceof PersistableAttachment) { |
248 | 0 | PersistableAttachment bo = (PersistableAttachment) getBusinessObjectService().retrieve((PersistableBusinessObject) document.getNewMaintainableObject().getDataObject()); |
249 | 0 | request.setAttribute("fileName", bo.getFileName()); |
250 | |
} |
251 | 0 | } catch (ValidationException vex) { |
252 | 0 | if(GlobalVariables.getMessageMap().hasNoErrors()) { |
253 | 0 | throw new RuntimeException("Validation Exception with no error message.", vex); |
254 | |
} |
255 | |
|
256 | 0 | modelAndView = getUIFModelAndView(form); |
257 | 0 | } |
258 | |
|
259 | 0 | return modelAndView; |
260 | |
} |
261 | |
|
262 | |
@Override |
263 | |
protected ModelAndView getUIFModelAndView(UifFormBase form, String viewId, String pageId) { |
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | 0 | return super.getUIFModelAndView(form, viewId, pageId); |
277 | |
} |
278 | |
|
279 | |
protected MaintenanceDocumentService getMaintenanceDocumentService() { |
280 | 0 | return KNSServiceLocatorWeb.getMaintenanceDocumentService(); |
281 | |
} |
282 | |
|
283 | |
protected MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() { |
284 | 0 | return KNSServiceLocatorWeb.getMaintenanceDocumentDictionaryService(); |
285 | |
} |
286 | |
|
287 | |
} |