Search in sources :

Example 6 with UserAuthor

use of com.pratilipi.data.type.UserAuthor in project pratilipi by Pratilipi.

the class UserAuthorDataUtil method saveUserAuthorFollow.

public static UserAuthorData saveUserAuthorFollow(Long userId, Long authorId, UserFollowState followState) throws InvalidArgumentException, InsufficientAccessException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    UserAuthor userAuthor = dataAccessor.getUserAuthor(userId, authorId);
    if (userAuthor == null) {
        userAuthor = dataAccessor.newUserAuthor();
        userAuthor.setUserId(userId);
        userAuthor.setAuthorId(authorId);
    }
    if (!hasAccessToUpdateUserAuthorData(userAuthor, AccessType.USER_AUTHOR_FOLLOWING))
        throw new InsufficientAccessException();
    AccessToken accessToken = AccessTokenFilter.getAccessToken();
    AuditLog auditLog = dataAccessor.newAuditLog(accessToken, AccessType.USER_AUTHOR_FOLLOWING, userAuthor);
    userAuthor.setFollowState(followState);
    userAuthor.setFollowDate(new Date());
    userAuthor = dataAccessor.createOrUpdateUserAuthor(userAuthor, auditLog);
    return createUserAuthorData(userAuthor);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) AccessToken(com.pratilipi.data.type.AccessToken) UserAuthor(com.pratilipi.data.type.UserAuthor) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) AuditLog(com.pratilipi.data.type.AuditLog) Date(java.util.Date)

Example 7 with UserAuthor

use of com.pratilipi.data.type.UserAuthor in project pratilipi by Pratilipi.

the class UserAuthorDataUtil method getUserFollowList.

public static DataListCursorTuple<AuthorData> getUserFollowList(Long userId, String cursor, Integer offset, Integer resultCount) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    User user = dataAccessor.getUser(userId);
    if (user.getFollowCount() == 0L)
        return new DataListCursorTuple<>(new ArrayList<AuthorData>(0), null, 0L);
    DataListCursorTuple<Long> authorIdListCursorTuple = dataAccessor.getUserAuthorFollowList(userId, null, cursor, offset, resultCount);
    List<Long> authorIdList = authorIdListCursorTuple.getDataList();
    List<AuthorData> authorDataList = AuthorDataUtil.createAuthorDataList(authorIdList, true);
    // Setting AuthorData.isFollowing flag
    if (userId.equals(AccessTokenFilter.getAccessToken().getUserId())) {
        for (AuthorData authorData : authorDataList) authorData.setFollowing(true);
    } else {
        List<UserAuthor> userAuthorList = dataAccessor.getUserAuthorList(AccessTokenFilter.getAccessToken().getUserId(), authorIdList);
        if (userAuthorList.size() != 0)
            for (int i = 0; i < authorIdList.size(); i++) if (userAuthorList.get(i) != null && userAuthorList.get(i).getFollowState() == UserFollowState.FOLLOWING)
                authorDataList.get(i).setFollowing(true);
    }
    // Setting UserData.isFollowing flag
    Author author = dataAccessor.getAuthorByUserId(AccessTokenFilter.getAccessToken().getUserId());
    if (author != null) {
        List<Long> userIdList = new ArrayList<>(authorDataList.size());
        List<UserData> userDataList = new ArrayList<>(authorDataList.size());
        for (AuthorData authorData : authorDataList) {
            if (authorData.getUser().getId() != null) {
                userIdList.add(authorData.getUser().getId());
                userDataList.add(authorData.getUser());
            }
        }
        List<UserAuthor> userAuthorList = dataAccessor.getUserAuthorList(userIdList, author.getId());
        if (userAuthorList != null) {
            for (UserAuthor userAuthor : userAuthorList) if (userAuthor != null && userAuthor.getFollowState() == UserFollowState.FOLLOWING)
                userDataList.get(userIdList.indexOf(userAuthor.getUserId())).setFollowing(true);
        }
    }
    return new DataListCursorTuple<>(authorDataList, authorIdListCursorTuple.getCursor(), user.getFollowCount());
}
Also used : User(com.pratilipi.data.type.User) UserData(com.pratilipi.data.client.UserData) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) UserAuthorData(com.pratilipi.data.client.UserAuthorData) AuthorData(com.pratilipi.data.client.AuthorData) UserAuthor(com.pratilipi.data.type.UserAuthor) UserAuthor(com.pratilipi.data.type.UserAuthor) Author(com.pratilipi.data.type.Author)

Example 8 with UserAuthor

use of com.pratilipi.data.type.UserAuthor in project pratilipi by Pratilipi.

the class UserAuthorDataUtil method getUserAuthor.

public static UserAuthorData getUserAuthor(Long userId, Long authorId) {
    if (userId == null || userId.equals(0L) || authorId == null || authorId.equals(0L))
        return null;
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    UserAuthor userAuthor = dataAccessor.getUserAuthor(userId, authorId);
    if (userAuthor == null) {
        userAuthor = dataAccessor.newUserAuthor();
        userAuthor.setUserId(userId);
        userAuthor.setAuthorId(authorId);
    }
    return createUserAuthorData(userAuthor);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) UserAuthor(com.pratilipi.data.type.UserAuthor)

Example 9 with UserAuthor

