use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.
the class CommentDataUtil method saveCommentData.
public static CommentData saveCommentData(CommentData commentData) throws InvalidArgumentException, InsufficientAccessException {
_validateCommentDataForSave(commentData);
boolean isNew = commentData.getId() == null;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Comment comment = isNew ? dataAccessor.newComment() : dataAccessor.getComment(commentData.getId());
if (isNew && !hasAccessToAddCommentData(commentData))
throw new InsufficientAccessException();
if (!isNew && !hasAccessToUpdateCommentData(comment))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), isNew ? AccessType.COMMENT_ADD : AccessType.COMMENT_UPDATE, comment);
if (isNew) {
comment.setUserId(commentData.getUserId());
comment.setParentType(commentData.getParentType());
comment.setParentId(commentData.getParentId());
if (commentData.getParentType() == CommentParentType.REVIEW) {
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(commentData.getParentId());
comment.setReferenceType(ReferenceType.PRATILIPI);
comment.setReferenceId(userPratilipi.getPratilipiId());
}
comment.setCreationDate(new Date());
} else {
comment.setLastUpdated(new Date());
}
if (commentData.hasContent())
comment.setContent(commentData.getContent());
if (commentData.hasState())
comment.setState(commentData.getState());
comment = dataAccessor.createOrUpdateComment(comment, auditLog);
User user = dataAccessor.getUser(commentData.getUserId());
UserData userData = UserDataUtil.createUserData(user);
commentData = createCommentData(comment);
commentData.setUser(userData);
return commentData;
}
use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.
the class DataAccessorMockImpl method createOrUpdateUser.
@Override
public User createOrUpdateUser(User user) {
boolean newUser = true;
for (User aUser : UserMock.USER_TABLE) if (aUser.getId() == user.getId())
newUser = false;
if (newUser) {
Long id = 0L;
for (User aUser : UserMock.USER_TABLE) if (aUser.getId() >= id)
id = aUser.getId() + 1;
((UserEntity) user).setId(id);
UserMock.USER_TABLE.add(user);
} else {
int index = -1;
for (int i = 0; i < UserMock.USER_TABLE.size(); i++) if (UserMock.USER_TABLE.get(i).getId() == user.getId())
index = i;
UserMock.USER_TABLE.set(index, user);
}
return user;
}
use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.
the class DataAccessorGaeImpl method getUserByEmail.
@Override
public User getUserByEmail(String email) {
String memcacheId = "DataStore.User-" + email;
User user = memcache.get(memcacheId);
if (user != null)
return user;
user = ObjectifyService.ofy().load().type(UserEntity.class).filter("EMAIL", email).filter("STATE !=", UserState.DELETED).order("STATE").order("SIGN_UP_DATE").first().now();
if (user != null)
memcache.put(memcacheId, user);
return user;
}
use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.
the class AuthorDataUtil method createAuthorDataList.
public static List<AuthorData> createAuthorDataList(List<Long> authorIdList, boolean includeUserData) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<Author> authorList = dataAccessor.getAuthorList(authorIdList);
Map<Long, Page> authorPages = dataAccessor.getPages(PageType.AUTHOR, authorIdList);
List<AuthorData> authorDataList = new ArrayList<>(authorIdList.size());
if (includeUserData) {
List<Long> userIdList = new ArrayList<>(authorIdList.size());
for (Author author : authorList) if (author.getUserId() != null)
userIdList.add(author.getUserId());
List<User> userList = dataAccessor.getUserList(userIdList);
Map<Long, User> users = new HashMap<>(userIdList.size());
for (User user : userList) users.put(user.getId(), user);
for (Author author : authorList) authorDataList.add(createAuthorData(author, authorPages.get(author.getId()), users.get(author.getUserId())));
} else {
for (Author author : authorList) authorDataList.add(createAuthorData(author, authorPages.get(author.getId())));
}
return authorDataList;
}
use of com.pratilipi.data.type.User 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);
}
Aggregations