Search in sources :

Example 1 with PratilipiState

use of com.pratilipi.common.type.PratilipiState in project pratilipi by Pratilipi.

the class PratilipiSite method createDataModelForAuthorPage.

public Map<String, Object> createDataModelForAuthorPage(Long authorId, Language language, boolean basicMode, HttpServletRequest request) throws InsufficientAccessException, UnexpectedServerException {
    Map<String, Object> dataModel = new HashMap<String, Object>();
    Gson gson = new Gson();
    AuthorApi.GetRequest authorApiGetRequest = new AuthorApi.GetRequest();
    authorApiGetRequest.setAuthorId(authorId);
    AuthorApi.Response authorResponse = ApiRegistry.getApi(AuthorApi.class).get(authorApiGetRequest);
    dataModel.put("title", SEOTitleUtil.getAuthorPageTitle(authorId, language));
    if (basicMode)
        dataModel.put("author", authorResponse);
    else
        dataModel.put("authorJson", gson.toJson(authorResponse));
    String action = request.getParameter("action") != null ? request.getParameter("action") : "author_page";
    dataModel.put("action", action);
    if (basicMode && action.equals("list_contents")) {
        Integer pageCurr = request.getParameter(RequestParameter.LIST_PAGE_NUMBER.getName()) != null ? Integer.parseInt(request.getParameter(RequestParameter.LIST_PAGE_NUMBER.getName())) : 1;
        PratilipiState pratilipiState = request.getParameter(RequestParameter.PRATILIPI_STATE.getName()) != null ? PratilipiState.valueOf(request.getParameter(RequestParameter.PRATILIPI_STATE.getName())) : PratilipiState.PUBLISHED;
        Integer resultCount = 10;
        PratilipiListV2Api.GetRequest pratilipiListRequest = new PratilipiListV2Api.GetRequest();
        pratilipiListRequest.setAuthorId(authorId);
        pratilipiListRequest.setState(pratilipiState);
        pratilipiListRequest.setResultCount(resultCount);
        pratilipiListRequest.setOffset((pageCurr - 1) * resultCount);
        PratilipiListV2Api.Response pratilipiListResponse = ApiRegistry.getApi(PratilipiListV2Api.class).get(pratilipiListRequest);
        dataModel.put("state", pratilipiState.toString());
        dataModel.put("pratilipiList", pratilipiListResponse.getPratilipiList());
        dataModel.put("pratilipiListPageCurr", pageCurr);
        Integer pageMax = pratilipiListResponse.getNumberFound() != null ? (int) Math.ceil(((double) pratilipiListResponse.getNumberFound()) / resultCount) : 1;
        dataModel.put("pratilipiListPageMax", pageMax);
        return dataModel;
    }
    UserAuthorFollowV1Api.GetRequest getRequest = new UserAuthorFollowV1Api.GetRequest();
    getRequest.setAuthorId(authorId);
    UserAuthorFollowV1Api.Response userAuthorResponse = ApiRegistry.getApi(UserAuthorFollowV1Api.class).get(getRequest);
    if (basicMode)
        dataModel.put("userAuthor", userAuthorResponse);
    else
        dataModel.put("userAuthorJson", gson.toJson(userAuthorResponse));
    if (basicMode) {
        Integer resultCount = 3;
        PratilipiListV2Api.GetRequest publishedPratilipiListRequest = new PratilipiListV2Api.GetRequest();
        publishedPratilipiListRequest.setAuthorId(authorId);
        publishedPratilipiListRequest.setState(PratilipiState.PUBLISHED);
        publishedPratilipiListRequest.setResultCount(resultCount);
        PratilipiListV2Api.Response publishedPratilipiListResponse = ApiRegistry.getApi(PratilipiListV2Api.class).get(publishedPratilipiListRequest);
        if (authorResponse.hasAccessToUpdate()) {
            PratilipiListV2Api.GetRequest draftedPratilipiListRequest = new PratilipiListV2Api.GetRequest();
            draftedPratilipiListRequest.setAuthorId(authorId);
            draftedPratilipiListRequest.setState(PratilipiState.DRAFTED);
            draftedPratilipiListRequest.setResultCount(resultCount);
            PratilipiListV2Api.Response draftedPratilipiListResponse = ApiRegistry.getApi(PratilipiListV2Api.class).get(draftedPratilipiListRequest);
            dataModel.put("draftedPratilipiList", draftedPratilipiListResponse.getPratilipiList());
        }
        Integer followResultCount = 3;
        UserAuthorFollowListApi.GetRequest followersListRequest = new UserAuthorFollowListApi.GetRequest();
        followersListRequest.setAuthorId(authorId);
        followersListRequest.setResultCount(followResultCount);
        UserAuthorFollowListApi.Response followersList = ApiRegistry.getApi(UserAuthorFollowListApi.class).get(followersListRequest);
        if (authorResponse.getUser() != null) {
            UserAuthorFollowListApi.GetRequest followingListRequest = new UserAuthorFollowListApi.GetRequest();
            followingListRequest.setUserId(authorResponse.getUser().getId());
            followingListRequest.setResultCount(followResultCount);
            UserAuthorFollowListApi.Response followingList = ApiRegistry.getApi(UserAuthorFollowListApi.class).get(followingListRequest);
            dataModel.put("followingList", followingList);
        }
        dataModel.put("followersList", followersList);
        dataModel.put("publishedPratilipiList", publishedPratilipiListResponse.getPratilipiList());
    }
    return dataModel;
}
Also used : PratilipiListV2Api(com.pratilipi.api.impl.pratilipi.PratilipiListV2Api) HashMap(java.util.HashMap) PratilipiState(com.pratilipi.common.type.PratilipiState) UserAuthorFollowV1Api(com.pratilipi.api.impl.userauthor.UserAuthorFollowV1Api) Gson(com.google.gson.Gson) AuthorApi(com.pratilipi.api.impl.author.AuthorApi) UserAuthorFollowListApi(com.pratilipi.api.impl.userauthor.UserAuthorFollowListApi) JsonObject(com.google.gson.JsonObject)

