Search in sources :

Example 1 with User

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;
}
Also used : Comment(com.pratilipi.data.type.Comment) UserPratilipi(com.pratilipi.data.type.UserPratilipi) User(com.pratilipi.data.type.User) UserData(com.pratilipi.data.client.UserData) DataAccessor(com.pratilipi.data.DataAccessor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 2 with User

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;
}
Also used : ConversationUser(com.pratilipi.data.type.ConversationUser) User(com.pratilipi.data.type.User) ConversationUserEntity(com.pratilipi.data.type.gae.ConversationUserEntity) UserEntity(com.pratilipi.data.type.gae.UserEntity)

Example 3 with 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;
}
Also used : ConversationUser(com.pratilipi.data.type.ConversationUser) User(com.pratilipi.data.type.User) ConversationUserEntity(com.pratilipi.data.type.gae.ConversationUserEntity) UserEntity(com.pratilipi.data.type.gae.UserEntity)

Example 4 with 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;
}
Also used : User(com.pratilipi.data.type.User) HashMap(java.util.HashMap) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) Page(com.pratilipi.data.type.Page) AuthorData(com.pratilipi.data.client.AuthorData) Author(com.pratilipi.data.type.Author)

Example 5 with User

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);
}
Also used : User(com.pratilipi.data.type.User) DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) UserFollowsDoc(com.pratilipi.data.type.UserFollowsDoc) AuditLog(com.pratilipi.data.type.AuditLog)

Aggregations

User (com.pratilipi.data.type.User)30 DataAccessor (com.pratilipi.data.DataAccessor)22 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)9 AuditLog (com.pratilipi.data.type.AuditLog)8 UserData (com.pratilipi.data.client.UserData)7 UserEntity (com.pratilipi.data.type.gae.UserEntity)7 Date (java.util.Date)7 Author (com.pratilipi.data.type.Author)6 ConversationUser (com.pratilipi.data.type.ConversationUser)5 ArrayList (java.util.ArrayList)5 JsonObject (com.google.gson.JsonObject)4 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)4 ConversationUserEntity (com.pratilipi.data.type.gae.ConversationUserEntity)4 GenericResponse (com.pratilipi.api.shared.GenericResponse)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 HashMap (java.util.HashMap)3 Get (com.pratilipi.api.annotation.Get)2 BlobAccessor (com.pratilipi.data.BlobAccessor)2 DocAccessor (com.pratilipi.data.DocAccessor)2