use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class PratilipiDocUtil method getContent_v3.
public static Object getContent_v3(Long pratilipiId, Integer chapterNo, Integer pageNo) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (!PratilipiDataUtil.hasAccessToReadPratilipiContent(pratilipi))
throw new InsufficientAccessException();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
if (pcDoc == null)
return null;
else if (chapterNo == null)
return _processContent_v3(pratilipi, pcDoc);
Chapter chapter = pcDoc.getChapter(chapterNo);
if (chapter == null)
return null;
else if (pageNo == null)
return _processContent_v3(pratilipi, chapter);
PratilipiContentDoc.Page page = chapter.getPage(pageNo);
if (page == null)
return null;
else
return _processContent_v3(pratilipi, chapter.getPage(pageNo));
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class PratilipiDocUtil method updatePratilipiContent.
public static void updatePratilipiContent(Long pratilipiId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
BlobAccessor blobAccessor = DataAccessorFactory.getBlobAccessor();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
PratilipiContentDoc pcDoc = DataAccessorFactory.getDocAccessor().newPratilipiContentDoc();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (!pratilipi.isOldContent()) {
return;
} else if (pratilipi.getContentType() == PratilipiContentType.PRATILIPI) {
BlobEntry blobEntry = blobAccessor.getBlob("pratilipi-content/pratilipi/" + pratilipiId);
if (blobEntry == null)
return;
String contentHtml = new String(blobEntry.getData(), Charset.forName("UTF-8"));
List<Object[]> pageletList = _createPageletList(pratilipi, Jsoup.parse(contentHtml).body());
if (pageletList.size() > 0) {
PratilipiContentDoc.Chapter chapter = null;
if (pageletList.get(0)[0] != PratilipiContentDoc.PageletType.HEAD)
chapter = pcDoc.addChapter(pratilipi.getTitle() == null ? pratilipi.getTitleEn() : pratilipi.getTitle());
for (Object[] pagelet : pageletList) {
if (pagelet[0] == PratilipiContentDoc.PageletType.HEAD) {
chapter = pcDoc.addChapter((String) pagelet[1]);
} else {
PratilipiContentDoc.Page page = chapter.getPage(1);
if (page == null)
page = chapter.addPage();
page.addPagelet((PratilipiContentDoc.PageletType) pagelet[0], pagelet[1], (PratilipiContentDoc.AlignmentType) pagelet[2]);
}
}
}
} else if (pratilipi.getContentType() == PratilipiContentType.IMAGE) {
for (int i = 1; i <= pratilipi.getPageCount(); i++) {
BlobEntry blobEntry = blobAccessor.getBlob("pratilipi/" + pratilipiId + "/images/" + i);
if (pratilipi.getId() == 5639838220943360L && i <= 5)
// Skipping first 5 pages as per Shally's request
continue;
else if (pratilipi.getId() == 5749258686824448L && i <= 4)
// Skipping first 4 pages as per Shally's request
continue;
else if (pratilipi.getId() == 5486454792781824L && i <= 1)
// Skipping first page as per Shally's request
continue;
else if (blobEntry == null && pratilipi.getId() == 5768181499035648L)
// Skipping missing pages as per Dileepan's request
continue;
JsonObject imgData = new JsonObject();
imgData.addProperty("name", i + "");
imgData.addProperty("height", ImageUtil.getHeight(blobEntry));
imgData.addProperty("width", ImageUtil.getWidth(blobEntry));
pcDoc.addChapter(null).addPage().addPagelet(PratilipiContentDoc.PageletType.IMAGE, imgData);
}
} else {
throw new UnexpectedServerException("ContentType " + pratilipi.getContentType() + " is not supported !");
}
docAccessor.save(pratilipiId, pcDoc);
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class PratilipiDocUtil method updatePratilipiReviews.
public static void updatePratilipiReviews(Long pratilipiId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
List<Comment> commentList = dataAccessor.getCommentListByReference(ReferenceType.PRATILIPI, pratilipiId);
Map<String, List<Comment>> reviewIdCommentListMap = new HashMap<>();
for (Comment comment : commentList) {
if (comment.getParentType() != CommentParentType.REVIEW)
continue;
List<Comment> reviewCommentList = reviewIdCommentListMap.get(comment.getParentId());
if (reviewCommentList == null) {
reviewCommentList = new LinkedList<>();
reviewIdCommentListMap.put(comment.getParentId(), reviewCommentList);
}
reviewCommentList.add(comment);
}
List<Vote> voteList = dataAccessor.getVoteListByReference(ReferenceType.PRATILIPI, pratilipiId);
Map<String, List<Vote>> reviewIdLikeVotesMap = new HashMap<>();
Map<String, List<Long>> commentIdLikedByUserIdsMap = new HashMap<>();
for (Vote vote : voteList) {
if (vote.getType() == VoteType.NONE) {
continue;
} else if (vote.getParentType() == VoteParentType.REVIEW) {
List<Vote> reviewLikeVoteList = reviewIdLikeVotesMap.get(vote.getParentId());
if (reviewLikeVoteList == null) {
reviewLikeVoteList = new LinkedList<>();
reviewIdLikeVotesMap.put(vote.getParentId(), reviewLikeVoteList);
}
reviewLikeVoteList.add(vote);
} else if (vote.getParentType() == VoteParentType.COMMENT) {
List<Long> userIdList = commentIdLikedByUserIdsMap.get(vote.getParentId());
if (userIdList == null) {
userIdList = new LinkedList<>();
commentIdLikedByUserIdsMap.put(vote.getParentId(), userIdList);
}
userIdList.add(vote.getUserId());
}
}
List<UserPratilipi> userPratilipiList = dataAccessor.getUserPratilipiList(null, pratilipiId, null, null, true).getDataList();
long ratingCount = 0;
long totalRating = 0;
List<UserPratilipiDoc> reviewDocList = new ArrayList<>();
for (UserPratilipi userPratilipi : userPratilipiList) {
if (userPratilipi.getRating() != null && userPratilipi.getRating() > 0) {
ratingCount++;
totalRating += userPratilipi.getRating();
}
if (userPratilipi.getReviewState() != UserReviewState.PUBLISHED)
continue;
if ((userPratilipi.getReviewTitle() == null || userPratilipi.getReviewTitle().trim().isEmpty()) && (userPratilipi.getReview() == null || userPratilipi.getReview().trim().isEmpty()))
continue;
UserPratilipiDoc reviewDoc = docAccessor.newUserPratilipiDoc();
reviewDoc.setId(userPratilipi.getId());
reviewDoc.setUserId(userPratilipi.getUserId());
reviewDoc.setRating(userPratilipi.getRating());
reviewDoc.setReviewTitle(userPratilipi.getReviewTitle() == null || userPratilipi.getReviewTitle().trim().isEmpty() ? null : userPratilipi.getReviewTitle().trim());
reviewDoc.setReview(userPratilipi.getReview() == null || userPratilipi.getReview().trim().isEmpty() ? null : userPratilipi.getReview().trim());
reviewDoc.setReviewDate(userPratilipi.getReviewDate());
reviewDocList.add(reviewDoc);
List<Vote> reviewLikeVoteList = reviewIdLikeVotesMap.get(userPratilipi.getId());
if (reviewLikeVoteList != null) {
List<Long> userIdList = new ArrayList<>(reviewLikeVoteList.size());
for (Vote vote : reviewLikeVoteList) {
if (vote.getLastUpdated().before(userPratilipi.getReviewDate()))
continue;
userIdList.add(vote.getUserId());
}
reviewDoc.setLikedByUserIds(userIdList);
}
List<Comment> reviewCommentList = reviewIdCommentListMap.get(userPratilipi.getId());
if (reviewCommentList != null) {
List<CommentDoc> commentDocList = new ArrayList<>(reviewCommentList.size());
for (Comment comment : reviewCommentList) {
if (comment.getState() == CommentState.DELETED)
continue;
if (comment.getCreationDate().before(userPratilipi.getReviewDate()))
continue;
CommentDoc commentDoc = docAccessor.newCommentDoc();
commentDoc.setId(comment.getId());
commentDoc.setUserId(comment.getUserId());
commentDoc.setContent(comment.getContent());
commentDoc.setCreationDate(comment.getCreationDate());
commentDoc.setLastUpdated(comment.getLastUpdated());
commentDoc.setLikedByUserIds(commentIdLikedByUserIdsMap.get(comment.getId().toString()));
commentDocList.add(commentDoc);
}
reviewDoc.setComments(commentDocList);
}
}
PratilipiReviewsDoc reviewsDoc = docAccessor.newPratilipiReviewsDoc();
reviewsDoc.setRatingCount(ratingCount);
reviewsDoc.setTotalRating(totalRating);
reviewsDoc.setReviews(reviewDocList);
docAccessor.save(pratilipiId, reviewsDoc);
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class PratilipiDataUtil method updatePratilipiStats.
public static void updatePratilipiStats(Long pratilipiId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
PratilipiGoogleAnalyticsDoc gaDoc = docAccessor.getPratilipiGoogleAnalyticsDoc(pratilipiId);
Page pratilipiPage = dataAccessor.getPage(PageType.PRATILIPI, pratilipiId);
long readCountOffset = 0L;
for (int month = 1; month <= 12; month++) for (int day = 1; day <= 31; day++) readCountOffset += gaDoc.getPageViews(2015, month, day);
for (int month = 1; month <= 4; month++) for (int day = 1; day <= 31; day++) readCountOffset += gaDoc.getPageViews(2016, month, day);
long readCount = gaDoc.getTotalReadPageViews();
long fbLikeShareCount = FacebookApi.getUrlShareCount("http://" + Website.ALL_LANGUAGE.getHostName() + pratilipiPage.getUri());
if (pratilipi.getReadCountOffset() == readCountOffset && pratilipi.getReadCount() == readCount && pratilipi.getFbLikeShareCount() == fbLikeShareCount)
return;
updatePratilipiStats(pratilipiId, readCountOffset, readCount, null, fbLikeShareCount);
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class PratilipiDocUtil method getContent.
@Deprecated
public static Object getContent(Long pratilipiId, Integer chapterNo, Integer pageNo) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (!PratilipiDataUtil.hasAccessToReadPratilipiContent(pratilipi))
throw new InsufficientAccessException();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
if (pcDoc == null)
return null;
else if (chapterNo == null)
return _processContent(pratilipi, pcDoc);
Chapter chapter = pcDoc.getChapter(chapterNo);
if (chapter == null)
return null;
else if (pageNo == null)
return _processContent(pratilipi, chapter);
PratilipiContentDoc.Page page = chapter.getPage(pageNo);
if (page == null)
return null;
else
return _processContent(pratilipi, chapter.getPage(pageNo));
}
Aggregations