private WorkoutsData<DisciplineData.Count> fetchStatisticsData(
     final Group group, final int firstIndex, String discipline) {
   if (discipline != null && discipline.length() == 0) discipline = null;
   final PaginatedCollection<Workout> workouts =
       workoutStore.getWorkouts(group, discipline, firstIndex, 10);
   final Double globalDistance = fetchGlobalDistance(group);
   final List<DisciplineData<DisciplineData.Count>> disciplineData =
       aggregateByDiscipline(group, DisciplineAggregator.COUNT_AGGREGATOR);
   return new WorkoutsData<DisciplineData.Count>(workouts, globalDistance, disciplineData);
 }
 public Workout createWorkout(
     final Date date,
     final User user,
     final Long duration,
     final Double distance,
     final Long energy,
     final String discipline,
     final String debriefing,
     final String nikePlusId) {
   return workoutStore.createWorkout(
       date, user, duration, distance, energy, discipline, debriefing, nikePlusId);
 }
 private WorkoutsData<DisciplineData.Count> fetchStatisticsData(
     final User user,
     final Collection<String> disciplines,
     final int firstIndex,
     final int pageSize) {
   final PaginatedCollection<Workout> workouts =
       workoutStore.getWorkouts(user, disciplines, firstIndex, pageSize);
   final Double globalDistance = fetchGlobalDistance(user);
   final List<DisciplineData<DisciplineData.Count>> disciplineData =
       aggregateByDiscipline(user, DisciplineAggregator.COUNT_AGGREGATOR);
   return new WorkoutsData<DisciplineData.Count>(workouts, globalDistance, disciplineData);
 }
 private PrivateMessage createMessage(
     final User sender,
     final User receiver,
     final String content,
     final Date date,
     final Long workoutId)
     throws WorkoutNotFoundException {
   final Workout workout = workoutId != null ? workoutStore.fetchWorkout(workoutId) : null;
   final PrivateMessageImpl message =
       new PrivateMessageImpl(sender, receiver, date, content, workout);
   entityManager.persist(message);
   return message;
 }
 public WorkoutPageData fetchWorkoutPageData(
     final User currentUser,
     final Long workoutId,
     final int similarPage,
     final int workoutStartIndex,
     final int messagesStartIndex,
     final int privateMessagesPageIndex)
     throws WorkoutNotFoundException {
   final Workout workout = workoutStore.fetchWorkout(workoutId);
   final PaginatedCollection<PrivateMessage> emptyPage = emptyPage();
   final PaginatedCollection<PrivateMessage> privateConversation =
       currentUser == null
           ? emptyPage
           : fetchPrivateConversation(
               currentUser, workout.getUser().getId(), privateMessagesPageIndex);
   return new WorkoutPageData(
       workout,
       fetchPublicMessages(Topic.Kind.WORKOUT, workoutId, 5, messagesStartIndex),
       getSimilarWorkouts(workout, similarPage),
       workoutStore.getWorkouts(workout.getUser(), EMPTY_STRING_LIST, workoutStartIndex, 10),
       privateConversation);
 }
 public PublicMessage createPublicMessage(
     final User sender,
     final String content,
     final Date date,
     final Long topicId,
     final Topic.Kind topicKind)
     throws WorkoutNotFoundException {
   final PublicMessageImpl message;
   if (topicKind == Topic.Kind.WORKOUT) {
     final Workout workout = workoutStore.fetchWorkout(topicId);
     message = new PublicMessageImpl(sender, date, content, workout);
   } else {
     final GroupImpl group = entityManager.find(GroupImpl.class, topicId);
     message = new PublicMessageImpl(sender, date, content, group);
   }
   entityManager.persist(message);
   return message;
 }
 public void updateWorkout(
     final Long id,
     final User user,
     final Date date,
     final Long duration,
     final Double distance,
     final Long energy,
     final String discipline,
     final String debriefing,
     final String trackId)
     throws WorkoutNotFoundException, AccessDeniedException, TrackNotFoundException {
   final TrackImpl track =
       trackId != null && !trackId.isEmpty()
           ? fetchTrackForUpdate(user, Long.parseLong(trackId))
           : null;
   workoutStore.updateWorkout(
       id, user, date, duration, distance, energy, discipline, debriefing, track);
 }
 public ConversationData fetchConvertationData(
     final User sender, final String receiver, final Long aboutWorkoutId, final int startIndex)
     throws WorkoutNotFoundException {
   final Workout aboutWorkout =
       aboutWorkoutId == null ? null : workoutStore.fetchWorkout(aboutWorkoutId);
   final ConversationData conversationData =
       new ConversationData(
           fetchConversation(sender, receiver, startIndex),
           aboutWorkout,
           UserStringImpl.valueOf(receiver));
   for (final PrivateMessage privateMessage : conversationData.privateMessages) {
     final PrivateMessageImpl message1 = (PrivateMessageImpl) privateMessage;
     if (!message1.isRead() && message1.getReceiver().equals(sender)) {
       message1.setRead(true);
       message1.setNew(true);
       entityManager.merge(privateMessage);
     }
   }
   return conversationData;
 }
 public BibPageData fetchBibPageData(
     final User currentUser,
     final Long targetUserId,
     final int workoutStartIndex,
     final int privateMessagesPageIndex)
     throws UserNotFoundException {
   final User target;
   final PaginatedCollection<PrivateMessage> privateMessages;
   if (currentUser == null) {
     target = fetchUser(targetUserId);
     privateMessages = emptyPage();
   } else {
     target = currentUser.getId().equals(targetUserId) ? currentUser : fetchUser(targetUserId);
     privateMessages =
         fetchPrivateConversation(currentUser, targetUserId, privateMessagesPageIndex);
   }
   final PaginatedCollection<Workout> workouts =
       workoutStore.getWorkouts(target, EMPTY_STRING_LIST, workoutStartIndex, 10);
   return new BibPageData(target, privateMessages, workouts);
 }
 public Workout fetchWorkout(final Long id) {
   return workoutStore.fetchWorkout(id);
 }
 public void checkEditionGrant(final Workout workout, final User user)
     throws AccessDeniedException {
   workoutStore.checkEditionGrant(workout, user);
 }
 public void setWorkoutParticipants(
     final User user, final Long workoutId, final String[] participants)
     throws AccessDeniedException {
   workoutStore.setWorkoutParticipants(user, workoutId, participants);
 }
 private PaginatedCollection<Workout> getSimilarWorkouts(
     final Workout workout, final int similarPageIndex) {
   return workoutStore.getSimilarWorkouts(workout, similarPageIndex);
 }
 public Workout fetchWorkout(final Long id, final User user, final boolean willWrite)
     throws WorkoutNotFoundException, AccessDeniedException {
   return workoutStore.fetchWorkoutForEdition(id, user, willWrite);
 }