Search in sources :

Example 1 with UserPratilipiData

use of com.pratilipi.data.client.UserPratilipiData in project pratilipi by Pratilipi.

the class EmailDataUtil method _createDataModelForCommentReviewEmail.

private static Object[] _createDataModelForCommentReviewEmail(Long commentId) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    CommentData comment = CommentDataUtil.createCommentData(dataAccessor.getComment(commentId));
    comment.setUser(UserDataUtil.createUserData(dataAccessor.getUser(comment.getUserId())));
    UserPratilipiData review = UserPratilipiDataUtil.createUserPratilipiData(dataAccessor.getUserPratilipi(comment.getParentId()));
    PratilipiData pratilipi = PratilipiDataUtil.createPratilipiData(dataAccessor.getPratilipi(review.getPratilipiId()));
    Map<String, Object> dataModel = new HashMap<>();
    dataModel.put("pratilipi_title", pratilipi.getTitle() != null ? pratilipi.getTitle() : pratilipi.getTitleEn());
    dataModel.put("pratilipi_page_url", _getDomainName(pratilipi.getLanguage()) + pratilipi.getPageUrl());
    dataModel.put("reviewer_name", review.getUser().getAuthor().getName() != null ? review.getUser().getAuthor().getName() : review.getUser().getAuthor().getNameEn());
    dataModel.put("reviewer_page_url", _getDomainName(review.getUser().getAuthor().getLanguage()) + review.getUser().getProfilePageUrl());
    dataModel.put("reviewer_image_url", review.getUser().getAuthor().getProfileImageUrl(64));
    dataModel.put("review_date", _getDateFormat(review.getReviewDate()));
    dataModel.put("review_review", HtmlUtil.truncateText(review.getReview(), 250));
    dataModel.put("commentor_name", comment.getUser().getAuthor().getName() != null ? comment.getUser().getAuthor().getName() : comment.getUser().getAuthor().getNameEn());
    dataModel.put("commentor_page_url", _getDomainName(comment.getUser().getAuthor().getLanguage()) + comment.getUser().getProfilePageUrl());
    dataModel.put("commentor_image_url", comment.getUser().getAuthor().getProfileImageUrl(50));
    dataModel.put("comment_date", _getDateFormat(comment.getCreationDate()));
    dataModel.put("comment_comment", HtmlUtil.truncateText(comment.getContent(), 200));
    return new Object[] { dataModel, pratilipi.getLanguage() };
}
Also used : HashMap(java.util.HashMap) DataAccessor(com.pratilipi.data.DataAccessor) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData) PratilipiData(com.pratilipi.data.client.PratilipiData) CommentData(com.pratilipi.data.client.CommentData) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData)

Example 2 with UserPratilipiData

use of com.pratilipi.data.client.UserPratilipiData in project pratilipi by Pratilipi.

the class EmailDataUtil method _createDataModelForUserPratilipiEmail.

