Ticket #866: RoleListController_delete.patch
| File RoleListController_delete.patch, 3.3 kB (added by dkayiwa, 7 months ago) |
|---|
patch for displaying a user friendly messages for exceptions thro.wn when attempting to delete roles |
-
openmrs/trunk/src/web/org/openmrs/web/controller/user/RoleListController.java
old new 34 34 import org.openmrs.web.WebConstants; 35 35 import org.springframework.beans.propertyeditors.CustomNumberEditor; 36 36 import org.springframework.context.support.MessageSourceAccessor; 37 import org.springframework.dao.DataIntegrityViolationException; 37 38 import org.springframework.validation.BindException; 38 39 import org.springframework.web.bind.ServletRequestDataBinder; 39 40 import org.springframework.web.bind.ServletRequestUtils; … … 73 74 Locale locale = request.getLocale(); 74 75 String view = getFormView(); 75 76 if (Context.isAuthenticated()) { 76 String[] roleList = ServletRequestUtils.getStringParameters(request, "roleId");77 AdministrationService as = Context.getAdministrationService();78 UserService us = Context.getUserService();79 80 77 String success = ""; 81 78 String error = ""; 82 79 83 80 MessageSourceAccessor msa = getMessageSourceAccessor(); 84 String deleted = msa.getMessage("general.deleted"); 85 String notDeleted = msa.getMessage("general.cannot.delete"); 86 for (String p : roleList) { 87 //TODO convenience method deleteRole(String) ?? 88 try { 89 as.deleteRole(us.getRole(p)); 90 if (!success.equals("")) success += "<br/>"; 91 success += p + " " + deleted; 81 82 String[] roleList = ServletRequestUtils.getStringParameters(request, "roleId"); 83 if(roleList != null){ 84 AdministrationService as = Context.getAdministrationService(); 85 UserService us = Context.getUserService(); 86 87 String deleted = msa.getMessage("general.deleted"); 88 String notDeleted = msa.getMessage("Role.cannot.delete"); 89 for (String p : roleList) { 90 //TODO convenience method deleteRole(String) ?? 91 try { 92 as.deleteRole(us.getRole(p)); 93 if (!success.equals("")) success += "<br/>"; 94 success += p + " " + deleted; 95 } 96 catch(DataIntegrityViolationException e){ 97 error = handleRoleIntegrityException(e,error,notDeleted); 98 } 99 catch (APIException e) { 100 error = handleRoleIntegrityException(e,error,notDeleted); 101 } 92 102 } 93 catch (APIException e) {94 log.warn(e);95 if (!error.equals("")) error += "<br/>";96 error += p + " " + notDeleted;97 }98 103 } 104 else 105 error = msa.getMessage("Role.select"); 99 106 100 107 view = getSuccessView(); 101 108 if (!success.equals("")) … … 106 113 107 114 return new ModelAndView(new RedirectView(view)); 108 115 } 116 117 /** 118 * 119 * Logs a role delete data integrity violation exception and 120 * returns a user friedly message of the problem that occured. 121 * 122 * @param e the exception. 123 * @param error the error message. 124 * @param notDeleted the role not deleted error message. 125 * @return the formatted error message. 126 */ 127 private String handleRoleIntegrityException(Exception e,String error,String notDeleted){ 128 log.warn("Error deleting role", e); 129 if (!error.equals("")) error += "<br/>"; 130 error += notDeleted; 131 return error; 132 } 109 133 110 134 /** 111 135 *
Download in other formats:
Powered by Trac 0.10.5
By Edgewall Software.
Visit the Trac open source project at
http://trac.edgewall.com/