Exemplo n.º 1
0
  @RequestMapping(value = "edit/save", method = RequestMethod.POST)
  public String saveInformation(
      @ModelAttribute Person person, BindingResult bindingResult, Model model) {
    if (person != null) {
      System.out.println("Found Person: " + person);
      repository.save(person);

      // This requests access to the spouse's information to be used.
      // This will only be done if person does not already have access.
      Person potentialSpouse = repository.findById(person.getSpouse());
      if (potentialSpouse != null) {
        AccessRequest req =
            accessRequestRepository.findById(
                AccessRequest.makeId(potentialSpouse.getId(), person.getId()));
        if (req == null) {
          accessRequestRepository.save(new AccessRequest(potentialSpouse.getId(), person.getId()));
          System.out.println(new AccessRequest(potentialSpouse.getId(), person.getId()));
        }
      }

    } else {
      System.err.println("Could not find person in database");
    }

    return "redirect:/dashboard";
  }
Exemplo n.º 2
0
  @RequestMapping("/edit")
  public String gatherInformation(HttpServletRequest servletRequest, Model model) {
    if (AccountResolver.INSTANCE.hasAccount(servletRequest)) {
      // a known user has authenticated previously - get the user identity:
      Account account = AccountResolver.INSTANCE.getRequiredAccount(servletRequest);
      Person person = repository.findById(Person.makeId(account.getEmail()));

      if (person == null) {
        person = new Person(account);
        System.out.println(person);
      }

      model.addAttribute("person", person);

      System.out.println(
          person.getIsMarried()
              + "  "
              + person.getSpouse()
              + "  "
              + repository.findById(person.getSpouse()));
      if (person.getIsMarried()) {
        Person spouse = repository.findById(person.getSpouse());
        AccessRequest spouseReq =
            accessRequestRepository.findById(AccessRequest.makeId(spouse.getId(), person.getId()));
        System.out.println(spouseReq);

        model.addAttribute("spouseReq", spouseReq);
        model.addAttribute("spouse", spouse);
      }

      if (person.hasChildren()) {
        // Do nothing for right now
      }
    } else {
      // the current user is unknown - either unauthenticated or a guest.
      // Should redirect
    }

    return "gather_information";
  }