Ticket #866: ConceptClassListController_delete.patch
| File ConceptClassListController_delete.patch, 3.2 kB (added by dkayiwa, 7 months ago) |
|---|
patch for displaying a user friendly messages for exceptions thro.wn when attempting to delete concepts |
-
openmrs/trunk/src/web/org/openmrs/web/controller/concept/ConceptClassListController.java
old new 30 30 import org.openmrs.web.WebConstants; 31 31 import org.springframework.beans.propertyeditors.CustomNumberEditor; 32 32 import org.springframework.context.support.MessageSourceAccessor; 33 import org.springframework.dao.DataIntegrityViolationException; 33 34 import org.springframework.validation.BindException; 34 35 import org.springframework.web.bind.ServletRequestDataBinder; 35 36 import org.springframework.web.servlet.ModelAndView; … … 67 68 68 69 String view = getFormView(); 69 70 if (Context.isAuthenticated()) { 70 71 String[] conceptClassList = request.getParameterValues("conceptClassId");72 ConceptService cs = Context.getConceptService();73 74 71 String success = ""; 75 72 String error = ""; 76 73 77 74 MessageSourceAccessor msa = getMessageSourceAccessor(); 78 String deleted = msa.getMessage("general.deleted"); 79 String notDeleted = msa.getMessage("general.cannot.delete"); 80 for (String cc : conceptClassList) { 81 try { 82 cs.purgeConceptClass(cs.getConceptClass(Integer.valueOf(cc))); 83 if (!success.equals("")) success += "<br/>"; 84 success += cc + " " + deleted; 75 76 String[] conceptClassList = request.getParameterValues("conceptClassId"); 77 if(conceptClassList != null){ 78 ConceptService cs = Context.getConceptService(); 79 80 String deleted = msa.getMessage("general.deleted"); 81 String notDeleted = msa.getMessage("ConceptClass.cannot.delete"); 82 for (String cc : conceptClassList) { 83 try { 84 cs.purgeConceptClass(cs.getConceptClass(Integer.valueOf(cc))); 85 if (!success.equals("")) success += "<br/>"; 86 success += cc + " " + deleted; 87 } 88 catch(DataIntegrityViolationException e){ 89 error = handleConceptClassIntegrityException(e,error,notDeleted); 90 } 91 catch (APIException e) { 92 error = handleConceptClassIntegrityException(e,error,notDeleted); 93 } 85 94 } 86 catch (APIException e) {87 log.warn("Error deleting concept class", e);88 if (!error.equals("")) error += "<br/>";89 error += cc + " " + notDeleted;90 }91 95 } 96 else 97 error = msa.getMessage("ConceptClass.select"); 92 98 93 99 view = getSuccessView(); 94 100 if (!success.equals("")) … … 99 105 100 106 return new ModelAndView(new RedirectView(view)); 101 107 } 108 109 /** 110 * 111 * Logs a concept class delete data integrity violation exception and 112 * returns a user friedly message of the problem that occured. 113 * 114 * @param e the exception. 115 * @param error the error message. 116 * @param notDeleted the not deleted error message. 117 * @return the formatted error message. 118 */ 119 private String handleConceptClassIntegrityException(Exception e,String error,String notDeleted){ 120 log.warn("Error deleting concept class", e); 121 if (!error.equals("")) error += "<br/>"; 122 error += notDeleted; 123 return error; 124 } 102 125 103 126 /** 104 127 *
Download in other formats:
Powered by Trac 0.10.5
By Edgewall Software.
Visit the Trac open source project at
http://trac.edgewall.com/