Search in sources :

Example 6 with AuthorData

use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.

the class UserDataUtil method createUserData.

public static UserData createUserData(User user, Author author) {
    if (user == null)
        return null;
    UserData userData = new UserData(user.getId());
    userData.setFacebookId(user.getFacebookId());
    userData.setPassword(user.getPassword() != null);
    userData.setEmail(user.getEmail());
    userData.setPhone(user.getPhone());
    userData.setLanguage(user.getLanguage());
    userData.setState(user.getState());
    userData.setSignUpDate(user.getSignUpDate());
    userData.setFollowCount(user.getFollowCount());
    userData.setFirebaseToken(FirebaseApi.getCustomTokenForUser(userData.getId()));
    if (author != null) {
        AuthorData authorData = AuthorDataUtil.createAuthorData(author);
        userData.setAuthor(authorData);
        if (userData.getLanguage() == null)
            userData.setLanguage(author.getLanguage());
        userData.setFirstName(authorData.getFirstName() != null ? authorData.getFirstName() : authorData.getFirstNameEn());
        userData.setLastName(authorData.getLastName() != null ? authorData.getLastName() : authorData.getLastNameEn());
        userData.setDisplayName(userData.getFirstName() != null ? userData.getFirstName() : userData.getLastName());
        userData.setGender(authorData.getGender());
        userData.setDateOfBirth(authorData.getDateOfBirth());
        userData.setProfilePageUrl(authorData.getPageUrl());
        userData.setProfileImageUrl(authorData.getImageUrl());
    }
    return userData;
}
Also used : UserData(com.pratilipi.data.client.UserData) AuthorData(com.pratilipi.data.client.AuthorData)

Example 7 with AuthorData

use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.

the class PratilipiDataUtil method createPratilipiDataList.

public static List<PratilipiData> createPratilipiDataList(List<Long> pratilipiIdList, boolean includeAuthorData, boolean includeMetaData) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    List<Pratilipi> pratilipiList = dataAccessor.getPratilipiList(pratilipiIdList);
    Map<Long, Page> pratilipiPages = dataAccessor.getPages(PageType.PRATILIPI, pratilipiIdList);
    Map<Long, AuthorData> authorIdToDataMap = null;
    if (includeAuthorData) {
        List<Long> authorIdList = new LinkedList<>();
        for (Pratilipi pratilipi : pratilipiList) if (pratilipi.getAuthorId() != null && !authorIdList.contains(pratilipi.getAuthorId()))
            authorIdList.add(pratilipi.getAuthorId());
        List<AuthorData> authorDataList = AuthorDataUtil.createAuthorDataList(authorIdList, false);
        authorIdToDataMap = new HashMap<>(authorDataList.size());
        for (AuthorData authorData : authorDataList) authorIdToDataMap.put(authorData.getId(), authorData);
    }
    List<PratilipiData> pratilipiDataList = new ArrayList<>(pratilipiList.size());
    for (Pratilipi pratilipi : pratilipiList) {
        PratilipiData pratilipiData = createPratilipiData(pratilipi, pratilipiPages.get(pratilipi.getId()), null, includeMetaData);
        if (includeAuthorData && pratilipi.getAuthorId() != null)
            pratilipiData.setAuthor(authorIdToDataMap.get(pratilipi.getAuthorId()));
        pratilipiData.setRelevance(calculateRelevance(pratilipi, dataAccessor.getAuthor(pratilipi.getAuthorId())));
        pratilipiDataList.add(pratilipiData);
    }
    // Fetching UserPratilipi list from DataStore
    List<UserPratilipi> userPratilipiList = dataAccessor.getUserPratilipiList(AccessTokenFilter.getAccessToken().getUserId(), pratilipiIdList);
    // Setting isAddedToLib flag for for each PratilipiData in the list
    for (int i = 0; i < userPratilipiList.size(); i++) {
        UserPratilipi userPratilipi = userPratilipiList.get(i);
        pratilipiDataList.get(i).setAddedToLib(userPratilipi != null && userPratilipi.isAddedToLib());
    }
    return pratilipiDataList;
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) Page(com.pratilipi.data.type.Page) LinkedList(java.util.LinkedList) UserPratilipi(com.pratilipi.data.type.UserPratilipi) PratilipiData(com.pratilipi.data.client.PratilipiData) AuthorData(com.pratilipi.data.client.AuthorData) UserPratilipi(com.pratilipi.data.type.UserPratilipi) Pratilipi(com.pratilipi.data.type.Pratilipi)

Example 8 with AuthorData

use of com.pratilipi.data.client.AuthorData 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 9 with AuthorData

use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.

the class UserDataUtil method getCurrentUser.

public static UserData getCurrentUser() {
    AccessToken accessToken = AccessTokenFilter.getAccessToken();
    Long userId = accessToken.getUserId();
    if (userId.equals(0L) || accessToken.isExpired()) {
        UserData userData = new UserData(0L);
        userData.setAuthor(new AuthorData());
        userData.setFirstName("Guest");
        userData.setLastName("User");
        userData.setState(UserState.GUEST);
        return userData;
    } else {
        return createUserData(DataAccessorFactory.getDataAccessor().getUser(accessToken.getUserId()));
    }
}
Also used : UserData(com.pratilipi.data.client.UserData) AccessToken(com.pratilipi.data.type.AccessToken) AuthorData(com.pratilipi.data.client.AuthorData)

Example 10 with AuthorData

use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.

the class AuthorListApi method get.

@Get
public Response get(GetRequest request) throws InsufficientAccessException {
    AuthorFilter authorFilter = new AuthorFilter();
    authorFilter.setLanguage(request.getLanguage());
    authorFilter.setOrderByContentPublished(request.getOrderByContentPublished());
    DataListCursorTuple<AuthorData> authorListCursorTuple = AuthorDataUtil.getAuthorDataList(request.getSearchQuery(), authorFilter, request.getCursor(), request.getResultCount() == null ? 20 : request.getResultCount());
    return new Response(authorListCursorTuple.getDataList(), authorListCursorTuple.getCursor());
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) AuthorFilter(com.pratilipi.common.util.AuthorFilter) AuthorData(com.pratilipi.data.client.AuthorData) Get(com.pratilipi.api.annotation.Get)

Aggregations

AuthorData (com.pratilipi.data.client.AuthorData)15 DataAccessor (com.pratilipi.data.DataAccessor)7 UserData (com.pratilipi.data.client.UserData)6 GenericResponse (com.pratilipi.api.shared.GenericResponse)5 Author (com.pratilipi.data.type.Author)4 ArrayList (java.util.ArrayList)4 Get (com.pratilipi.api.annotation.Get)3 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)3 Page (com.pratilipi.data.type.Page)3 UserAuthor (com.pratilipi.data.type.UserAuthor)3 Post (com.pratilipi.api.annotation.Post)2 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)2 User (com.pratilipi.data.type.User)2 Task (com.pratilipi.taskqueue.Task)2 HashMap (java.util.HashMap)2 Gson (com.google.gson.Gson)1 AuthorFilter (com.pratilipi.common.util.AuthorFilter)1 DocAccessor (com.pratilipi.data.DocAccessor)1 PratilipiData (com.pratilipi.data.client.PratilipiData)1 UserAuthorData (com.pratilipi.data.client.UserAuthorData)1