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();
}
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);
}
Aggregations