Search in sources :

Example 1 with AuthorData

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

the class AuthorApi method get.

@Get
public Response get(GetRequest request) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Author author = dataAccessor.getAuthor(request.authorId);
    UserAuthor userAuthor = dataAccessor.getUserAuthor(AccessTokenFilter.getAccessToken().getUserId(), request.authorId);
    AuthorData authorData = AuthorDataUtil.createAuthorData(author, null, null);
    Response response = new Response(authorData);
    response.setFollowing(userAuthor != null && userAuthor.getFollowState() == UserFollowState.FOLLOWING);
    return response;
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) AuthorData(com.pratilipi.data.client.AuthorData) UserAuthor(com.pratilipi.data.type.UserAuthor) Author(com.pratilipi.data.type.Author) UserAuthor(com.pratilipi.data.type.UserAuthor) Get(com.pratilipi.api.annotation.Get)

Example 2 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 3 with AuthorData

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

the class AuthorApi method post.

@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
    Gson gson = new Gson();
    AuthorData authorData = gson.fromJson(gson.toJson(request), AuthorData.class);
    if (// New authors (added by AEEs) are ACTIVE by default
    request.getId() == null)
        authorData.setState(AuthorState.ACTIVE);
    authorData = AuthorDataUtil.saveAuthorData(authorData);
    return new Response(authorData);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) AuthorData(com.pratilipi.data.client.AuthorData) Gson(com.google.gson.Gson) Post(com.pratilipi.api.annotation.Post)

Example 4 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() != null && 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 5 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);
        // List<AuthorData> authorDataList = AuthorDataUtil.createAuthorDataListEcs( authorIdList );
        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) Pratilipi(com.pratilipi.data.type.Pratilipi) UserPratilipi(com.pratilipi.data.type.UserPratilipi)

Aggregations

AuthorData (com.pratilipi.data.client.AuthorData)17 DataAccessor (com.pratilipi.data.DataAccessor)8 UserData (com.pratilipi.data.client.UserData)6 GenericResponse (com.pratilipi.api.shared.GenericResponse)5 Get (com.pratilipi.api.annotation.Get)3 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)3 Gson (com.google.gson.Gson)2 Post (com.pratilipi.api.annotation.Post)2 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)2 Author (com.pratilipi.data.type.Author)2 UserAuthor (com.pratilipi.data.type.UserAuthor)2 ArrayList (java.util.ArrayList)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)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 AccessToken (com.pratilipi.data.type.AccessToken)1 Page (com.pratilipi.data.type.Page)1