use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.
the class PratilipiDataUtil method updatePratilipiStats.
public static void updatePratilipiStats(Long pratilipiId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
PratilipiGoogleAnalyticsDoc gaDoc = docAccessor.getPratilipiGoogleAnalyticsDoc(pratilipiId);
Page pratilipiPage = dataAccessor.getPage(PageType.PRATILIPI, pratilipiId);
long readCountOffset = 0L;
for (int month = 1; month <= 12; month++) for (int day = 1; day <= 31; day++) readCountOffset += gaDoc.getPageViews(2015, month, day);
for (int month = 1; month <= 4; month++) for (int day = 1; day <= 31; day++) readCountOffset += gaDoc.getPageViews(2016, month, day);
long readCount = gaDoc.getTotalReadPageViews();
long fbLikeShareCount = FacebookApi.getUrlShareCount("http://" + Website.ALL_LANGUAGE.getHostName() + pratilipiPage.getUri());
if (pratilipi.getReadCountOffset() == readCountOffset && pratilipi.getReadCount() == readCount && pratilipi.getFbLikeShareCount() == fbLikeShareCount)
return;
updatePratilipiStats(pratilipiId, readCountOffset, readCount, null, fbLikeShareCount);
}
use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.
the class PratilipiDocUtil method getContent.
@Deprecated
public static Object getContent(Long pratilipiId, Integer chapterNo, Integer pageNo) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (!PratilipiDataUtil.hasAccessToReadPratilipiContent(pratilipi))
throw new InsufficientAccessException();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
if (pcDoc == null)
return null;
else if (chapterNo == null)
return _processContent(pratilipi, pcDoc);
Chapter chapter = pcDoc.getChapter(chapterNo);
if (chapter == null)
return null;
else if (pageNo == null)
return _processContent(pratilipi, chapter);
PratilipiContentDoc.Page page = chapter.getPage(pageNo);
if (page == null)
return null;
else
return _processContent(pratilipi, chapter.getPage(pageNo));
}
use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.
the class PratilipiDocUtil method addContentChapter.
public static JsonArray addContentChapter(Long pratilipiId, Integer chapterNo) throws InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (!PratilipiDataUtil.hasAccessToUpdatePratilipiContent(pratilipi))
throw new InsufficientAccessException();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
PratilipiContentDoc pcDoc = docAccessor.getPratilipiContentDoc(pratilipiId);
if (pcDoc == null)
pcDoc = docAccessor.newPratilipiContentDoc();
pcDoc.addChapter(chapterNo, null);
docAccessor.save(pratilipiId, pcDoc);
return pcDoc.getIndex();
}
use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.
the class UserDataUtil method updateUserAuthorStats.
public static void updateUserAuthorStats(Long userId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
User user = dataAccessor.getUser(userId);
UserFollowsDoc followsDoc = docAccessor.getUserFollowsDoc(userId);
if (user.getFollowCount().equals(followsDoc.getFollows(UserFollowState.FOLLOWING).size()))
return;
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_UPDATE, user);
user.setFollowCount((long) followsDoc.getFollows(UserFollowState.FOLLOWING).size());
user = dataAccessor.createOrUpdateUser(user, auditLog);
}
use of com.pratilipi.data.DocAccessor in project pratilipi by Pratilipi.
the class PratilipiDataUtil method updateUserPratilipiStats.
public static void updateUserPratilipiStats(Long pratilipiId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (pratilipi.getState() != PratilipiState.PUBLISHED)
return;
PratilipiReviewsDoc reviewsDoc = docAccessor.getPratilipiReviewsDoc(pratilipiId);
if (pratilipi.getRatingCount().equals(reviewsDoc.getRatingCount()) && pratilipi.getTotalRating().equals(reviewsDoc.getTotalRating()) && pratilipi.getReviewCount().equals(reviewsDoc.getReviewCount()))
return;
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.PRATILIPI_UPDATE, pratilipi);
pratilipi.setRatingCount(reviewsDoc.getRatingCount());
pratilipi.setTotalRating(reviewsDoc.getTotalRating());
pratilipi.setReviewCount(reviewsDoc.getReviewCount());
pratilipi = dataAccessor.createOrUpdatePratilipi(pratilipi, auditLog);
}
Aggregations