| 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 | |
public ModelAndView start(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result, |
| 130 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 131 | |
|
| 132 | 0 | setupMaintenance(form, request, KNSConstants.MAINTENANCE_NEW_ACTION); |
| 133 | |
|
| 134 | 0 | return getUIFModelAndView(form); |
| 135 | |
} |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
@RequestMapping(params = "methodToCall=" + METHOD_TO_CALL_EDIT) |
| 142 | |
public ModelAndView maintenanceEdit(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result, |
| 143 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 144 | |
|
| 145 | 0 | setupMaintenance(form, request, KNSConstants.MAINTENANCE_EDIT_ACTION); |
| 146 | |
|
| 147 | 0 | return getUIFModelAndView(form); |
| 148 | |
} |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
@RequestMapping(params = "methodToCall=" + METHOD_TO_CALL_COPY) |
| 155 | |
public ModelAndView maintenanceCopy(@ModelAttribute("KualiForm") MaintenanceForm form, BindingResult result, |
| 156 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 157 | |
|
| 158 | 0 | setupMaintenance(form, request, KNSConstants.MAINTENANCE_COPY_ACTION); |
| 159 | |
|
| 160 | 0 | return getUIFModelAndView(form); |
| 161 | |
} |
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
@RequestMapping(params = "methodToCall=" + METHOD_TO_CALL_NEW_WITH_EXISTING) |
| 168 | |
public ModelAndView maintenanceNewWithExisting(@ModelAttribute("KualiForm") MaintenanceForm form, |
| 169 | |
BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 170 | |
|
| 171 | 0 | setupMaintenance(form, request, KNSConstants.MAINTENANCE_NEWWITHEXISTING_ACTION); |
| 172 | |
|
| 173 | 0 | return getUIFModelAndView(form); |
| 174 | |
} |
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
protected void setupMaintenance(MaintenanceForm form, HttpServletRequest request, String maintenanceAction) |
| 195 | |
throws Exception { |
| 196 | 0 | MaintenanceDocument document = form.getDocument(); |
| 197 | |
|
| 198 | |
|
| 199 | 0 | if (document == null) { |
| 200 | 0 | document = getMaintenanceDocumentService().setupNewMaintenanceDocument(form.getDataObjectClassName(), |
| 201 | |
form.getDocTypeName(), maintenanceAction); |
| 202 | |
|
| 203 | 0 | form.setDocument(document); |
| 204 | 0 | form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentType()); |
| 205 | |
} |
| 206 | |
|
| 207 | |
|
| 208 | 0 | form.setMaintenanceAction(maintenanceAction); |
| 209 | |
|
| 210 | |
|
| 211 | 0 | document.getNewMaintainableObject().setupMaintenanceObject(document, maintenanceAction, |
| 212 | |
request.getParameterMap()); |
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | 0 | if (KNSConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction)) { |
| 217 | 0 | MaintenanceUtils.checkForLockingDocument(document.getNewMaintainableObject(), false); |
| 218 | |
} |
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | 0 | DocumentEntry entry = getMaintenanceDocumentDictionaryService().getMaintenanceDocumentEntry( |
| 224 | |
document.getDocumentHeader().getWorkflowDocument().getDocumentType()); |
| 225 | 0 | document.setDisplayTopicFieldInNotes(entry.getDisplayTopicFieldInNotes()); |
| 226 | 0 | } |
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
@Override |
| 235 | |
@RequestMapping(params = "methodToCall=route") |
| 236 | |
public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, HttpServletRequest request, |
| 237 | |
HttpServletResponse response) throws Exception { |
| 238 | |
|
| 239 | |
ModelAndView modelAndView; |
| 240 | |
|
| 241 | |
try { |
| 242 | 0 | modelAndView = super.route(form, result, request, response); |
| 243 | |
|
| 244 | 0 | MaintenanceDocument document = (MaintenanceDocument) form.getDocument(); |
| 245 | 0 | if (document.getNewMaintainableObject().getDataObject() instanceof PersistableAttachment) { |
| 246 | 0 | PersistableAttachment bo = (PersistableAttachment) getBusinessObjectService().retrieve((PersistableBusinessObject) document.getNewMaintainableObject().getDataObject()); |
| 247 | 0 | request.setAttribute("fileName", bo.getFileName()); |
| 248 | |
} |
| 249 | 0 | } catch (ValidationException vex) { |
| 250 | 0 | modelAndView = getUIFModelAndView(form); |
| 251 | 0 | } |
| 252 | |
|
| 253 | 0 | return modelAndView; |
| 254 | |
} |
| 255 | |
|
| 256 | |
@Override |
| 257 | |
protected ModelAndView getUIFModelAndView(UifFormBase form, String viewId, String pageId) { |
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | 0 | return super.getUIFModelAndView(form, viewId, pageId); |
| 271 | |
} |
| 272 | |
|
| 273 | |
protected MaintenanceDocumentService getMaintenanceDocumentService() { |
| 274 | 0 | return KNSServiceLocatorWeb.getMaintenanceDocumentService(); |
| 275 | |
} |
| 276 | |
|
| 277 | |
protected MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() { |
| 278 | 0 | return KNSServiceLocatorWeb.getMaintenanceDocumentDictionaryService(); |
| 279 | |
} |
| 280 | |
|
| 281 | |
} |