Ejemplo n.º 1
0
  @Override
  public Comment getComment(String commentId) {
    FirebaseSyncRequester<Comment> commentRequester = newFirebaseSyncRequesterForComment(commentId);

    if (!commentRequester.exists()) {
      throw new IllegalArgumentException("Comment does not exist");
    }

    return commentRequester.get();
  }
  @Override
  public String[] getCategories() {
    Firebase fb = new Firebase(FIREBASE_CATEGORIES_URL);

    FirebaseSyncRequester<Map> categoriesRequester = new FirebaseSyncRequester<>(fb, Map.class);

    Map<String, Boolean> categoryMap = categoriesRequester.get();

    return categoryMap.keySet().toArray(new String[categoryMap.size()]);
  }
Ejemplo n.º 3
0
  @Override
  public Comment downvoteComment(String commentId) {
    Firebase commentFirebaseRef = newFirebaseRefForComment(commentId);
    FirebaseSyncRequester<Comment> commentRequester =
        new FirebaseSyncRequester<>(commentFirebaseRef, Comment.class);

    Comment downvotedComment = null;

    if (commentRequester.exists()) {
      downvotedComment = newDownvotedComment(commentRequester.get());
      commentFirebaseRef.setValue(newDownvotedComment(downvotedComment));
    } else {
      throw new IllegalArgumentException("Comment with id " + commentId + " does not exist");
    }

    return downvotedComment;
  }
Ejemplo n.º 4
0
  @Override
  public Comment deleteComment(String commentId) {
    Firebase firebaseCommentRef = newFirebaseRefForComment(commentId);
    FirebaseSyncRequester<Comment> commentRequester =
        new FirebaseSyncRequester<>(firebaseCommentRef, Comment.class);

    Comment commentToReturn = null;

    if (commentRequester.exists()) {
      final CountDownLatch latch = new CountDownLatch(1);

      firebaseCommentRef.removeValue(
          new Firebase.CompletionListener() {
            @Override
            public void onComplete(FirebaseError firebaseError, Firebase firebase) {
              if (firebaseError != null) {
                throw firebaseError.toException();
              }

              latch.countDown();
            }
          });

      try {
        latch.await();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      commentToReturn = commentRequester.get();
    } else {
      throw new IllegalArgumentException("Comment with id " + commentId + " does not exist.");
    }

    return commentToReturn;
  }