Search in sources :

Example 1 with PageEntity

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

the class DataStoreCleanupUtil method delete.

public static void delete(Pratilipi pratilipi, boolean preview) {
    System.out.println();
    System.out.println("Pratilipi id: " + pratilipi.getId() + ", state: " + pratilipi.getState());
    if (!preview && pratilipi.getState() != PratilipiState.DELETED && pratilipi.getState() != PratilipiState.BLOCKED) {
        pratilipi.setState(PratilipiState.DELETED);
        // Save
        ObjectifyService.ofy().save().entity(pratilipi).now();
        // Delete search index
        DataAccessorFactory.getSearchAccessor().deletePratilipiDataIndex(pratilipi.getId());
    }
    // USER_PRATILIPI table
    List<UserPratilipi> userPratilipiList = DataAccessorFactory.getDataAccessor().getUserPratilipiList(null, pratilipi.getId(), null, null).getDataList();
    System.out.println();
    System.out.println("UserPratilipiEntity # " + userPratilipiList.size());
    if (!preview) {
        boolean save = false;
        for (UserPratilipi userPratilipi : userPratilipiList) {
            if (userPratilipi.isAddedToLib()) {
                userPratilipi.setAddedToLib(null);
                save = true;
            }
        }
        if (save) {
            ObjectifyService.ofy().save().entities(userPratilipiList).now();
        }
    }
    // PAGE Table
    List<PageEntity> pageList = ObjectifyService.ofy().load().type(PageEntity.class).filter("PAGE_TYPE", "PRATILIPI").filter("PRIMARY_CONTENT_ID", pratilipi.getId()).list();
    System.out.println("PageEntity # " + pageList.size());
    if (!preview)
        for (Page page : pageList) // Delete
        ObjectifyService.ofy().delete().entity(page).now();
}
Also used : PageEntity(com.pratilipi.data.type.gae.PageEntity) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Page(com.pratilipi.data.type.Page)

Example 2 with PageEntity

use of com.pratilipi.data.type.gae.PageEntity 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)

Aggregations

Page (com.pratilipi.data.type.Page)2 UserPratilipi (com.pratilipi.data.type.UserPratilipi)2 PageEntity (com.pratilipi.data.type.gae.PageEntity)2 Pratilipi (com.pratilipi.data.type.Pratilipi)1 UserAuthor (com.pratilipi.data.type.UserAuthor)1 PratilipiEntity (com.pratilipi.data.type.gae.PratilipiEntity)1 UserAuthorEntity (com.pratilipi.data.type.gae.UserAuthorEntity)1 UserPratilipiEntity (com.pratilipi.data.type.gae.UserPratilipiEntity)1