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 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.api.KewApiConstants; |
24 | |
import org.kuali.rice.krad.bo.PersistableAttachment; |
25 | |
import org.kuali.rice.krad.bo.PersistableBusinessObject; |
26 | |
import org.kuali.rice.krad.datadictionary.DocumentEntry; |
27 | |
import org.kuali.rice.krad.document.MaintenanceDocument; |
28 | |
import org.kuali.rice.krad.exception.ValidationException; |
29 | |
import org.kuali.rice.krad.maintenance.Maintainable; |
30 | |
import org.kuali.rice.krad.maintenance.MaintenanceUtils; |
31 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
32 | |
import org.kuali.rice.krad.service.MaintenanceDocumentService; |
33 | |
import org.kuali.rice.krad.util.GlobalVariables; |
34 | |
import org.kuali.rice.krad.util.KRADConstants; |
35 | |
import org.kuali.rice.krad.web.form.DocumentFormBase; |
36 | |
import org.kuali.rice.krad.web.form.MaintenanceForm; |
37 | |
import org.kuali.rice.krad.web.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 | |
|
56 | |
|
57 | |
|
58 | |
@Override |
59 | |
protected MaintenanceForm createInitialForm(HttpServletRequest request) { |
60 | 0 | return new MaintenanceForm(); |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
@Override |
67 | |
@RequestMapping(params = "methodToCall=docHandler") |
68 | |
public ModelAndView docHandler(@ModelAttribute("KualiForm") DocumentFormBase formBase, BindingResult result, |
69 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | 0 | MaintenanceForm form = (MaintenanceForm) formBase; |
76 | |
|
77 | |
|
78 | 0 | if (ArrayUtils.contains(DOCUMENT_LOAD_COMMANDS, form.getCommand()) && form.getDocId() != null) { |
79 | 0 | loadDocument(form); |
80 | 0 | } else if (KewApiConstants.INITIATE_COMMAND.equals(form.getCommand())) { |
81 | 0 | createDocument(form); |
82 | |
} else { |
83 | 0 | LOG.error("docHandler called with invalid parameters"); |
84 | 0 | throw new IllegalStateException("docHandler called with invalid parameters"); |
85 | |
} |
86 | |
|
87 | |
|
88 | 0 | if (KewApiConstants.ACTIONLIST_COMMAND.equals(form.getCommand()) || |
89 | |
KewApiConstants.DOCSEARCH_COMMAND.equals(form.getCommand()) || |
90 | |
KewApiConstants.SUPERUSER_COMMAND.equals(form.getCommand()) || |
91 | |
KewApiConstants.HELPDESK_ACTIONLIST_COMMAND.equals(form.getCommand()) && form.getDocId() != null) { |
92 | |
|
93 | |
|
94 | 0 | form.setMaintenanceAction((form.getDocument()).getNewMaintainableObject().getMaintenanceAction()); |
95 | |
|
96 | |
|
97 | 0 | Maintainable tmpMaintainable = form.getDocument().getNewMaintainableObject(); |
98 | 0 | if (tmpMaintainable.getDataObject() instanceof PersistableAttachment) { |
99 | 0 | PersistableAttachment bo = (PersistableAttachment) getBusinessObjectService() |
100 | |
.retrieve((PersistableBusinessObject) tmpMaintainable.getDataObject()); |
101 | 0 | if (bo != null) { |
102 | 0 | request.setAttribute("fileName", bo.getFileName()); |
103 | |
} |
104 | |
} |
105 | 0 | } else if (KewApiConstants.INITIATE_COMMAND.equals(form.getCommand())) { |
106 | |
|
107 | 0 | setupMaintenance(form, request, KRADConstants.MAINTENANCE_NEW_ACTION); |
108 | |
} else { |
109 | 0 | LOG.error("We should never have gotten to here"); |
110 | 0 | throw new IllegalStateException("docHandler called with invalid parameters"); |
111 | |
} |
112 | |
|
113 | 0 | return getUIFModelAndView(form); |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
@RequestMapping(params = "methodToCall=" + KRADConstants.Maintenance.METHOD_TO_CALL_NEW) |
121 | |
@Override |
122 | |
public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, |
123 | |
HttpServletRequest request, HttpServletResponse response) { |
124 | 0 | MaintenanceForm maintenanceForm = (MaintenanceForm) form; |
125 | |
|
126 | 0 | setupMaintenance(maintenanceForm, request, KRADConstants.MAINTENANCE_NEW_ACTION); |
127 | |
|
128 | 0 | return getUIFModelAndView(maintenanceForm); |
129 | |
} |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
@RequestMapping(params = "methodToCall=" + KRADConstants.Maintenance.METHOD_TO_CALL_EDIT) |
136 | |
public ModelAndView maintenanceEdit(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result, |
137 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
138 | |
|
139 | 0 | setupMaintenance(form, request, KRADConstants.MAINTENANCE_EDIT_ACTION); |
140 | |
|
141 | 0 | return getUIFModelAndView(form); |
142 | |
} |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
@RequestMapping(params = "methodToCall=" + KRADConstants.Maintenance.METHOD_TO_CALL_COPY) |
149 | |
public ModelAndView maintenanceCopy(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result, |
150 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
151 | |
|
152 | 0 | setupMaintenance(form, request, KRADConstants.MAINTENANCE_COPY_ACTION); |
153 | |
|
154 | 0 | return getUIFModelAndView(form); |
155 | |
} |
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
@RequestMapping(params = "methodToCall=" + KRADConstants.Maintenance.METHOD_TO_CALL_NEW_WITH_EXISTING) |
162 | |
public ModelAndView maintenanceNewWithExisting(@ModelAttribute("KualiForm") MaintenanceForm form, |
163 | |
BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception { |
164 | |
|
165 | 0 | setupMaintenance(form, request, KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION); |
166 | |
|
167 | 0 | return getUIFModelAndView(form); |
168 | |
} |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
protected void setupMaintenance(MaintenanceForm form, HttpServletRequest request, String maintenanceAction) { |
186 | 0 | MaintenanceDocument document = form.getDocument(); |
187 | |
|
188 | |
|
189 | 0 | if (document == null) { |
190 | 0 | document = getMaintenanceDocumentService() |
191 | |
.setupNewMaintenanceDocument(form.getDataObjectClassName(), form.getDocTypeName(), |
192 | |
maintenanceAction); |
193 | |
|
194 | 0 | form.setDocument(document); |
195 | 0 | form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName()); |
196 | |
} |
197 | |
|
198 | |
|
199 | 0 | form.setMaintenanceAction(maintenanceAction); |
200 | |
|
201 | |
|
202 | 0 | getMaintenanceDocumentService().setupMaintenanceObject(document, maintenanceAction, request.getParameterMap()); |
203 | |
|
204 | |
|
205 | |
|
206 | 0 | if (KRADConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction)) { |
207 | 0 | MaintenanceUtils.checkForLockingDocument(document, false); |
208 | |
} |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | 0 | DocumentEntry entry = KRADServiceLocatorWeb.getDocumentDictionaryService() |
214 | |
.getMaintenanceDocumentEntry(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName()); |
215 | 0 | document.setDisplayTopicFieldInNotes(entry.getDisplayTopicFieldInNotes()); |
216 | 0 | } |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
@Override |
225 | |
@RequestMapping(params = "methodToCall=route") |
226 | |
public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, |
227 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
228 | |
|
229 | |
ModelAndView modelAndView; |
230 | |
|
231 | |
try { |
232 | 0 | modelAndView = super.route(form, result, request, response); |
233 | |
|
234 | 0 | MaintenanceDocument document = (MaintenanceDocument) form.getDocument(); |
235 | 0 | if (document.getNewMaintainableObject().getDataObject() instanceof PersistableAttachment) { |
236 | 0 | PersistableAttachment bo = (PersistableAttachment) getBusinessObjectService() |
237 | |
.retrieve((PersistableBusinessObject) document.getNewMaintainableObject().getDataObject()); |
238 | 0 | request.setAttribute("fileName", bo.getFileName()); |
239 | |
} |
240 | 0 | } catch (ValidationException vex) { |
241 | 0 | if (GlobalVariables.getMessageMap().hasNoErrors()) { |
242 | 0 | throw new RuntimeException("Validation Exception with no error message.", vex); |
243 | |
} |
244 | |
|
245 | 0 | modelAndView = getUIFModelAndView(form); |
246 | 0 | } |
247 | |
|
248 | 0 | return modelAndView; |
249 | |
} |
250 | |
|
251 | |
protected MaintenanceDocumentService getMaintenanceDocumentService() { |
252 | 0 | return KRADServiceLocatorWeb.getMaintenanceDocumentService(); |
253 | |
} |
254 | |
|
255 | |
} |