use of com.pratilipi.data.type.gae.UserAuthorEntity in project pratilipi by Pratilipi.
the class DataAccessorGaeImpl method getUserAuthorFollowList.
@Override
public DataListCursorTuple<Long> getUserAuthorFollowList(Long userId, Long authorId, String cursorStr, Integer offset, Integer resultCount) {
Query<UserAuthorEntity> query = ObjectifyService.ofy().load().type(UserAuthorEntity.class);
if (userId != null)
query = query.filter("USER_ID", userId);
if (authorId != null)
query = query.filter("AUTHOR_ID", authorId);
query = query.filter("FOLLOW_STATE", UserFollowState.FOLLOWING);
query = query.order("-FOLLOW_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<UserAuthorEntity> iterator = query.iterator();
// UserAuthor List
ArrayList<Long> idList = resultCount == null ? new ArrayList<Long>() : new ArrayList<Long>(resultCount);
while (iterator.hasNext()) {
if (userId != null)
idList.add(iterator.next().getAuthorId());
else if (authorId != null)
idList.add(iterator.next().getUserId());
}
// Cursor
Cursor cursor = iterator.getCursor();
return new DataListCursorTuple<Long>(idList, cursor == null ? null : cursor.toWebSafeString());
}
use of com.pratilipi.data.type.gae.UserAuthorEntity 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);
}
use of com.pratilipi.data.type.gae.UserAuthorEntity in project pratilipi by Pratilipi.
the class DataAccessorGaeImpl method createOrUpdateUserAuthor.
@Override
public UserAuthor createOrUpdateUserAuthor(UserAuthor userAuthor, AuditLog auditLog) {
((UserAuthorEntity) userAuthor).setId(userAuthor.getUserId() + "-" + userAuthor.getAuthorId());
userAuthor.setTimestamp(new Date());
return createOrUpdateEntity(userAuthor, auditLog);
}
use of com.pratilipi.data.type.gae.UserAuthorEntity in project pratilipi by Pratilipi.
the class DataAccessorGaeImpl method getUserAuthorList.
@Override
public DataListCursorTuple<UserAuthor> getUserAuthorList(Long userId, Long authorId, String cursorStr, Integer offset, Integer resultCount) {
Query<UserAuthorEntity> query = ObjectifyService.ofy().load().type(UserAuthorEntity.class);
if (userId != null)
query = query.filter("USER_ID", userId);
if (authorId != null)
query = query.filter("AUTHOR_ID", authorId);
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<UserAuthorEntity> iterator = query.iterator();
// UserAuthor List
ArrayList<UserAuthor> userAuthorList = resultCount == null ? new ArrayList<UserAuthor>() : new ArrayList<UserAuthor>(resultCount);
while (iterator.hasNext()) userAuthorList.add(iterator.next());
// Cursor
Cursor cursor = iterator.getCursor();
return new DataListCursorTuple<UserAuthor>(userAuthorList, cursor == null ? null : cursor.toWebSafeString());
}
use of com.pratilipi.data.type.gae.UserAuthorEntity in project pratilipi by Pratilipi.
the class DataStoreCleanupUtil method delete.
public static void delete(Author author, boolean preview) {
System.out.println();
System.out.println("Author id: " + author.getId() + ", state: " + author.getState());
if (!preview && author.getState() != AuthorState.DELETED && author.getState() != AuthorState.BLOCKED) {
author.setState(AuthorState.DELETED);
// Save
ObjectifyService.ofy().save().entity(author).now();
// Delete search index
DataAccessorFactory.getSearchAccessor().deleteAuthorDataIndex(author.getId());
}
// USER_AUTHOR Table
List<UserAuthorEntity> userAuthorList = ObjectifyService.ofy().load().type(UserAuthorEntity.class).filter("AUTHOR_ID", author.getId()).list();
System.out.println("UserAuthorEntity # " + userAuthorList.size());
int followerCount = 0;
for (UserAuthor userAuthor : userAuthorList) if (userAuthor.getFollowState() == UserFollowState.FOLLOWING)
followerCount++;
System.out.println("Follower ## " + followerCount);
if (!preview) {
for (UserAuthor userAuthor : userAuthorList) {
if (userAuthor.getFollowState() != null) {
userAuthor.setFollowState(null);
// Save
ObjectifyService.ofy().save().entity(userAuthor).now();
}
}
}
// PAGE Table
List<PageEntity> pageList = ObjectifyService.ofy().load().type(PageEntity.class).filter("PAGE_TYPE", "AUTHOR").filter("PRIMARY_CONTENT_ID", author.getId()).list();
System.out.println("PageEntity # " + pageList.size());
if (!preview)
for (Page page : pageList) // Delete
ObjectifyService.ofy().delete().entity(page).now();
// PRATILIPI Table
List<PratilipiEntity> pratilipiList = ObjectifyService.ofy().load().type(PratilipiEntity.class).filter("AUTHOR_ID", author.getId()).list();
System.out.println();
System.out.println("PratilipiEntity # " + pratilipiList.size());
if (pratilipiList.size() == 0)
return;
for (Pratilipi pratilipi : pratilipiList) delete(pratilipi, preview);
}
Aggregations