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