Ticket #866: MimeTypeListController_delete.patch
| File MimeTypeListController_delete.patch, 3.4 kB (added by dkayiwa, 7 months ago) |
|---|
patch for displaying a user friendly messages for exceptions thro.wn when attempting to delete mime types |
-
openmrs/trunk/src/web/org/openmrs/web/controller/observation/MimeTypeListController.java
old new 32 32 import org.openmrs.web.WebConstants; 33 33 import org.springframework.beans.propertyeditors.CustomNumberEditor; 34 34 import org.springframework.context.support.MessageSourceAccessor; 35 import org.springframework.dao.DataIntegrityViolationException; 35 36 import org.springframework.validation.BindException; 36 37 import org.springframework.web.bind.ServletRequestDataBinder; 37 38 import org.springframework.web.servlet.ModelAndView; … … 70 71 Locale locale = request.getLocale(); 71 72 String view = getFormView(); 72 73 if (Context.isAuthenticated()) { 73 String[] mimeTypeList = request.getParameterValues("mimeTypeId");74 AdministrationService as = Context.getAdministrationService();75 ObsService os = Context.getObsService();76 77 74 String success = ""; 78 75 String error = ""; 79 76 80 77 MessageSourceAccessor msa = getMessageSourceAccessor(); 81 String deleted = msa.getMessage("general.deleted"); 82 String notDeleted = msa.getMessage("general.cannot.delete"); 83 for (String m : mimeTypeList) { 84 try { 85 as.deleteMimeType(os.getMimeType(Integer.valueOf(m))); 86 if (!success.equals("")) success += "<br/>"; 87 success += m + " " + deleted; 78 79 String[] mimeTypeList = request.getParameterValues("mimeTypeId"); 80 if(mimeTypeList != null){ 81 AdministrationService as = Context.getAdministrationService(); 82 ObsService os = Context.getObsService(); 83 84 String deleted = msa.getMessage("general.deleted"); 85 String notDeleted = msa.getMessage("MimeType.cannot.delete"); 86 for (String m : mimeTypeList) { 87 try { 88 as.deleteMimeType(os.getMimeType(Integer.valueOf(m))); 89 if (!success.equals("")) success += "<br/>"; 90 success += m + " " + deleted; 91 } 92 catch(DataIntegrityViolationException e){ 93 error = handleMimeTypeIntegrityException(e,error,notDeleted); 94 } 95 catch (APIException e) { 96 error = handleMimeTypeIntegrityException(e,error,notDeleted); 97 } 88 98 } 89 catch (APIException e) {90 log.warn("Error deleting mime type", e);91 if (!error.equals("")) error += "<br/>";92 error += m + " " + notDeleted;93 }94 99 } 100 else 101 error = msa.getMessage("MimeType.select"); 95 102 96 103 view = getSuccessView(); 97 104 if (!success.equals("")) … … 105 112 106 113 /** 107 114 * 115 * Logs a mime type delete data integrity violation exception and 116 * returns a user friedly message of the problem that occured. 117 * 118 * @param e the exception. 119 * @param error the error message. 120 * @param notDeleted the not deleted error message. 121 * @return the formatted error message. 122 */ 123 private String handleMimeTypeIntegrityException(Exception e,String error,String notDeleted){ 124 log.warn("Error deleting mime type", e); 125 if (!error.equals("")) error += "<br/>"; 126 error += notDeleted; 127 return error; 128 } 129 130 /** 131 * 108 132 * This is called prior to displaying a form for the first time. It tells Spring 109 133 * the form/command object to load into the request 110 134 *
Download in other formats:
Powered by Trac 0.10.5
By Edgewall Software.
Visit the Trac open source project at
http://trac.edgewall.com/