Ticket #866: PatientIdentifierTypeListController.patch
| File PatientIdentifierTypeListController.patch, 3.0 kB (added by dkayiwa, 7 months ago) |
|---|
patch for displaying a user friendly messages for exceptions thro.wn when attempting to delete patient identifier types |
-
openmrs/trunk/src/web/org/openmrs/web/controller/patient/PatientIdentifierTypeListController.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 72 String success = ""; 73 String error = ""; 74 75 MessageSourceAccessor msa = getMessageSourceAccessor(); 76 72 77 String[] identifierTypeList = request.getParameterValues("patientIdentifierTypeId"); 78 if(identifierTypeList != null){ 73 79 AdministrationService as = Context.getAdministrationService(); 74 80 PatientService ps = Context.getPatientService(); 75 81 76 String success = "";77 String error = "";78 79 MessageSourceAccessor msa = getMessageSourceAccessor();80 82 String deleted = msa.getMessage("general.deleted"); 81 String notDeleted = msa.getMessage(" general.cannot.delete");83 String notDeleted = msa.getMessage("PatientIdentifierType.cannot.delete"); 82 84 for (String p : identifierTypeList) { 83 85 try { 84 86 as.deletePatientIdentifierType(ps.getPatientIdentifierType(Integer.valueOf(p))); 85 87 if (!success.equals("")) success += "<br/>"; 86 88 success += p + " " + deleted; 87 89 } 90 catch(DataIntegrityViolationException e){ 91 error = handleIdentifierIntegrityException(e,error,notDeleted); 92 } 88 93 catch (APIException e) { 89 log.warn("Error deleting patient identifier type", e); 90 if (!error.equals("")) error += "<br/>"; 91 error += p + " " + notDeleted; 94 error = handleIdentifierIntegrityException(e,error,notDeleted); 92 95 } 93 96 } 97 } 98 else 99 error = msa.getMessage("PatientIdentifierType.select"); 94 100 95 101 view = getSuccessView(); 96 102 if (!success.equals("")) … … 101 107 102 108 return new ModelAndView(new RedirectView(view)); 103 109 } 110 111 /** 112 * 113 * Logs a Patient Identifier Type delete data integrity violation exception and 114 * returns a user friedly message of the problem that occured. 115 * 116 * @param e the exception. 117 * @param error the error message. 118 * @param notDeleted the role not deleted error message. 119 * @return the formatted error message. 120 */ 121 private String handleIdentifierIntegrityException(Exception e,String error,String notDeleted){ 122 log.warn("Error deleting patient identifier type", e); 123 if (!error.equals("")) error += "<br/>"; 124 error += notDeleted; 125 return error; 126 } 104 127 105 128 /** 106 129 *
Download in other formats:
Powered by Trac 0.10.5
By Edgewall Software.
Visit the Trac open source project at
http://trac.edgewall.com/