Example usage for com.liferay.portal.kernel.util PortalUtil getHttpServletResponse

List of usage examples for com.liferay.portal.kernel.util PortalUtil getHttpServletResponse

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PortalUtil getHttpServletResponse.

Prototype

public static HttpServletResponse getHttpServletResponse(PortletResponse portletResponse) 

Source Link

Usage

From source file:se.vgregion.portal.innovationsslussen.idea.controller.IdeaViewController.java

License:Open Source License

/**
 * The default render method.//from w ww .ja  v  a2 s. c o m
 *
 * @param request  the request
 * @param response the response
 * @param model    the model
 * @return the view
 */
@RenderMapping()
public String showIdea(RenderRequest request, RenderResponse response, final ModelMap model)
        throws PortalException, SystemException {

    ThemeDisplay themeDisplay = getThemeDisplay(request);
    String ideaType = ParamUtil.getString(request, "type", "public");

    String returnView = "view_public";

    //If a user trying to accsess the private part of an idea when not sign in.
    if (ideaType.equals("private") && !themeDisplay.isSignedIn()) {
        returnView = "idea_not_sign_in";
    } else {

        long scopeGroupId = themeDisplay.getScopeGroupId();
        long companyId = themeDisplay.getCompanyId();
        long userId = themeDisplay.getUserId();
        boolean isSignedIn = themeDisplay.isSignedIn();
        String urlTitle = ParamUtil.getString(request, "urlTitle", "");

        Layout ideaLayout = getFriendlyURLLayout(scopeGroupId, themeDisplay.getLayout().isPrivateLayout());
        long ideaPlid = ideaLayout.getPlid();
        model.addAttribute("ideaPlid", ideaPlid);

        int maxCommentCountDisplay = ParamUtil.getInteger(request, "maxCommentCountDisplay",
                defaultCommentCount);
        boolean moreComments = ParamUtil.getString(request, "moreComments") != null;
        if (moreComments) {
            maxCommentCountDisplay += defaultCommentCount;
        }

        if (!urlTitle.equals("")) {
            Idea idea = ideaService.findIdeaByUrlTitle(urlTitle);
            if (idea != null) {

                boolean isIdeaUserLiked = ideaService.getIsIdeaUserLiked(companyId, scopeGroupId, userId,
                        urlTitle);
                boolean isIdeaUserFavorite = ideaService.getIsIdeaUserFavorite(companyId, scopeGroupId, userId,
                        urlTitle);

                List<CommentItemVO> commentsList = null;

                if (ideaType.equals("private")) {
                    commentsList = ideaService.getPrivateComments(idea);
                } else {
                    commentsList = ideaService.getPublicComments(idea);
                }

                if (idea.getIdeaContentPrivate() != null) {
                    String ideTansportor = idea.getIdeaContentPrivate().getIdeTansportor();
                    if (ideTansportor != null && !ideTansportor.isEmpty()) {
                        model.addAttribute("tansportor", ideTansportor);
                    }
                }

                IdeaPermissionChecker ideaPermissionChecker = ideaPermissionCheckerService
                        .getIdeaPermissionChecker(scopeGroupId, userId, idea);

                model.addAttribute("commentCount", commentsList.size());
                commentsList = commentsList.subList(0, Math.min(maxCommentCountDisplay, commentsList.size()));

                idea = IdeaPortletUtil.replaceBreaklines(idea);

                model.addAttribute("idea", idea);
                model.addAttribute("commentsList", commentsList);
                model.addAttribute("commentsDelta", 1);
                model.addAttribute("isIdeaUserFavorite", isIdeaUserFavorite);
                model.addAttribute("isIdeaUserLiked", isIdeaUserLiked);
                model.addAttribute("urlTitle", urlTitle);
                model.addAttribute("userId", userId);

                model.addAttribute("isSignedIn", isSignedIn);
                model.addAttribute("ideaPermissionChecker", ideaPermissionChecker);

                model.addAttribute("ideaType", ideaType);

                model.addAttribute("maxCommentCountDisplay", maxCommentCountDisplay);
                model.addAttribute("defaultCommentCount", defaultCommentCount);

                model.addAttribute("ideaPortletName", IdeaPortletsConstants.PORTLET_NAME_IDEA_PORTLET);

                model.addAttribute("bariumUrl", bariumUrl);

                if (ideaType.equals("private") && (ideaPermissionChecker.getHasPermissionViewIdeaPrivate()
                        || idea.getUserId() == userId)) {
                    returnView = "view_private";
                }

                // If a user trying to access the public or private part of an idea that still is private.
                // The user dose not have premmisions and is not the creator of the idea.
                // Showing 404 view.
                if (!idea.isPublic() && !(ideaPermissionChecker.getHasPermissionViewIdeaPrivate()
                        || idea.getUserId() == userId)) {
                    HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(response);
                    httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
                    returnView = "idea_404";
                }
            } else {
                HttpServletResponse httpServletResponse = getHttpServletResponse(response);
                httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
                returnView = "idea_404";
            }
        }
    }
    return returnView;
}

From source file:se.vgregion.portal.innovationsslussen.idea.controller.IdeaViewController.java

License:Open Source License

protected HttpServletResponse getHttpServletResponse(RenderResponse response) {
    return PortalUtil.getHttpServletResponse(response);
}