Search in sources :

Example 36 with DataAccessor

use of com.pratilipi.data.DataAccessor 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 37 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class UserPratilipiDataUtil method getContentsReadList.

/**
	 * @param userId
	 * @return List of pratilipi Ids read (completed) by the user
	 */
public static List<Long> getContentsReadList(Long userId) {
    Logger logger = Logger.getLogger(UserPratilipiDataUtil.class.getSimpleName());
    List<Long> contentsReadList = new ArrayList<>();
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    List<UserPratilipi> userPratilipiList = dataAccessor.getUserPratilipiList(userId, null, null, null).getDataList();
    if (userPratilipiList == null || userPratilipiList.size() == 0)
        return null;
    logger.log(Level.INFO, "LIST OF READ CONTENTS");
    for (UserPratilipi userPratilipi : userPratilipiList) {
        if (userPratilipi.getLastOpenedDate() != null) {
            contentsReadList.add(userPratilipi.getPratilipiId());
            logger.log(Level.INFO, "PRATILIPI ID : " + userPratilipi.getPratilipiId());
        }
    }
    return contentsReadList;
}
Also used : UserPratilipi(com.pratilipi.data.type.UserPratilipi) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) Logger(java.util.logging.Logger)

Example 38 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class LogAndSecurityFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    String uri = ((HttpServletRequest) request).getRequestURI().toString();
    if (!uri.equals("/poc1")) {
        DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
        Page page = dataAccessor.getPage(uri);
        if (page != null) {
            if (page.getType() == PageType.BLOG_POST) {
                JsonObject jsonObject = new JsonObject();
                jsonObject.addProperty("pageId", page.getId());
                jsonObject.addProperty("accessToken", AccessTokenFilter.getAccessToken().getId());
                logger.log(Level.INFO, "DataFlow#PAGE_HIT::" + jsonObject.toString());
            }
        }
    }
    chain.doFilter(request, response);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) JsonObject(com.google.gson.JsonObject) Page(com.pratilipi.data.type.Page)

Example 39 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class NotificationFilter method doFilter.

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
    String notificationIdStr = ((HttpServletRequest) req).getParameter(RequestParameter.NOTIFICATION_ID.getName());
    if (notificationIdStr != null && !notificationIdStr.trim().isEmpty()) {
        DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
        Notification notification = dataAccessor.getNotification(Long.parseLong(notificationIdStr.trim()));
        if (notification != null && notification.getState() == NotificationState.UNREAD && AccessTokenFilter.getAccessToken().getUserId().equals(notification.getUserId())) {
            notification.setState(NotificationState.READ);
            notification = dataAccessor.createOrUpdateNotification(notification);
        }
    }
    chain.doFilter(req, resp);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DataAccessor(com.pratilipi.data.DataAccessor) Notification(com.pratilipi.data.type.Notification)

Example 40 with DataAccessor

use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.

the class VoteDataUtil method saveVoteData.

public static VoteData saveVoteData(Long userId, VoteParentType parentType, String parentId, VoteType type) throws InsufficientAccessException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Vote vote = dataAccessor.getVote(userId, parentType, parentId);
    boolean isNew = vote == null;
    if (isNew)
        vote = dataAccessor.newVote();
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.VOTE, vote);
    if (isNew) {
        vote.setUserId(userId);
        vote.setParentType(parentType);
        vote.setParentId(parentId);
        if (parentType == VoteParentType.REVIEW) {
            UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(parentId);
            vote.setReferenceType(ReferenceType.PRATILIPI);
            vote.setReferenceId(userPratilipi.getPratilipiId());
        } else if (parentType == VoteParentType.COMMENT) {
            Comment comment = dataAccessor.getComment(Long.parseLong(parentId));
            UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(comment.getParentId());
            vote.setReferenceType(ReferenceType.PRATILIPI);
            vote.setReferenceId(userPratilipi.getPratilipiId());
        }
        vote.setCreationDate(new Date());
    } else {
        vote.setLastUpdated(new Date());
    }
    vote.setType(type);
    if (!hasAccessToAddOrUpdateData(vote))
        throw new InsufficientAccessException();
    vote = dataAccessor.createOrUpdateVote(vote, auditLog);
    return createVoteData(vote);
}
Also used : UserPratilipi(com.pratilipi.data.type.UserPratilipi) Comment(com.pratilipi.data.type.Comment) Vote(com.pratilipi.data.type.Vote) DataAccessor(com.pratilipi.data.DataAccessor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Aggregations

DataAccessor (com.pratilipi.data.DataAccessor)162 Date (java.util.Date)53 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)37 Pratilipi (com.pratilipi.data.type.Pratilipi)34 Author (com.pratilipi.data.type.Author)33 AuditLog (com.pratilipi.data.type.AuditLog)32 UserPratilipi (com.pratilipi.data.type.UserPratilipi)32 ArrayList (java.util.ArrayList)30 Page (com.pratilipi.data.type.Page)28 HashMap (java.util.HashMap)25 GenericResponse (com.pratilipi.api.shared.GenericResponse)24 DocAccessor (com.pratilipi.data.DocAccessor)22 User (com.pratilipi.data.type.User)22 Get (com.pratilipi.api.annotation.Get)20 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)19 PratilipiData (com.pratilipi.data.client.PratilipiData)15 UserData (com.pratilipi.data.client.UserData)14 BlobAccessor (com.pratilipi.data.BlobAccessor)13 Email (com.pratilipi.data.type.Email)13 JsonObject (com.google.gson.JsonObject)12