use of com.pratilipi.data.client.PratilipiData 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() };
}
use of com.pratilipi.data.client.PratilipiData 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() };
}
use of com.pratilipi.data.client.PratilipiData in project pratilipi by Pratilipi.
the class PratilipiDataUtil method createPratilipiData.
@SuppressWarnings("unused")
public static PratilipiData createPratilipiData(Pratilipi pratilipi, Page pratilipiPage, Author author, boolean includeMetaData) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
if (// will still be null for DELETED Pratilipis
pratilipiPage == null)
pratilipiPage = dataAccessor.getPage(PageType.PRATILIPI, pratilipi.getId());
// dataAccessor.getPage( PageType.READ, pratilipi.getId() ); TODO: Uncomment this once data in DataStore is fixed.
Page readPage = null;
// dataAccessor.getPage( PageType.WRITE, pratilipi.getId() ); TODO: Uncomment this once data in DataStore is fixed.
Page writePage = null;
PratilipiData pratilipiData = new PratilipiData();
pratilipiData.setId(pratilipi.getId());
pratilipiData.setTitle(pratilipi.getTitle());
pratilipiData.setTitleEn(pratilipi.getTitleEn());
pratilipiData.setLanguage(pratilipi.getLanguage());
pratilipiData.setAuthorId(pratilipi.getAuthorId());
pratilipiData.setAuthor(AuthorDataUtil.createAuthorData(author));
pratilipiData.setSummary(HtmlUtil.toPlainText(pratilipi.getSummary()));
pratilipiData.setPageUrl(pratilipiPage == null ? null : (pratilipiPage.getUriAlias() == null ? pratilipiPage.getUri() : pratilipiPage.getUriAlias()));
pratilipiData.setCoverImageUrl(createPratilipiCoverUrl(pratilipi));
pratilipiData.setReadPageUrl(readPage == null || readPage.getUriAlias() == null ? PageType.READ.getUrlPrefix() + pratilipi.getId() : readPage.getUriAlias());
if (writePage != null && writePage.getUriAlias() != null) {
pratilipiData.setWritePageUrl(writePage.getUriAlias());
} else {
if (pratilipi.isOldContent())
pratilipiData.setWritePageUrl("/write?id=" + pratilipi.getId());
else
pratilipiData.setWritePageUrl(PageType.WRITE.getUrlPrefix() + pratilipi.getId());
}
pratilipiData.setOldContent(pratilipi.isOldContent());
pratilipiData.setType(pratilipi.getType());
pratilipiData.setContentType(pratilipi.getContentType());
pratilipiData.setState(pratilipi.getState());
pratilipiData.setListingDate(pratilipi.getListingDate());
if (includeMetaData)
pratilipiData.setLastUpdated(pratilipi.getLastUpdated());
pratilipiData.setIndex(pratilipi.getIndex());
pratilipiData.setPageCount(pratilipi.getPageCount());
pratilipiData.setReviewCount(pratilipi.getReviewCount());
pratilipiData.setRatingCount(pratilipi.getRatingCount());
pratilipiData.setAverageRating(pratilipi.getRatingCount() == 0L ? 0F : (float) ((double) pratilipi.getTotalRating() / pratilipi.getRatingCount()));
pratilipiData.setRelevance(calculateRelevance(pratilipi, author));
pratilipiData.setReadCount(pratilipi.getReadCountOffset() + pratilipi.getReadCount());
pratilipiData.setFbLikeShareCount(pratilipi.getFbLikeShareCountOffset() + pratilipi.getFbLikeShareCount());
pratilipiData.setWordCount(pratilipi.getWordCount());
pratilipiData.setTags(TagDataUtil.createTagDataList(pratilipi.getTagIds()));
pratilipiData.setSuggestedTags(pratilipi.getSuggestedTags());
pratilipiData.setAccessToUpdate(hasAccessToUpdatePratilipiData(pratilipi, null));
return pratilipiData;
}
use of com.pratilipi.data.client.PratilipiData in project pratilipi by Pratilipi.
the class PratilipiDataUtil method getPratilipiDataList.
public static DataListCursorTuple<PratilipiData> getPratilipiDataList(String searchQuery, Long eventId, PratilipiFilter pratilipiFilter, String cursor, Integer offset, Integer resultCount) throws InsufficientAccessException, UnexpectedServerException {
if (!hasAccessToListPratilipiData(pratilipiFilter))
throw new InsufficientAccessException();
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
// Processing search query
if (searchQuery != null)
searchQuery = searchQuery.toLowerCase().trim().replaceAll("\"|\\\\|\\(|\\)|:|,|\\sor\\s", " ").trim().replaceAll("[\\s]+", " OR ");
// Fetching Pratilipi id list from DataStore/SearchIndex/Event
DataListCursorTuple<Long> pratilipiIdListCursorTuple = null;
if (eventId != null) {
List<Long> pratilipiIdList = dataAccessor.getEvent(eventId).getPratilipiIdList();
// move read content to end of the list.
List<Long> contentsReadList = UserPratilipiDataUtil.getContentsReadList(AccessTokenFilter.getAccessToken().getUserId());
// move all read contents to bottom of the list.
if (contentsReadList != null) {
// Find all read contents in the list
contentsReadList.retainAll(pratilipiIdList);
// Remove already read content from the list
pratilipiIdList.removeAll(contentsReadList);
// Append read content at end of the list
pratilipiIdList.addAll(contentsReadList);
}
offset = (cursor == null ? 0 : Integer.parseInt(cursor)) + (offset == null || offset < 0 ? 0 : offset);
offset = Math.min(offset, pratilipiIdList.size());
resultCount = resultCount == null || resultCount > pratilipiIdList.size() - offset ? pratilipiIdList.size() - offset : resultCount;
pratilipiIdListCursorTuple = new DataListCursorTuple<Long>(pratilipiIdList.subList(offset, offset + resultCount), offset + resultCount + "", (long) pratilipiIdList.size());
} else if (pratilipiFilter.getListName() == null && pratilipiFilter.getState() == PratilipiState.PUBLISHED) {
pratilipiIdListCursorTuple = DataAccessorFactory.getSearchAccessor().searchPratilipi(searchQuery, pratilipiFilter, cursor, offset, resultCount);
} else {
pratilipiIdListCursorTuple = dataAccessor.getPratilipiIdList(pratilipiFilter, cursor, offset, resultCount);
}
// Creating PratilipiData list from Pratilipi id list
List<PratilipiData> pratilipiDataList = createPratilipiDataList(pratilipiIdListCursorTuple.getDataList(), pratilipiFilter.getAuthorId() == null, false);
// Creating response object
return new DataListCursorTuple<PratilipiData>(pratilipiDataList, pratilipiIdListCursorTuple.getCursor(), pratilipiIdListCursorTuple.getNumberFound());
}
use of com.pratilipi.data.client.PratilipiData in project pratilipi by Pratilipi.
the class PratilipiDataUtil method _updatePratilipiSearchIndex.
private static void _updatePratilipiSearchIndex(List<Pratilipi> pratilipiList) throws InvalidArgumentException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
SearchAccessor searchAccessor = DataAccessorFactory.getSearchAccessor();
List<PratilipiData> pratilipiDataList = new ArrayList<>(pratilipiList.size());
for (Pratilipi pratilipi : pratilipiList) {
if (pratilipi.getState() == PratilipiState.PUBLISHED) {
Author author = dataAccessor.getAuthor(pratilipi.getAuthorId());
pratilipiDataList.add(createPratilipiData(pratilipi, author, true));
} else {
searchAccessor.deletePratilipiDataIndex(pratilipi.getId());
}
}
if (pratilipiDataList.size() > 0) {
Map<PratilipiData, String> pratilipiDataKeywordsMap = new HashMap<>();
for (PratilipiData pratilipiData : pratilipiDataList) pratilipiDataKeywordsMap.put(pratilipiData, getPratilipiKeywords(pratilipiData.getId()));
searchAccessor.indexPratilipiDataList(pratilipiDataKeywordsMap);
}
}
Aggregations