private static Object[] _createDataModelForUserPratilipiEmail(String userPratilipiId) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    UserPratilipiData userPratilipi = UserPratilipiDataUtil.createUserPratilipiData(dataAccessor.getUserPratilipi(userPratilipiId));
    PratilipiData pratilipi = PratilipiDataUtil.createPratilipiData(dataAccessor.getPratilipi(userPratilipi.getPratilipiId()));
    UserData reviewer = UserDataUtil.createUserData(dataAccessor.getUser(userPratilipi.getUserId()));
    Map<String, Object> dataModel = new HashMap<>();
    dataModel.put("pratilipi_title", pratilipi.getTitle() != null ? pratilipi.getTitle() : pratilipi.getTitleEn());
    dataModel.put("pratilipi_page_url", _getDomainName(pratilipi.getLanguage()) + pratilipi.getPageUrl());
    dataModel.put("reviewer_name", reviewer.getAuthor().getName() != null ? reviewer.getAuthor().getName() : reviewer.getAuthor().getNameEn());
    dataModel.put("reviewer_page_url", _getDomainName(pratilipi.getLanguage()) + reviewer.getProfilePageUrl());
    dataModel.put("reviewer_image_url", reviewer.getAuthor().getProfileImageUrl(100));
    dataModel.put("review_creation_date", _getDateFormat(userPratilipi.getReviewDate()));
    if (userPratilipi.getRating() != null)
        dataModel.put("rating", userPratilipi.getRating());
    if (userPratilipi.getReview() != null)
        dataModel.put("review_review", HtmlUtil.truncateText(userPratilipi.getReview(), 250));
    if (userPratilipi.getCommentCount() != null)
        dataModel.put("review_comment_count", userPratilipi.getCommentCount().toString());
    return new Object[] { dataModel, pratilipi.getLanguage() };
}
Also used : UserData(com.pratilipi.data.client.UserData) HashMap(java.util.HashMap) DataAccessor(com.pratilipi.data.DataAccessor) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData) PratilipiData(com.pratilipi.data.client.PratilipiData) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData)

Example 3 with UserPratilipiData

use of com.pratilipi.data.client.UserPratilipiData in project pratilipi by Pratilipi.

the class UserPratilipiDataUtil method createUserPratilipiData.

public static UserPratilipiData createUserPratilipiData(UserPratilipi userPratilipi) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    User user = dataAccessor.getUser(userPratilipi.getUserId());
    UserData userData = UserDataUtil.createUserData(user);
    PratilipiReviewsDoc reviewsDoc = docAccessor.getPratilipiReviewsDoc(userPratilipi.getPratilipiId());
    UserPratilipiData userPratilipiData = new UserPratilipiData();
    userPratilipiData.setId(userPratilipi.getId());
    userPratilipiData.setUserId(userPratilipi.getUserId());
    userPratilipiData.setPratilipiId(userPratilipi.getPratilipiId());
    userPratilipiData.setUser(userData);
    userPratilipiData.setUserName(userData.getDisplayName());
    userPratilipiData.setUserImageUrl(userData.getProfileImageUrl());
    userPratilipiData.setUserProfilePageUrl(userData.getProfilePageUrl());
    userPratilipiData.setRating(userPratilipi.getRating());
    userPratilipiData.setReview(processReview(userPratilipi.getReviewTitle(), userPratilipi.getReview()));
    userPratilipiData.setReviewState(userPratilipi.getReviewState());
    userPratilipiData.setReviewDate(userPratilipi.getReviewDate());
    for (UserPratilipiDoc review : reviewsDoc.getReviews()) {
        if (review.getId().equals(userPratilipi.getId())) {
            userPratilipiData.setCommentCount(review.getCommentCount());
            userPratilipiData.setLikeCount(review.getLikeCount());
            userPratilipiData.setLiked(review.getLikedByUserIds().contains(AccessTokenFilter.getAccessToken().getUserId()));
            break;
        }
    }
    userPratilipiData.setAddedToLib(userPratilipi.isAddedToLib());
    userPratilipiData.setAccessToReview(hasAccessToUpdateUserPratilipiData(userPratilipi, AccessType.USER_PRATILIPI_REVIEW));
    return userPratilipiData;
}
Also used : User(com.pratilipi.data.type.User) UserData(com.pratilipi.data.client.UserData) DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) UserPratilipiDoc(com.pratilipi.data.type.UserPratilipiDoc) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData) PratilipiReviewsDoc(com.pratilipi.data.type.PratilipiReviewsDoc)

Example 4 with UserPratilipiData

use of com.pratilipi.data.client.UserPratilipiData in project pratilipi by Pratilipi.

the class UserPratilipiDataUtil method getPratilipiReviewList.

