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