Search in sources :

Example 1 with UserPratilipiEntity

use of com.pratilipi.data.type.gae.UserPratilipiEntity in project pratilipi by Pratilipi.

the class DataAccessorGaeImpl method getUserPratilipiList.

@Override
public DataListCursorTuple<UserPratilipi> getUserPratilipiList(Long userId, Long pratilipiId, String cursorStr, Integer resultCount, boolean sortByReviewDate) {
    Query<UserPratilipiEntity> query = ObjectifyService.ofy().load().type(UserPratilipiEntity.class);
    if (userId != null)
        query = query.filter("USER_ID", userId);
    if (pratilipiId != null)
        query = query.filter("PRATILIPI_ID", pratilipiId);
    if (cursorStr != null)
        query = query.startAt(Cursor.fromWebSafeString(cursorStr));
    if (resultCount != null && resultCount > 0)
        query = query.limit(resultCount);
    if (sortByReviewDate)
        query = query.order("REVIEW_DATE");
    QueryResultIterator<UserPratilipiEntity> iterator = query.iterator();
    // UserPratilipi List
    ArrayList<UserPratilipi> userPratilipiList = resultCount == null ? new ArrayList<UserPratilipi>() : new ArrayList<UserPratilipi>(resultCount);
    while (iterator.hasNext()) userPratilipiList.add(iterator.next());
    // Cursor
    Cursor cursor = iterator.getCursor();
    return new DataListCursorTuple<UserPratilipi>(userPratilipiList, cursor == null ? null : cursor.toWebSafeString());
}
Also used : UserPratilipi(com.pratilipi.data.type.UserPratilipi) Cursor(com.google.appengine.api.datastore.Cursor) UserPratilipiEntity(com.pratilipi.data.type.gae.UserPratilipiEntity)

Example 2 with UserPratilipiEntity

use of com.pratilipi.data.type.gae.UserPratilipiEntity in project pratilipi by Pratilipi.

the class DataAccessorGaeImpl method getUserLibrary.

@Override
public DataListCursorTuple<Long> getUserLibrary(Long userId, String cursorStr, Integer offset, Integer resultCount) {
    Query<UserPratilipiEntity> query = ObjectifyService.ofy().load().type(UserPratilipiEntity.class).filter("USER_ID", userId).filter("ADDED_TO_LIB", true);
    if (UxModeFilter.isAndroidApp())
        query = query.order("ADDED_TO_LIB_DATE");
    else
        query = query.order("-ADDED_TO_LIB_DATE");
    if (cursorStr != null)
        query = query.startAt(Cursor.fromWebSafeString(cursorStr));
    if (offset != null && offset > 0)
        query = query.offset(offset);
    if (resultCount != null && resultCount > 0)
        query = query.limit(resultCount);
    QueryResultIterator<UserPratilipiEntity> iterator = query.iterator();
    // Pratilipi id list
    ArrayList<Long> pratilipiIdList = resultCount == null ? new ArrayList<Long>() : new ArrayList<Long>(resultCount);
    while (iterator.hasNext()) pratilipiIdList.add(iterator.next().getPratilipiId());
    // Cursor
    Cursor cursor = iterator.getCursor();
    return new DataListCursorTuple<Long>(pratilipiIdList, cursor == null ? null : cursor.toWebSafeString());
}
Also used : Cursor(com.google.appengine.api.datastore.Cursor) UserPratilipiEntity(com.pratilipi.data.type.gae.UserPratilipiEntity)

Example 3 with UserPratilipiEntity

use of com.pratilipi.data.type.gae.UserPratilipiEntity in project pratilipi by Pratilipi.

the class DataAccessorGaeImpl method createOrUpdateUserPratilipi.

