/**
   * 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));
  }
示例#2
0
  /**
   * @see FormatTag#printConcept(StringBuilder,Concept)
   * @verifies print the name with the correct name, and type
   */
  @Test
  public void printConcept_shouldPrintTheNameWithTheCorrectLocaleNameAndType() throws Exception {
    ConceptService service = Context.getConceptService();
    Locale locale = Context.getLocale();
    ConceptNameTag tag = service.getConceptNameTag(5);
    ConceptNameTag anotherTag = service.getConceptNameTag(6);
    Context.flushSession();

    Concept c = new Concept();
    c.addName(
        buildName("English fully specified", locale, true, ConceptNameType.FULLY_SPECIFIED, null));
    c.addName(buildName("English synonym", locale, false, null, null));
    c.addName(buildName("English tag", locale, false, null, tag));
    c.addName(buildName("English another tag", locale, false, null, anotherTag));
    c.setDatatype(service.getConceptDatatype(1));
    c.setConceptClass(service.getConceptClass(1));

    Context.getConceptService().saveConcept(c);

    assertPrintConcept("English fully specified", c, null, null);
    assertPrintConcept(
        "English fully specified", c, ConceptNameType.FULLY_SPECIFIED.toString(), null);
    assertPrintConcept("English tag", c, null, tag.getTag());
  }