public static DataListCursorTuple<UserPratilipiData> getPratilipiReviewList(Long pratilipiId, String cursor, Integer offset, Integer resultCount) throws UnexpectedServerException {
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    PratilipiReviewsDoc reviewsDoc = docAccessor.getPratilipiReviewsDoc(pratilipiId);
    List<UserPratilipiDoc> reviewDocList = reviewsDoc.getReviews();
    // Reverse Sort
    Collections.reverse(reviewDocList);
    // Using next UserPratilipiId as the cursor
    int fromIndex = 0;
    if (cursor != null && !cursor.equals("-1")) {
        for (int i = 0; i < reviewDocList.size(); i++) {
            if (reviewDocList.get(i).getId().equals(cursor)) {
                fromIndex = i;
                break;
            }
        }
        if (offset != null)
            fromIndex = fromIndex + offset;
    }
    if (fromIndex >= reviewDocList.size() || (cursor != null && cursor.equals("-1"))) {
        return new DataListCursorTuple<UserPratilipiData>(new ArrayList<UserPratilipiData>(), "-1", (long) (int) reviewsDoc.getReviews().size());
    }
    int toIndex = resultCount == null ? reviewDocList.size() : Math.min(fromIndex + resultCount, reviewDocList.size());
    // Next cursor
    cursor = toIndex == reviewDocList.size() ? "-1" : reviewDocList.get(toIndex).getId();
    reviewDocList = reviewDocList.subList(fromIndex, toIndex);
    List<UserPratilipiData> userPratilipiDataList = new ArrayList<>(reviewDocList.size());
    for (UserPratilipiDoc review : reviewDocList) userPratilipiDataList.add(createUserPratilipiData(review));
    return new DataListCursorTuple<UserPratilipiData>(userPratilipiDataList, cursor, (long) (int) reviewsDoc.getReviews().size());
}
Also used : DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) DocAccessor(com.pratilipi.data.DocAccessor) UserPratilipiDoc(com.pratilipi.data.type.UserPratilipiDoc) ArrayList(java.util.ArrayList) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData) PratilipiReviewsDoc(com.pratilipi.data.type.PratilipiReviewsDoc)

Example 5 with UserPratilipiData

use of com.pratilipi.data.client.UserPratilipiData in project pratilipi by Pratilipi.

the class UserPratilipiReviewApi method post.

@Post
public UserPratilipiApi.Response post(PostRequest request) throws InsufficientAccessException, UnexpectedServerException {
    UserPratilipiData userPratilipiData = UserPratilipiDataUtil.saveUserPratilipiReview(AccessTokenFilter.getAccessToken().getUserId(), request.pratilipiId, request.rating, request.review, request.reviewState);
    Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", request.pratilipiId.toString()).addParam("updateReviewsDoc", "true").addParam("updateUserPratilipiStats", "true");
    TaskQueueFactory.getPratilipiTaskQueue().add(task);
    return new UserPratilipiApi.Response(userPratilipiData, UserPratilipiReviewApi.class);
}
Also used : Task(com.pratilipi.taskqueue.Task) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData) Post(com.pratilipi.api.annotation.Post)

Aggregations

UserPratilipiData (com.pratilipi.data.client.UserPratilipiData)8 DataAccessor (com.pratilipi.data.DataAccessor)6 PratilipiData (com.pratilipi.data.client.PratilipiData)4 UserData (com.pratilipi.data.client.UserData)4 HashMap (java.util.HashMap)4 DocAccessor (com.pratilipi.data.DocAccessor)2 CommentData (com.pratilipi.data.client.CommentData)2 PratilipiReviewsDoc (com.pratilipi.data.type.PratilipiReviewsDoc)2 User (com.pratilipi.data.type.User)2 UserPratilipiDoc (com.pratilipi.data.type.UserPratilipiDoc)2 Post (com.pratilipi.api.annotation.Post)1 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)1 VoteData (com.pratilipi.data.client.VoteData)1 Vote (com.pratilipi.data.type.Vote)1 Task (com.pratilipi.taskqueue.Task)1 ArrayList (java.util.ArrayList)1