@Override
public UserPratilipi createOrUpdateUserPratilipi(UserPratilipi userPratilipi, AuditLog auditLog) {
    ((UserPratilipiEntity) userPratilipi).setId(userPratilipi.getUserId() + "-" + userPratilipi.getPratilipiId());
    userPratilipi.setTimestamp(new Date());
    return createOrUpdateEntity(userPratilipi, auditLog);
}
Also used : Date(java.util.Date) UserPratilipiEntity(com.pratilipi.data.type.gae.UserPratilipiEntity)

Example 4 with UserPratilipiEntity

use of com.pratilipi.data.type.gae.UserPratilipiEntity in project pratilipi by Pratilipi.

the class DataStoreCleanupUtil method delete.

public static void delete(User user, boolean preview) {
    System.out.println();
    System.out.println("User id: " + user.getId() + ", state: " + user.getState() + ", signUpDate:" + user.getSignUpDate() + ", signUpSource:" + user.getSignUpSource());
    if (!preview && user.getState() != UserState.DELETED && user.getState() != UserState.BLOCKED) {
        user.setState(UserState.DELETED);
        // Save
        ObjectifyService.ofy().save().entity(user).now();
    }
    // ACCESS_TOKEN Table
    List<AccessTokenEntity> accessTokenList = ObjectifyService.ofy().load().type(AccessTokenEntity.class).filter("USER_ID", user.getId()).filter("EXPIRY >", new Date()).list();
    System.out.println("AccessTokenEntity # " + accessTokenList.size());
    if (!preview) {
        for (AccessToken accessToken : accessTokenList) {
            accessToken.setExpiry(new Date());
            // Save
            ObjectifyService.ofy().save().entity(accessToken).now();
        }
    }
    // USER_PRATILIPI Table
    List<UserPratilipiEntity> userPratilipiList = ObjectifyService.ofy().load().type(UserPratilipiEntity.class).filter("USER_ID", user.getId()).list();
    System.out.println("UserPratilipiEntity # " + userPratilipiList.size());
    int reviewCount = 0;
    int ratingCount = 0;
    for (UserPratilipi userPratilipi : userPratilipiList) {
        if (userPratilipi.getReviewState() != UserReviewState.DELETED && userPratilipi.getReviewState() != UserReviewState.BLOCKED)
            reviewCount++;
        if (userPratilipi.getRating() != null && userPratilipi.getRating() != 0)
            ratingCount++;
    }
    System.out.println("Review ## " + reviewCount);
    System.out.println("Rating ## " + ratingCount);
    if (!preview) {
        for (UserPratilipi userPratilipi : userPratilipiList) {
            boolean save = false;
            if (userPratilipi.getReviewState() != UserReviewState.DELETED && userPratilipi.getReviewState() != UserReviewState.BLOCKED) {
                userPratilipi.setReviewState(UserReviewState.DELETED);
                save = true;
            }
            if (userPratilipi.getRating() != null && userPratilipi.getRating() != 0) {
                userPratilipi.setRating(null);
                save = true;
            }
            if (save) {
                // Save
                ObjectifyService.ofy().save().entity(userPratilipi).now();
                Task task = TaskQueueFactory.newTask().setUrl("/pratilipi/process").addParam("pratilipiId", userPratilipi.getPratilipiId().toString()).addParam("updateReviewsDoc", "true").addParam("updateUserPratilipiStats", "true");
                TaskQueueFactory.getPratilipiTaskQueue().add(task);
            }
        }
    }
    // USER_AUTHOR Table
    List<UserAuthorEntity> userAuthorList = ObjectifyService.ofy().load().type(UserAuthorEntity.class).filter("USER_ID", user.getId()).list();
    System.out.println("UserAuthorEntity # " + userAuthorList.size());
    int followCount = 0;
    for (UserAuthor userAuthor : userAuthorList) if (userAuthor.getFollowState() == UserFollowState.FOLLOWING)
        followCount++;
    System.out.println("Follow ## " + followCount);
    if (!preview) {
        for (UserAuthor userAuthor : userAuthorList) {
            if (userAuthor.getFollowState() != null) {
                userAuthor.setFollowState(null);
                // Save
                ObjectifyService.ofy().save().entity(userAuthor).now();
            }
        }
    }
    // COMMENT Table
    List<CommentEntity> commentList = ObjectifyService.ofy().load().type(CommentEntity.class).filter("USER_ID", user.getId()).list();
    System.out.println("CommentEntity # " + commentList.size());
    int commentCount = 0;
    for (Comment comment : commentList) if (comment.getState() == CommentState.ACTIVE)
        commentCount++;
    System.out.println("Comment ## " + commentCount);
    if (!preview) {
        for (Comment comment : commentList) {
            if (comment.getState() == CommentState.ACTIVE) {
                comment.setState(CommentState.DELETED);
                // Save
                ObjectifyService.ofy().save().entity(comment).now();
            }
        }
    }
    // VOTE Table
    List<VoteEntity> voteList = ObjectifyService.ofy().load().type(VoteEntity.class).filter("USER_ID", user.getId()).list();
    System.out.println("VoteEntity # " + voteList.size());
    int voteCount = 0;
    for (Vote vote : voteList) if (vote.getType() != VoteType.NONE)
        voteCount++;
    System.out.println("Vote ## " + voteCount);
    if (!preview)
        for (Vote vote : voteList) // Delete
        ObjectifyService.ofy().delete().entity(vote).now();
    // AUTHOR Table
    List<AuthorEntity> authorList = ObjectifyService.ofy().load().type(AuthorEntity.class).filter("USER_ID", user.getId()).list();
    System.out.println();
    System.out.println("AuthorEntity # " + authorList.size());
    if (authorList.size() == 0)
        return;
    for (Author author : authorList) delete(author, preview);
}
Also used : UserAuthorEntity(com.pratilipi.data.type.gae.UserAuthorEntity) Comment(com.pratilipi.data.type.Comment) Task(com.pratilipi.taskqueue.Task) Vote(com.pratilipi.data.type.Vote) AccessTokenEntity(com.pratilipi.data.type.gae.AccessTokenEntity) Date(java.util.Date) UserAuthorEntity(com.pratilipi.data.type.gae.UserAuthorEntity) AuthorEntity(com.pratilipi.data.type.gae.AuthorEntity) CommentEntity(com.pratilipi.data.type.gae.CommentEntity) UserPratilipi(com.pratilipi.data.type.UserPratilipi) VoteEntity(com.pratilipi.data.type.gae.VoteEntity) AccessToken(com.pratilipi.data.type.AccessToken) UserAuthor(com.pratilipi.data.type.UserAuthor) UserAuthor(com.pratilipi.data.type.UserAuthor) Author(com.pratilipi.data.type.Author) UserPratilipiEntity(com.pratilipi.data.type.gae.UserPratilipiEntity)

Aggregations

UserPratilipiEntity (com.pratilipi.data.type.gae.UserPratilipiEntity)4 Cursor (com.google.appengine.api.datastore.Cursor)2 UserPratilipi (com.pratilipi.data.type.UserPratilipi)2 Date (java.util.Date)2 AccessToken (com.pratilipi.data.type.AccessToken)1 Author (com.pratilipi.data.type.Author)1 Comment (com.pratilipi.data.type.Comment)1 UserAuthor (com.pratilipi.data.type.UserAuthor)1 Vote (com.pratilipi.data.type.Vote)1 AccessTokenEntity (com.pratilipi.data.type.gae.AccessTokenEntity)1 AuthorEntity (com.pratilipi.data.type.gae.AuthorEntity)1 CommentEntity (com.pratilipi.data.type.gae.CommentEntity)1 UserAuthorEntity (com.pratilipi.data.type.gae.UserAuthorEntity)1 VoteEntity (com.pratilipi.data.type.gae.VoteEntity)1 Task (com.pratilipi.taskqueue.Task)1