public void addWorkoutParticipants( final User user, final Long workoutId, final Long... participants) throws AccessDeniedException { final WorkoutImpl workout = entityManager.find(WorkoutImpl.class, workoutId); if (!workout.getUser().equals(user)) throw new AccessDeniedException(); final Set<Long> participantsSet = new HashSet<Long>(Arrays.asList(participants)); final Query query = createParticipantsInsertUnionQuery(workoutId, participantsSet); query.executeUpdate(); }
public void removeWorkoutParticipants( final User user, final Long workoutId, final Long... participants) throws AccessDeniedException { final WorkoutImpl workout = entityManager.find(WorkoutImpl.class, workoutId); if (!workout.getUser().equals(user)) throw new AccessDeniedException(); final Set<Long> participantsWithoutSelf = new HashSet<Long>(Arrays.asList(participants)); participantsWithoutSelf.remove(user.getId()); final Query query = createParticipantsDeleteQuery(workoutId, participantsWithoutSelf); query.executeUpdate(); }