use of com.pratilipi.data.type.UserAuthor in project pratilipi by Pratilipi.

the class UserAuthorDataUtil method getAuthorFollowList.

public static DataListCursorTuple<UserData> getAuthorFollowList(Long authorId, String cursor, Integer offset, Integer resultCount) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Author author = dataAccessor.getAuthor(authorId);
    if (author.getFollowCount() == 0L)
        return new DataListCursorTuple<>(new ArrayList<UserData>(0), null, 0L);
    DataListCursorTuple<Long> userIdListCursorTuple = dataAccessor.getUserAuthorFollowList(null, authorId, cursor, offset, resultCount);
    List<Long> userIdList = userIdListCursorTuple.getDataList();
    Map<Long, UserData> users = UserDataUtil.createUserDataList(userIdList, true);
    List<UserData> userDataList = new ArrayList<>(userIdList.size());
    for (Long userId : userIdList) userDataList.add(users.get(userId));
    // Setting UserData.isFollowing flag
    if (AccessTokenFilter.getAccessToken().getUserId().equals(author.getUserId())) {
        for (UserData userData : userDataList) userData.setFollowing(true);
    } else {
        Author authorProfile = dataAccessor.getAuthorByUserId(AccessTokenFilter.getAccessToken().getUserId());
        if (authorProfile != null) {
            List<UserAuthor> userAuthorList = dataAccessor.getUserAuthorList(userIdList, authorProfile.getId());
            for (int i = 0; i < userIdList.size(); i++) if (userAuthorList.get(i) != null && userAuthorList.get(i).getFollowState() == UserFollowState.FOLLOWING)
                userDataList.get(i).setFollowing(true);
        }
    }
    // Setting AuthorData.isFollowing flag
    List<Long> authorIdList = new ArrayList<>(userDataList.size());
    for (UserData userData : userDataList) authorIdList.add(userData.getAuthor().getId());
    List<UserAuthor> userAuthorList = dataAccessor.getUserAuthorList(AccessTokenFilter.getAccessToken().getUserId(), authorIdList);
    if (userAuthorList.size() != 0)
        for (int i = 0; i < authorIdList.size(); i++) if (userAuthorList.get(i) != null && userAuthorList.get(i).getFollowState() == UserFollowState.FOLLOWING)
            userDataList.get(i).getAuthor().setFollowing(true);
    return new DataListCursorTuple<>(userDataList, userIdListCursorTuple.getCursor(), author.getFollowCount());
}
Also used : UserData(com.pratilipi.data.client.UserData) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) UserAuthor(com.pratilipi.data.type.UserAuthor) Author(com.pratilipi.data.type.Author) UserAuthor(com.pratilipi.data.type.UserAuthor)

Example 10 with UserAuthor

use of com.pratilipi.data.type.UserAuthor in project pratilipi by Pratilipi.

the class EmailDataUtil method _createDataModelForAuthorFollowEmail.

private static Object[] _createDataModelForAuthorFollowEmail(String userAuthorId) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    UserAuthor userAuthor = dataAccessor.getUserAuthor(userAuthorId);
    UserData user = UserDataUtil.createUserData(dataAccessor.getUser(userAuthor.getUserId()));
    AuthorData follower = AuthorDataUtil.createAuthorData(dataAccessor.getAuthorByUserId(userAuthor.getUserId()));
    Map<String, Object> dataModel = new HashMap<>();
    dataModel.put("follower_name", follower.getName() != null ? follower.getName() : follower.getNameEn());
    dataModel.put("follower_page_url", _getDomainName(follower.getLanguage()) + follower.getPageUrl());
    dataModel.put("follower_profile_image_url", follower.getProfileImageUrl(50));
    if (follower.getFollowCount() > 0)
        dataModel.put("follower_followers_count", follower.getFollowCount());
    return new Object[] { dataModel, user.getLanguage() };
}
Also used : UserData(com.pratilipi.data.client.UserData) HashMap(java.util.HashMap) DataAccessor(com.pratilipi.data.DataAccessor) AuthorData(com.pratilipi.data.client.AuthorData) UserAuthor(com.pratilipi.data.type.UserAuthor)

Aggregations

UserAuthor (com.pratilipi.data.type.UserAuthor)12 DataAccessor (com.pratilipi.data.DataAccessor)9 Author (com.pratilipi.data.type.Author)6 ArrayList (java.util.ArrayList)4 AuthorData (com.pratilipi.data.client.AuthorData)3 UserData (com.pratilipi.data.client.UserData)3 AccessToken (com.pratilipi.data.type.AccessToken)3 UserPratilipi (com.pratilipi.data.type.UserPratilipi)3 UserAuthorEntity (com.pratilipi.data.type.gae.UserAuthorEntity)3 UserPratilipiEntity (com.pratilipi.data.type.gae.UserPratilipiEntity)3 Date (java.util.Date)3 Get (com.pratilipi.api.annotation.Get)2 GenericResponse (com.pratilipi.api.shared.GenericResponse)2 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)2 AuditLog (com.pratilipi.data.type.AuditLog)2 Comment (com.pratilipi.data.type.Comment)2 Pratilipi (com.pratilipi.data.type.Pratilipi)2 Vote (com.pratilipi.data.type.Vote)2 HashMap (java.util.HashMap)2 Cursor (com.google.appengine.api.datastore.Cursor)1