public void DisjoinTeam(Team team) {

    User user;

    user = userService.findByPrincipal();

    team.getUsers().remove(user);
    user.getTeams().remove(team);

    save(team);
    userService.save(user);
  }
  public void joinTeam(Team team, RequestTeam requestTeam) {

    User user;

    user = requestTeam.getUser();

    requestTeam.setRequest(true);
    team.getUsers().add(user);
    user.getTeams().add(team);

    requestTeamService.save(requestTeam);
    save(team);
    userService.save(user);
  }
  public Team save(Team team) {
    Team result;
    User principal;

    principal = userService.findByPrincipal();

    result = teamRepository.save(team);

    if (team.getId() == 0) {
      principal.getTeamsCreated().add(result);
      principal.getTeams().add(result);
    }

    userService.save(principal);

    return result;
  }
  public void delete(Team team) {

    User captain;

    captain = team.getCaptain();

    for (Tournament t : team.getTournaments()) {
      Assert.isTrue(t.getFinishMoment().before(new Date()));
    }

    captain.getTeams().remove(team);
    captain.getTeamsCreated().remove(team);

    Assert.notNull(team);
    checkPrincipal(team);
    teamRepository.delete(team);

    userService.save(captain);
  }