use of com.pratilipi.data.type.UserAuthor 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);
}
use of com.pratilipi.data.type.UserAuthor 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());
}
Aggregations