Example 2 with PratilipiState

use of com.pratilipi.common.type.PratilipiState in project pratilipi by Pratilipi.

the class PratilipiSite method createDataModelForSearchPage.

private Map<String, Object> createDataModelForSearchPage(boolean basicMode, Language language, HttpServletRequest request) throws InsufficientAccessException, UnexpectedServerException {
    String searchQuery = request.getParameter(RequestParameter.SEARCH_QUERY.getName());
    if (searchQuery == null || searchQuery.trim().isEmpty())
        searchQuery = null;
    Long authorId = null;
    String authorIdString = request.getParameter(RequestParameter.AUTHOR_ID.getName());
    if (authorIdString != null && !authorIdString.trim().isEmpty())
        authorId = Long.parseLong(authorIdString);
    PratilipiState pratilipiState = PratilipiState.PUBLISHED;
    String state = request.getParameter(RequestParameter.PRATILIPI_STATE.getName());
    if (state != null && !state.trim().isEmpty())
        pratilipiState = PratilipiState.valueOf(state);
    Integer resultCount = 20;
    String resultCountString = request.getParameter(RequestParameter.RESULT_COUNT.getName());
    if (resultCountString != null && !resultCountString.trim().isEmpty())
        resultCount = Integer.parseInt(resultCountString);
    Integer pageCurr = 1;
    String pageNoString = request.getParameter(RequestParameter.LIST_PAGE_NUMBER.getName());
    if (pageNoString != null && !pageNoString.trim().isEmpty())
        pageCurr = Integer.parseInt(pageNoString);
    PratilipiListV2Api.GetRequest PratilipiListV1ApiRequest = new PratilipiListV2Api.GetRequest();
    PratilipiListV1ApiRequest.setLanguage(language);
    PratilipiListV1ApiRequest.setState(pratilipiState);
    PratilipiListV1ApiRequest.setResultCount(resultCount);
    PratilipiListV1ApiRequest.setOffset((pageCurr - 1) * resultCount);
    if (searchQuery != null)
        PratilipiListV1ApiRequest.setSearchQuery(searchQuery);
    if (authorId != null)
        PratilipiListV1ApiRequest.setAuthorId(authorId);
    PratilipiListV2Api.Response response = ApiRegistry.getApi(PratilipiListV2Api.class).get(PratilipiListV1ApiRequest);
    PratilipiFilter pratilipiFilter = new PratilipiFilter();
    pratilipiFilter.setLanguage(language);
    pratilipiFilter.setState(pratilipiState);
    Gson gson = new Gson();
    Map<String, Object> dataModel = new HashMap<String, Object>();
    dataModel.put("title", SEOTitleUtil.getSearchPageTitle(language));
    if (basicMode) {
        dataModel.put("pratilipiList", response.getPratilipiList());
        dataModel.put("pratilipiListSearchQuery", searchQuery);
        dataModel.put("pratilipiListPageCurr", pageCurr);
        Integer pageMax = response.getNumberFound() != null ? (int) Math.ceil(((double) response.getNumberFound()) / resultCount) : 1;
        dataModel.put("pratilipiListPageMax", pageMax);
    } else {
        dataModel.put("pratilipiListJson", gson.toJson(response.getPratilipiList()));
        dataModel.put("pratilipiListSearchQuery", searchQuery);
        dataModel.put("pratilipiListFilterJson", gson.toJson(pratilipiFilter));
        dataModel.put("pratilipiListCursor", response.getCursor());
    }
    return dataModel;
}
Also used : PratilipiListV2Api(com.pratilipi.api.impl.pratilipi.PratilipiListV2Api) HashMap(java.util.HashMap) PratilipiState(com.pratilipi.common.type.PratilipiState) Gson(com.google.gson.Gson) PratilipiFilter(com.pratilipi.common.util.PratilipiFilter) JsonObject(com.google.gson.JsonObject)

Aggregations

Gson (com.google.gson.Gson)2 JsonObject (com.google.gson.JsonObject)2 PratilipiListV2Api (com.pratilipi.api.impl.pratilipi.PratilipiListV2Api)2 PratilipiState (com.pratilipi.common.type.PratilipiState)2 HashMap (java.util.HashMap)2 AuthorApi (com.pratilipi.api.impl.author.AuthorApi)1 UserAuthorFollowListApi (com.pratilipi.api.impl.userauthor.UserAuthorFollowListApi)1 UserAuthorFollowV1Api (com.pratilipi.api.impl.userauthor.UserAuthorFollowV1Api)1 PratilipiFilter (com.pratilipi.common.util.PratilipiFilter)1