Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

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  
    3030import org.openmrs.web.WebConstants; 
    3131import org.springframework.beans.propertyeditors.CustomNumberEditor; 
    3232import org.springframework.context.support.MessageSourceAccessor; 
     33import org.springframework.dao.DataIntegrityViolationException; 
    3334import org.springframework.validation.BindException; 
    3435import org.springframework.web.bind.ServletRequestDataBinder; 
    3536import org.springframework.web.servlet.ModelAndView; 
     
    6768                 
    6869                String view = getFormView(); 
    6970                if (Context.isAuthenticated()) { 
    70                          
    71                         String[] conceptClassList = request.getParameterValues("conceptClassId"); 
    72                         ConceptService cs = Context.getConceptService(); 
    73                          
    7471                        String success = ""; 
    7572                        String error = ""; 
    7673 
    7774                        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                                        } 
    8594                                } 
    86                                 catch (APIException e) { 
    87                                         log.warn("Error deleting concept class", e); 
    88                                         if (!error.equals("")) error += "<br/>"; 
    89                                         error += cc + " " + notDeleted; 
    90                                 } 
    9195                        } 
     96                        else 
     97                                error = msa.getMessage("ConceptClass.select"); 
    9298                         
    9399                        view = getSuccessView(); 
    94100                        if (!success.equals("")) 
     
    99105                 
    100106                return new ModelAndView(new RedirectView(view)); 
    101107        } 
     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        } 
    102125 
    103126        /** 
    104127         *