use of com.pratilipi.data.type.UserPratilipi in project pratilipi by Pratilipi.
the class UserPratilipiDataUtil method hasAccessToUpdateUserPratilipiData.
public static boolean hasAccessToUpdateUserPratilipiData(UserPratilipi userPratilipi, AccessType accessType) {
AccessToken accessToken = AccessTokenFilter.getAccessToken();
if (!userPratilipi.getUserId().equals(accessToken.getUserId()))
return false;
if (!UserAccessUtil.hasUserAccess(accessToken.getUserId(), null, accessType))
return false;
// Review can not be created for content pieces created by the user
if (accessType == AccessType.USER_PRATILIPI_REVIEW) {
if (userPratilipi.getReviewState() == UserReviewState.BLOCKED)
return false;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(userPratilipi.getPratilipiId());
Author author = pratilipi.getAuthorId() == null ? null : dataAccessor.getAuthor(pratilipi.getAuthorId());
if (author != null && userPratilipi.getUserId().equals(author.getUserId()))
return false;
}
return true;
}
use of com.pratilipi.data.type.UserPratilipi in project pratilipi by Pratilipi.
the class UserPratilipiDataUtil method saveUserPratilipiReview.
public static UserPratilipiData saveUserPratilipiReview(Long userId, Long pratilipiId, Integer rating, String review, UserReviewState reviewState) throws InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(userId, pratilipiId);
if (userPratilipi == null) {
userPratilipi = dataAccessor.newUserPratilipi();
userPratilipi.setUserId(userId);
userPratilipi.setPratilipiId(pratilipiId);
}
if (!hasAccessToUpdateUserPratilipiData(userPratilipi, AccessType.USER_PRATILIPI_REVIEW))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_PRATILIPI_REVIEW, userPratilipi);
if (rating != null && !rating.equals(userPratilipi.getRating()) && !(rating == 0 && userPratilipi.getRating() == null)) {
userPratilipi.setRating(rating);
userPratilipi.setRatingDate(new Date());
}
if (review != null) {
userPratilipi.setReviewTitle(null);
userPratilipi.setReview(review);
if (userPratilipi.getReviewState() != UserReviewState.PUBLISHED) {
// NOTE: As review comment and likes are counted only if they
// were created after review date, do NOT update reviewDate if
// review is already published.
userPratilipi.setReviewState(UserReviewState.PUBLISHED);
userPratilipi.setReviewDate(new Date());
}
}
// review is already published.
if (reviewState != null && reviewState != userPratilipi.getReviewState()) {
userPratilipi.setReviewState(reviewState);
userPratilipi.setReviewDate(new Date());
}
userPratilipi = dataAccessor.createOrUpdateUserPratilipi(userPratilipi, auditLog);
return createUserPratilipiData(userPratilipi);
}
use of com.pratilipi.data.type.UserPratilipi in project pratilipi by Pratilipi.
the class UserPratilipiDataUtil method saveUserPratilipiAddToLibrary.
public static UserPratilipiData saveUserPratilipiAddToLibrary(Long userId, Long pratilipiId, String lastOpenedPage, Boolean addedToLibrary) throws InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(userId, pratilipiId);
if (userPratilipi == null) {
userPratilipi = dataAccessor.newUserPratilipi();
userPratilipi.setUserId(userId);
userPratilipi.setPratilipiId(pratilipiId);
}
if (lastOpenedPage == null && addedToLibrary == null)
return createUserPratilipiData(userPratilipi);
if (!hasAccessToUpdateUserPratilipiData(userPratilipi, AccessType.USER_PRATILIPI_LIBRARY))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_PRATILIPI_LIBRARY, userPratilipi);
if (lastOpenedPage != null) {
userPratilipi.setLastOpenedPage(lastOpenedPage);
userPratilipi.setLastOpenedDate(new Date());
}
if (addedToLibrary != null) {
userPratilipi.setAddedToLib(addedToLibrary);
userPratilipi.setAddedToLibDate(new Date());
}
userPratilipi = dataAccessor.createOrUpdateUserPratilipi(userPratilipi, auditLog);
return createUserPratilipiData(userPratilipi);
}
use of com.pratilipi.data.type.UserPratilipi in project pratilipi by Pratilipi.
the class UserPratilipiBackfillApi method updateUserPratilipi.
private UserPratilipiData updateUserPratilipi(Long userId, Long pratilipiId, String lastPageOpened, String lastOpenedDate) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(userId, pratilipiId);
if (userPratilipi == null) {
// CREATE USER PRATILIPI
userPratilipi = dataAccessor.newUserPratilipi();
userPratilipi.setUserId(userId);
userPratilipi.setPratilipiId(pratilipiId);
}
// Creating Auditlog entity
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_PRATILIPI_REVIEW, userPratilipi);
// update lastPageOpened
userPratilipi.setLastOpenedPage(lastPageOpened);
try {
// update lastPageOpenedDate
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
formatter.setTimeZone(TimeZone.getTimeZone("IST"));
Date date = (Date) formatter.parse(lastOpenedDate);
userPratilipi.setLastOpenedDate(date);
userPratilipi = dataAccessor.createOrUpdateUserPratilipi(userPratilipi, auditLog);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.log(Level.SEVERE, "Event Date : " + lastOpenedDate);
throw new UnexpectedServerException("Error while parsing date.");
}
return UserPratilipiDataUtil.createUserPratilipiData(userPratilipi);
}
Aggregations