/**
  * Checks if the given user group exists
  *
  * @param int $id
  *
  * @return ProjectUGroup
  *
  * @throws 404
  */
 private function getExistingUserGroup($id)
 {
     $this->checkIdIsAppropriate($id);
     $values = UserGroupRepresentation::getProjectAndUserGroupFromRESTId($id);
     $user_group_id = $values['user_group_id'];
     $user_group = $this->ugroup_manager->getById($user_group_id);
     if ($user_group->getId() === 0) {
         throw new RestException(404, 'User Group does not exist');
     }
     if (!$user_group->isStatic()) {
         $user_group->setProjectId($values['project_id']);
     }
     if ($user_group->isStatic() && $values['project_id'] && $values['project_id'] != $user_group->getProjectId()) {
         throw new RestException(404, 'User Group does not exist in project');
     }
     return $user_group;
 }