use of com.pratilipi.data.DataAccessor 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.DataAccessor in project pratilipi by Pratilipi.
the class UserDataUtil method _loginFederatedUser.
private static UserData _loginFederatedUser(UserData apiUserData, User user, UserSignUpSource signUpSource) throws InsufficientAccessException {
// Do nothing if a user is already logged in
if (!AccessTokenFilter.getAccessToken().getUserId().equals(0L))
return getCurrentUser();
// Note: Users having Facebook or Google Id can never be in GUEST or REFERRAL state.
// Note: No action required for REGISTERED or ACTIVE users.
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
boolean isNew = false;
if (user == null || user.getState() == UserState.DELETED) {
if (apiUserData.getEmail() != null)
user = dataAccessor.getUserByEmail(apiUserData.getEmail());
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), null, null);
if (user == null || user.getState() == UserState.DELETED) {
user = dataAccessor.newUser();
auditLog.setAccessType(AccessType.USER_ADD);
auditLog.setEventDataOld(user);
user.setEmail(apiUserData.getEmail());
// Counting on Facebook / Google for e-mail/user verification
user.setState(UserState.ACTIVE);
user.setSignUpDate(new Date());
user.setSignUpSource(signUpSource);
isNew = true;
} else if (user.getState() == UserState.REFERRAL) {
auditLog.setAccessType(AccessType.USER_ADD);
auditLog.setEventDataOld(user);
// Counting on Facebook / Google for e-mail/user verification
user.setState(UserState.ACTIVE);
user.setSignUpDate(new Date());
user.setSignUpSource(signUpSource);
isNew = true;
} else if (user.getState() == UserState.REGISTERED) {
auditLog.setAccessType(AccessType.USER_UPDATE);
auditLog.setEventDataOld(user);
// Counting on Facebook / google for e-mail/user verification
user.setState(UserState.ACTIVE);
} else {
// user.getState() == UserState.ACTIVE || user.getState() == UserState.BLOCKED
auditLog.setAccessType(AccessType.USER_UPDATE);
auditLog.setEventDataOld(user);
}
if (apiUserData.getFacebookId() != null)
user.setFacebookId(apiUserData.getFacebookId());
if (apiUserData.getGoogleId() != null)
user.setGoogleId(apiUserData.getGoogleId());
user.setLastUpdated(new Date());
user = dataAccessor.createOrUpdateUser(user, auditLog);
}
if (user.getState() == UserState.BLOCKED)
throw new InsufficientAccessException(GenericRequest.ERR_ACCOUNT_BLOCKED);
_loginUser(AccessTokenFilter.getAccessToken(), user);
UserData userData = createUserData(user);
if (isNew) {
userData.setFirstName(apiUserData.getFirstName());
userData.setLastName(apiUserData.getLastName());
userData.setGender(apiUserData.getGender());
userData.setDateOfBirth(apiUserData.getDateOfBirth());
}
return userData;
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class PratilipiDataUtil method updatePratilipiTags.
public static boolean updatePratilipiTags(long pratilipiId, PratilipiType pratilipiType, List<Long> tagIds, List<String> suggestedTags) throws InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (pratilipi == null)
return false;
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.PRATILIPI_UPDATE, pratilipi);
PratilipiData pratilipiData = createPratilipiData(pratilipi);
AccessToken accessToken = AccessTokenFilter.getAccessToken();
logger.log(Level.INFO, "User Id : " + accessToken.getUserId());
if (!hasAccessToUpdatePratilipiData(pratilipi, pratilipiData)) {
throw new InsufficientAccessException();
}
if (pratilipiType != null)
pratilipi.setType(pratilipiType);
if (tagIds != null)
pratilipi.setTagIds(tagIds);
if (suggestedTags != null)
pratilipi.setSuggestedTags(suggestedTags);
dataAccessor.createOrUpdatePratilipi(pratilipi, auditLog);
return true;
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class PratilipiDataUtil method createPratilipiDataList.
public static List<PratilipiData> createPratilipiDataList(List<Long> pratilipiIdList, boolean includeAuthorData, boolean includeMetaData) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<Pratilipi> pratilipiList = dataAccessor.getPratilipiList(pratilipiIdList);
Map<Long, Page> pratilipiPages = dataAccessor.getPages(PageType.PRATILIPI, pratilipiIdList);
Map<Long, AuthorData> authorIdToDataMap = null;
if (includeAuthorData) {
List<Long> authorIdList = new LinkedList<>();
for (Pratilipi pratilipi : pratilipiList) if (pratilipi.getAuthorId() != null && !authorIdList.contains(pratilipi.getAuthorId()))
authorIdList.add(pratilipi.getAuthorId());
List<AuthorData> authorDataList = AuthorDataUtil.createAuthorDataList(authorIdList, false);
authorIdToDataMap = new HashMap<>(authorDataList.size());
for (AuthorData authorData : authorDataList) authorIdToDataMap.put(authorData.getId(), authorData);
}
List<PratilipiData> pratilipiDataList = new ArrayList<>(pratilipiList.size());
for (Pratilipi pratilipi : pratilipiList) {
PratilipiData pratilipiData = createPratilipiData(pratilipi, pratilipiPages.get(pratilipi.getId()), null, includeMetaData);
if (includeAuthorData && pratilipi.getAuthorId() != null)
pratilipiData.setAuthor(authorIdToDataMap.get(pratilipi.getAuthorId()));
pratilipiData.setRelevance(calculateRelevance(pratilipi, dataAccessor.getAuthor(pratilipi.getAuthorId())));
pratilipiDataList.add(pratilipiData);
}
// Fetching UserPratilipi list from DataStore
List<UserPratilipi> userPratilipiList = dataAccessor.getUserPratilipiList(AccessTokenFilter.getAccessToken().getUserId(), pratilipiIdList);
// Setting isAddedToLib flag for for each PratilipiData in the list
for (int i = 0; i < userPratilipiList.size(); i++) {
UserPratilipi userPratilipi = userPratilipiList.get(i);
pratilipiDataList.get(i).setAddedToLib(userPratilipi != null && userPratilipi.isAddedToLib());
}
return pratilipiDataList;
}
use of com.pratilipi.data.DataAccessor 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