Exemplo n.º 1
0
  /**
   * Processes the submit of update contact form.
   *
   * @param dto The form object.
   * @param result The binding result describing whether there is validation errors.
   * @param attributes The redirect attributes used when request is redirected forward.
   * @return A redirect view name to the view contract page.
   * @throws NotFoundException
   */
  @RequestMapping(value = "/contact/update", method = RequestMethod.POST)
  public String updateContact(
      @Valid @ModelAttribute(MODEL_ATTRIBUTE_CONTACT) ContactDTO dto,
      BindingResult result,
      RedirectAttributes attributes)
      throws NotFoundException {
    LOGGER.debug("Updating contact with information: {}", dto);

    if (result.hasErrors()) {
      LOGGER.debug("Form was submitted with validation errors. Rendering form view.");
      return UPDATE_CONTACT_VIEW;
    }

    Contact updated = service.update(dto);
    LOGGER.debug("Updated contact with information: {}", updated);

    attributes.addAttribute(PARAMETER_CONTACT_ID, updated.getId());
    addFeedbackMessage(
        attributes,
        FEEDBACK_MESSAGE_KEY_CONTACT_UPDATED,
        updated.getFirstName(),
        updated.getLastName());

    return createRedirectViewPath(REQUEST_MAPPING_VIEW_CONTACT);
  }
Exemplo n.º 2
0
  /**
   * Shows the home page.
   *
   * @param model The model.
   * @return The name of the home page view.
   */
  @RequestMapping(value = "/", method = RequestMethod.GET)
  public String showHomePage(Model model) {
    LOGGER.debug("Rendering home page");

    List<Contact> contacts = service.findAll();
    model.addAttribute(MODEL_ATTRIBUTE_CONTACTS, contacts);

    return HOME_VIEW;
  }
Exemplo n.º 3
0
  /**
   * Shows the view contact page
   *
   * @param id The id of the viewed contact.
   * @param model The model.
   * @return The name of the view contact view.
   * @throws NotFoundException if not contact is found iwth the given id.
   */
  @RequestMapping(value = "/contact/{id}", method = RequestMethod.GET)
  public String showContactPage(@PathVariable("id") Long id, Model model) throws NotFoundException {
    LOGGER.debug("Showing contact page for contact with id: {}", id);

    Contact found = service.findById(id);
    LOGGER.debug("Found contact: {}", found);

    model.addAttribute(MODEL_ATTRIBUTE_CONTACT, found);
    return CONTACT_VIEW;
  }
Exemplo n.º 4
0
  /**
   * Processes delete contact ajax request.
   *
   * @param id The id of the deleted contact.
   * @return The feedback message.
   * @throws NotFoundException if no contact is found with the given id.
   */
  @RequestMapping(value = "/contact/{id}", method = RequestMethod.DELETE)
  @ResponseBody
  public String deleteContact(@PathVariable("id") Long id) throws NotFoundException {
    LOGGER.debug("Deleting contact with id: {}", id);

    Contact deleted = service.deleteById(id);
    LOGGER.debug("Deleted contact: {}", deleted);

    return getMessage(
        FEEDBACK_MESSAGE_KEY_CONTACT_DELETED, deleted.getFirstName(), deleted.getLastName());
  }
Exemplo n.º 5
0
  /**
   * Shows update contact page.
   *
   * @param id The id of the updated contact.
   * @param model The model.
   * @return The name of the update contact view.
   * @throws NotFoundException if no contact is found with the given id.
   */
  @RequestMapping(value = "/contact/update/{id}", method = RequestMethod.GET)
  public String showUpdateContactPage(@PathVariable("id") Long id, Model model)
      throws NotFoundException {
    LOGGER.debug("Showing edit contact for a contact with id: {}", id);

    Contact updated = service.findById(id);
    LOGGER.debug("Found contact: {}", updated);

    ContactDTO formObject = createFormObject(updated);
    model.addAttribute(MODEL_ATTRIBUTE_CONTACT, formObject);

    return UPDATE_CONTACT_VIEW;
  }