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