use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class UserPratilipiDataUtil method createUserPratilipiData.
public static UserPratilipiData createUserPratilipiData(UserPratilipi userPratilipi) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
User user = dataAccessor.getUser(userPratilipi.getUserId());
UserData userData = UserDataUtil.createUserData(user);
PratilipiReviewsDoc reviewsDoc = docAccessor.getPratilipiReviewsDoc(userPratilipi.getPratilipiId());
UserPratilipiData userPratilipiData = new UserPratilipiData();
userPratilipiData.setId(userPratilipi.getId());
userPratilipiData.setUserId(userPratilipi.getUserId());
userPratilipiData.setPratilipiId(userPratilipi.getPratilipiId());
userPratilipiData.setUser(userData);
userPratilipiData.setUserName(userData.getDisplayName());
userPratilipiData.setUserImageUrl(userData.getProfileImageUrl());
userPratilipiData.setUserProfilePageUrl(userData.getProfilePageUrl());
userPratilipiData.setRating(userPratilipi.getRating());
userPratilipiData.setReview(processReview(userPratilipi.getReviewTitle(), userPratilipi.getReview()));
userPratilipiData.setReviewState(userPratilipi.getReviewState());
userPratilipiData.setReviewDate(userPratilipi.getReviewDate());
for (UserPratilipiDoc review : reviewsDoc.getReviews()) {
if (review.getId().equals(userPratilipi.getId())) {
userPratilipiData.setCommentCount(review.getCommentCount());
userPratilipiData.setLikeCount(review.getLikeCount());
userPratilipiData.setLiked(review.getLikedByUserIds().contains(AccessTokenFilter.getAccessToken().getUserId()));
break;
}
}
userPratilipiData.setAddedToLib(userPratilipi.isAddedToLib());
userPratilipiData.setAccessToReview(hasAccessToUpdateUserPratilipiData(userPratilipi, AccessType.USER_PRATILIPI_REVIEW));
return userPratilipiData;
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class UserPratilipiDataUtil method getContentsReadList.
/**
* @param userId
* @return List of pratilipi Ids read (completed) by the user
*/
public static List<Long> getContentsReadList(Long userId) {
Logger logger = Logger.getLogger(UserPratilipiDataUtil.class.getSimpleName());
List<Long> contentsReadList = new ArrayList<>();
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<UserPratilipi> userPratilipiList = dataAccessor.getUserPratilipiList(userId, null, null, null).getDataList();
if (userPratilipiList == null || userPratilipiList.size() == 0)
return null;
logger.log(Level.INFO, "LIST OF READ CONTENTS");
for (UserPratilipi userPratilipi : userPratilipiList) {
if (userPratilipi.getLastOpenedDate() != null) {
contentsReadList.add(userPratilipi.getPratilipiId());
logger.log(Level.INFO, "PRATILIPI ID : " + userPratilipi.getPratilipiId());
}
}
return contentsReadList;
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class LogAndSecurityFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
String uri = ((HttpServletRequest) request).getRequestURI().toString();
if (!uri.equals("/poc1")) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Page page = dataAccessor.getPage(uri);
if (page != null) {
if (page.getType() == PageType.BLOG_POST) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("pageId", page.getId());
jsonObject.addProperty("accessToken", AccessTokenFilter.getAccessToken().getId());
logger.log(Level.INFO, "DataFlow#PAGE_HIT::" + jsonObject.toString());
}
}
}
chain.doFilter(request, response);
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class NotificationFilter method doFilter.
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
String notificationIdStr = ((HttpServletRequest) req).getParameter(RequestParameter.NOTIFICATION_ID.getName());
if (notificationIdStr != null && !notificationIdStr.trim().isEmpty()) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Notification notification = dataAccessor.getNotification(Long.parseLong(notificationIdStr.trim()));
if (notification != null && notification.getState() == NotificationState.UNREAD && AccessTokenFilter.getAccessToken().getUserId().equals(notification.getUserId())) {
notification.setState(NotificationState.READ);
notification = dataAccessor.createOrUpdateNotification(notification);
}
}
chain.doFilter(req, resp);
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class VoteDataUtil method saveVoteData.
public static VoteData saveVoteData(Long userId, VoteParentType parentType, String parentId, VoteType type) throws InsufficientAccessException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Vote vote = dataAccessor.getVote(userId, parentType, parentId);
boolean isNew = vote == null;
if (isNew)
vote = dataAccessor.newVote();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.VOTE, vote);
if (isNew) {
vote.setUserId(userId);
vote.setParentType(parentType);
vote.setParentId(parentId);
if (parentType == VoteParentType.REVIEW) {
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(parentId);
vote.setReferenceType(ReferenceType.PRATILIPI);
vote.setReferenceId(userPratilipi.getPratilipiId());
} else if (parentType == VoteParentType.COMMENT) {
Comment comment = dataAccessor.getComment(Long.parseLong(parentId));
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(comment.getParentId());
vote.setReferenceType(ReferenceType.PRATILIPI);
vote.setReferenceId(userPratilipi.getPratilipiId());
}
vote.setCreationDate(new Date());
} else {
vote.setLastUpdated(new Date());
}
vote.setType(type);
if (!hasAccessToAddOrUpdateData(vote))
throw new InsufficientAccessException();
vote = dataAccessor.createOrUpdateVote(vote, auditLog);
return createVoteData(vote);
}
Aggregations