/**
   * The onSubmit function receives the form/command object that was modified by the input form and
   * saves it to the db
   *
   * @see
   *     org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse, java.lang.Object,
   *     org.springframework.validation.BindException)
   */
  protected ModelAndView onSubmit(
      HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors)
      throws Exception {

    HttpSession httpSession = request.getSession();

    String view = getFormView();
    if (Context.isAuthenticated()) {
      String success = "";
      String error = "";

      MessageSourceAccessor msa = getMessageSourceAccessor();

      String[] conceptClassList = request.getParameterValues("conceptClassId");
      if (conceptClassList != null) {
        ConceptService cs = Context.getConceptService();

        String deleted = msa.getMessage("general.deleted");
        String notDeleted = msa.getMessage("ConceptClass.cannot.delete");
        for (String cc : conceptClassList) {
          try {
            cs.purgeConceptClass(cs.getConceptClass(Integer.valueOf(cc)));
            if (!success.equals("")) success += "<br/>";
            success += cc + " " + deleted;
          } catch (DataIntegrityViolationException e) {
            error = handleConceptClassIntegrityException(e, error, notDeleted);
          } catch (APIException e) {
            error = handleConceptClassIntegrityException(e, error, notDeleted);
          }
        }
      } else error = msa.getMessage("ConceptClass.select");

      view = getSuccessView();
      if (!success.equals("")) httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, success);
      if (!error.equals("")) httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, error);
    }

    return new ModelAndView(new RedirectView(view));
  }