Ticket #866: LocationListController_delete.patch
| File LocationListController_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 locations |
-
openmrs/trunk/src/web/org/openmrs/web/controller/encounter/LocationListController.java
old new 31 31 import org.openmrs.web.WebConstants; 32 32 import org.springframework.beans.propertyeditors.CustomNumberEditor; 33 33 import org.springframework.context.support.MessageSourceAccessor; 34 import org.springframework.dao.DataIntegrityViolationException; 34 35 import org.springframework.validation.BindException; 35 36 import org.springframework.web.bind.ServletRequestDataBinder; 36 37 import org.springframework.web.servlet.ModelAndView; … … 68 69 69 70 String view = getFormView(); 70 71 if (Context.isAuthenticated()) { 71 String[] locationList = request.getParameterValues("locationId");72 AdministrationService as = Context.getAdministrationService();73 EncounterService es = Context.getEncounterService();74 75 72 String success = ""; 76 73 String error = ""; 77 74 78 75 MessageSourceAccessor msa = getMessageSourceAccessor(); 79 String deleted = msa.getMessage("general.deleted"); 80 String notDeleted = msa.getMessage("general.cannot.delete"); 81 for (String p : locationList) { 82 //TODO convenience method deleteLocation(Integer) ?? 83 try { 84 as.deleteLocation(es.getLocation(Integer.valueOf(p))); 85 if (!success.equals("")) success += "<br/>"; 86 success += p + " " + deleted; 76 77 String[] locationList = request.getParameterValues("locationId"); 78 if(locationList != null){ 79 AdministrationService as = Context.getAdministrationService(); 80 EncounterService es = Context.getEncounterService(); 81 82 String deleted = msa.getMessage("general.deleted"); 83 String notDeleted = msa.getMessage("Location.cannot.delete"); 84 for (String p : locationList) { 85 //TODO convenience method deleteLocation(Integer) ?? 86 try { 87 as.deleteLocation(es.getLocation(Integer.valueOf(p))); 88 if (!success.equals("")) success += "<br/>"; 89 success += p + " " + deleted; 90 } 91 catch(DataIntegrityViolationException e){ 92 error = handleLocationIntegrityException(e,error,notDeleted); 93 } 94 catch (APIException e) { 95 error = handleLocationIntegrityException(e,error,notDeleted); 96 } 87 97 } 88 catch (APIException e) {89 log.warn("Error deleting location", e);90 if (!error.equals("")) error += "<br/>";91 error += p + " " + notDeleted;92 }93 98 } 99 else 100 error = msa.getMessage("Location.select"); 94 101 95 102 view = getSuccessView(); 96 103 if (!success.equals("")) … … 101 108 102 109 return new ModelAndView(new RedirectView(view)); 103 110 } 111 112 /** 113 * 114 * Logs a location delete data integrity violation exception and 115 * returns a user friedly message of the problem that occured. 116 * 117 * @param e the exception. 118 * @param error the error message. 119 * @param notDeleted the not deleted error message. 120 * @return the formatted error message. 121 */ 122 private String handleLocationIntegrityException(Exception e,String error,String notDeleted){ 123 log.warn("Error deleting location", e); 124 if (!error.equals("")) error += "<br/>"; 125 error += notDeleted; 126 return error; 127 } 104 128 105 129 /** 106 130 *
Download in other formats:
Powered by Trac 0.10.5
By Edgewall Software.
Visit the Trac open source project at
http://trac.edgewall.com/