Search in sources :

Example 1 with PratilipiData

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() };
}
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 PratilipiData

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() };
}
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 PratilipiData

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;
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) PratilipiData(com.pratilipi.data.client.PratilipiData) Page(com.pratilipi.data.type.Page)

Example 4 with 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());
}
Also used : DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) DataAccessor(com.pratilipi.data.DataAccessor) PratilipiData(com.pratilipi.data.client.PratilipiData) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException)

Example 5 with PratilipiData

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);
    }
}
Also used : SearchAccessor(com.pratilipi.data.SearchAccessor) HashMap(java.util.HashMap) DataAccessor(com.pratilipi.data.DataAccessor) PratilipiData(com.pratilipi.data.client.PratilipiData) ArrayList(java.util.ArrayList) Author(com.pratilipi.data.type.Author) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi)

Aggregations

PratilipiData (com.pratilipi.data.client.PratilipiData)20 DataAccessor (com.pratilipi.data.DataAccessor)15 HashMap (java.util.HashMap)9 Get (com.pratilipi.api.annotation.Get)5 UserPratilipiData (com.pratilipi.data.client.UserPratilipiData)5 Pratilipi (com.pratilipi.data.type.Pratilipi)5 LinkedList (java.util.LinkedList)5 Gson (com.google.gson.Gson)4 GenericResponse (com.pratilipi.api.shared.GenericResponse)4 PratilipiFilter (com.pratilipi.common.util.PratilipiFilter)4 PratilipiContentDoc (com.pratilipi.data.type.PratilipiContentDoc)4 JsonObject (com.google.gson.JsonObject)3 DocAccessor (com.pratilipi.data.DocAccessor)3 UserData (com.pratilipi.data.client.UserData)3 Author (com.pratilipi.data.type.Author)3 UserPratilipi (com.pratilipi.data.type.UserPratilipi)3 ArrayList (java.util.ArrayList)3 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)2 CommentData (com.pratilipi.data.client.CommentData)2 Event (com.pratilipi.data.type.Event)2