Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 public Workout fetchWorkout(final Long id) {
   return workoutStore.fetchWorkout(id);
 }