Search in sources :

Example 1 with CommentData

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

the class CommentDataUtil method createCommentData.

public static CommentData createCommentData(Comment comment) {
    CommentData commentData = new CommentData(comment.getId());
    commentData.setUserId(comment.getUserId());
    commentData.setParentType(comment.getParentType());
    commentData.setParentId(comment.getParentId());
    commentData.setReferenceType(comment.getReferenceType());
    commentData.setReferenceId(comment.getReferenceId());
    commentData.setContent(comment.getContent());
    commentData.setState(comment.getState());
    commentData.setCreationDate(comment.getCreationDate());
    commentData.setLastUpdated(comment.getLastUpdated());
    commentData.setAccessToUpdate(hasAccessToUpdateCommentData(comment));
    return commentData;
}
Also used : CommentData(com.pratilipi.data.client.CommentData)

Example 2 with CommentData

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

the class CommentDataUtil method getCommentList.

public static DataListCursorTuple<CommentData> getCommentList(CommentParentType parentType, String parentId, String cursor, Integer offset, Integer resultCount) throws UnexpectedServerException {
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    if (parentType == CommentParentType.REVIEW) {
        Long userId = Long.parseLong(parentId.substring(0, parentId.indexOf('-')));
        Long pratilipiId = Long.parseLong(parentId.substring(parentId.indexOf('-') + 1));
        PratilipiReviewsDoc reviewsDoc = docAccessor.getPratilipiReviewsDoc(pratilipiId);
        List<CommentDoc> commentDocList = null;
        for (UserPratilipiDoc reviewDoc : reviewsDoc.getReviews()) {
            if (reviewDoc.getUserId().equals(userId)) {
                commentDocList = reviewDoc.getComments();
                break;
            }
        }
        int fromIndex = (cursor == null ? 0 : Integer.parseInt(cursor)) + (offset == null ? 0 : offset);
        int toIndex = resultCount == null ? commentDocList.size() : fromIndex + resultCount;
        commentDocList = commentDocList.subList(Math.min(fromIndex, commentDocList.size()), Math.min(toIndex, commentDocList.size()));
        List<CommentData> commentDataList = createCommentDataList(commentDocList);
        return new DataListCursorTuple<CommentData>(commentDataList, toIndex + "", (long) (int) reviewsDoc.getReviews().size());
    }
    return null;
}
Also used : CommentDoc(com.pratilipi.data.type.CommentDoc) DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) DocAccessor(com.pratilipi.data.DocAccessor) UserPratilipiDoc(com.pratilipi.data.type.UserPratilipiDoc) CommentData(com.pratilipi.data.client.CommentData) PratilipiReviewsDoc(com.pratilipi.data.type.PratilipiReviewsDoc)

Example 3 with CommentData

use of com.pratilipi.data.client.CommentData 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 4 with CommentData

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

the class CommentDataUtil method createCommentDataList.

public static List<CommentData> createCommentDataList(List<CommentDoc> commentDocList) {
    List<Long> userIdList = new ArrayList<>(commentDocList.size());
    for (CommentDoc commentDoc : commentDocList) if (!userIdList.contains(commentDoc.getUserId()))
        userIdList.add(commentDoc.getUserId());
    Map<Long, UserData> userDataMap = UserDataUtil.createUserDataList(userIdList, true);
    List<CommentData> commentDataList = new ArrayList<>(commentDocList.size());
    for (CommentDoc commentDoc : commentDocList) {
        CommentData commentData = createCommentData(commentDoc);
        commentData.setUser(userDataMap.get(commentDoc.getUserId()));
        commentDataList.add(commentData);
    }
    return commentDataList;
}
Also used : CommentDoc(com.pratilipi.data.type.CommentDoc) UserData(com.pratilipi.data.client.UserData) ArrayList(java.util.ArrayList) CommentData(com.pratilipi.data.client.CommentData)

Example 5 with CommentData

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

the class EmailDataUtil method _createDataModelForVoteCommentEmail.

private static Object[] _createDataModelForVoteCommentEmail(String voteId) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    VoteData vote = VoteDataUtil.createVoteData(dataAccessor.getVote(voteId));
    vote.setUser(UserDataUtil.createUserData(dataAccessor.getUser(vote.getUserId())));
    CommentData comment = CommentDataUtil.createCommentData(dataAccessor.getComment(vote.getParentIdLong()));
    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("voter_name", vote.getUser().getAuthor().getName() != null ? vote.getUser().getAuthor().getName() : vote.getUser().getAuthor().getNameEn());
    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) VoteData(com.pratilipi.data.client.VoteData)

Aggregations

CommentData (com.pratilipi.data.client.CommentData)7 DataAccessor (com.pratilipi.data.DataAccessor)2 PratilipiData (com.pratilipi.data.client.PratilipiData)2 UserPratilipiData (com.pratilipi.data.client.UserPratilipiData)2 CommentDoc (com.pratilipi.data.type.CommentDoc)2 HashMap (java.util.HashMap)2 Post (com.pratilipi.api.annotation.Post)1 GenericResponse (com.pratilipi.api.shared.GenericResponse)1 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)1 DocAccessor (com.pratilipi.data.DocAccessor)1 UserData (com.pratilipi.data.client.UserData)1 VoteData (com.pratilipi.data.client.VoteData)1 PratilipiReviewsDoc (com.pratilipi.data.type.PratilipiReviewsDoc)1 UserPratilipiDoc (com.pratilipi.data.type.UserPratilipiDoc)1 Task (com.pratilipi.taskqueue.Task)1 ArrayList (java.util.ArrayList)1