Search in sources :

Example 11 with UserAuthor

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);
}
Also used : UserAuthorEntity(com.pratilipi.data.type.gae.UserAuthorEntity) PageEntity(com.pratilipi.data.type.gae.PageEntity) UserPratilipiEntity(com.pratilipi.data.type.gae.UserPratilipiEntity) PratilipiEntity(com.pratilipi.data.type.gae.PratilipiEntity) UserAuthor(com.pratilipi.data.type.UserAuthor) Page(com.pratilipi.data.type.Page) Pratilipi(com.pratilipi.data.type.Pratilipi) UserPratilipi(com.pratilipi.data.type.UserPratilipi)

Example 12 with UserAuthor

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());
}
Also used : UserAuthorEntity(com.pratilipi.data.type.gae.UserAuthorEntity) UserAuthor(com.pratilipi.data.type.UserAuthor) Cursor(com.google.appengine.api.datastore.Cursor)

Aggregations

UserAuthor (com.pratilipi.data.type.UserAuthor)12 DataAccessor (com.pratilipi.data.DataAccessor)9 Author (com.pratilipi.data.type.Author)6 ArrayList (java.util.ArrayList)4 AuthorData (com.pratilipi.data.client.AuthorData)3 UserData (com.pratilipi.data.client.UserData)3 AccessToken (com.pratilipi.data.type.AccessToken)3 UserPratilipi (com.pratilipi.data.type.UserPratilipi)3 UserAuthorEntity (com.pratilipi.data.type.gae.UserAuthorEntity)3 UserPratilipiEntity (com.pratilipi.data.type.gae.UserPratilipiEntity)3 Date (java.util.Date)3 Get (com.pratilipi.api.annotation.Get)2 GenericResponse (com.pratilipi.api.shared.GenericResponse)2 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)2 AuditLog (com.pratilipi.data.type.AuditLog)2 Comment (com.pratilipi.data.type.Comment)2 Pratilipi (com.pratilipi.data.type.Pratilipi)2 Vote (com.pratilipi.data.type.Vote)2 HashMap (java.util.HashMap)2 Cursor (com.google.appengine.api.datastore.Cursor)1