예제 #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);
  }
예제 #2
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());
  }
예제 #3
0
  /**
   * Creates a form object.
   *
   * @param model The model in which the form object is based.
   * @return The created form object.
   */
  private ContactDTO createFormObject(Contact model) {
    ContactDTO dto = new ContactDTO();

    dto.setId(model.getId());

    dto.setFirstName(model.getFirstName());
    dto.setLastName(model.getLastName());
    dto.setEmailAddress(model.getEmailAddress());
    dto.setPhoneNumber(model.getPhoneNumber());

    Address address = model.getAddress();
    if (address != null) {
      dto.setStreetAddress(address.getStreetAddress());
      dto.setPostCode(address.getPostCode());
      dto.setPostOffice(address.getPostOffice());
      dto.setState(address.getState());
      dto.setCountry(address.getCountry());
    }

    return dto;
  }