@@ -0,0 +1,2650 @@
+/*%0A * Copyright 2011 SURFnet bv, The Netherlands%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage nl.surfnet.coin.teams.util;%0A%0Aimport nl.surfnet.coin.teams.domain.Member;%0Aimport nl.surfnet.coin.teams.domain.Role;%0Aimport nl.surfnet.coin.teams.domain.Team;%0Aimport nl.surfnet.coin.teams.service.TeamService;%0Aimport org.opensocial.models.Person;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.stereotype.Component;%0Aimport org.springframework.util.StringUtils;%0A%0Aimport javax.servlet.http.HttpServletRequest;%0A%0A/**%0A * This class includes methods that are often used by controllers%0A */%0A@Component(%22controllerUtil%22)%0Apublic class ControllerUtil %7B%0A%0A  @Autowired%0A  private TeamService teamService;%0A%0A  private ControllerUtil() %7B%0A  %7D%0A%0A  /**%0A   * Get the team from the %7B@link HttpServletRequest%7D request.%0A   *%0A   * @param request the %7B@link HttpServletRequest%7D%0A   * @return The %7B@link Team%7D team%0A   * @throws RuntimeException if the team cannot be found%0A   */%0A  public Team getTeam(HttpServletRequest request) %7B%0A    String teamId = request.getParameter(%22team%22);%0A    Team team = null;%0A%0A    if (StringUtils.hasText(teamId)) %7B%0A      team = teamService.findTeamById(teamId);%0A    %7D%0A    if (team == null) %7B%0A      throw new RuntimeException(%22Team (%22 + teamId + %22) not found%22);%0A    %7D%0A    return team;%0A  %7D%0A%0A  /**%0A   * Checks if the current user has administrative privileges (whether he is admin OR manager) for a given team.%0A   *%0A   * @param person %7B@link Person%7D%0A   * @param teamId %7B@link String%7D the team Id for which the person's privileges are checked%0A   * @return %7B@link boolean%7D %3Ccode%3Etrue/code%3E if the user is admin AND/OR manager %3Ccode%3Efalse%3C/code%3E if the user isn't%0A   */%0A  public boolean hasUserAdministrativePrivileges(Person person, String teamId) %7B%0A    // Check if the requester is member of the team AND%0A    // Check if the requester has the role admin or manager, so he is allowed to invite new members.%0A    Member member = teamService.findMember(teamId, person.getId());%0A    return member != null && (member.getRoles().contains(Role.Admin) %7C%7C member.getRoles().contains(Role.Manager));%0A  %7D%0A%7D

Add controllerUtil for common methods among controllers