List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getLayout
public Layout getLayout()
From source file:com.liferay.wiki.web.internal.portlet.action.ActionUtil.java
License:Open Source License
public static WikiNode getFirstVisibleNode(PortletRequest portletRequest) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); WikiNode node = null;//from w w w. j a v a 2 s . c om int nodesCount = WikiNodeLocalServiceUtil.getNodesCount(themeDisplay.getScopeGroupId()); if (nodesCount == 0) { Layout layout = themeDisplay.getLayout(); ServiceContext serviceContext = ServiceContextFactory.getInstance(WikiNode.class.getName(), portletRequest); serviceContext.setAddGroupPermissions(true); if (layout.isPublicLayout() || layout.isTypeControlPanel()) { serviceContext.setAddGuestPermissions(true); } else { serviceContext.setAddGuestPermissions(false); } node = WikiNodeLocalServiceUtil.addDefaultNode(themeDisplay.getDefaultUserId(), serviceContext); } else { node = getFirstNode(portletRequest); if (node == null) { throw new PrincipalException(); } return node; } return node; }
From source file:com.liferay.wiki.web.internal.portlet.action.EditNodeMVCActionCommand.java
License:Open Source License
protected WikiPortletInstanceOverriddenConfiguration getWikiPortletInstanceOverriddenConfiguration( ActionRequest actionRequest) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); WikiPortletInstanceOverriddenConfiguration wikiPortletInstanceOverriddenConfiguration = ConfigurationProviderUtil .getConfiguration(WikiPortletInstanceOverriddenConfiguration.class, new PortletInstanceSettingsLocator(themeDisplay.getLayout(), portletDisplay.getId())); return wikiPortletInstanceOverriddenConfiguration; }
From source file:com.liferay.wiki.web.internal.portlet.action.EditPageMVCActionCommand.java
License:Open Source License
protected String getSaveAndContinueRedirect(ActionRequest actionRequest, ActionResponse actionResponse, WikiPage page, String redirect) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Layout layout = themeDisplay.getLayout(); PortletURLImpl portletURL = new StrutsActionPortletURL((PortletResponseImpl) actionResponse, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setParameter("mvcRenderCommandName", "/wiki/edit_page"); portletURL.setParameter(Constants.CMD, Constants.UPDATE, false); portletURL.setParameter("redirect", redirect, false); portletURL.setParameter("groupId", String.valueOf(layout.getGroupId()), false); portletURL.setParameter("nodeId", String.valueOf(page.getNodeId()), false); portletURL.setParameter("title", page.getTitle(), false); portletURL.setWindowState(actionRequest.getWindowState()); return portletURL.toString(); }
From source file:se.vgregion.portal.innovationsslussen.createidea.controller.CreateIdeaViewController.java
License:Open Source License
protected Layout getFriendlyURLLayout(long scopeGroupId, ThemeDisplay themeDisplay) throws SystemException, PortalException { return LayoutLocalServiceUtil.getFriendlyURLLayout(scopeGroupId, themeDisplay.getLayout().isPrivateLayout(), "/ide"); }
From source file:se.vgregion.portal.innovationsslussen.idea.controller.IdeaViewController.java
License:Open Source License
/** * The default render method.//from w w w . j a v a 2 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.IdeaViewControllerTest.java
License:Open Source License
@Before public void setUp() { ideaService = Mockito.mock(IdeaService.class); ideaPermissionCheckerService = Mockito.mock(IdeaPermissionCheckerService.class); ideaSettingsService = Mockito.mock(IdeaSettingsService.class); controller = new IdeaViewController(ideaService, ideaPermissionCheckerService, ideaSettingsService) { @Override//from w ww . j av a2 s. c om protected HttpServletResponse getHttpServletResponse(RenderResponse response) { return Mockito.mock(HttpServletResponse.class); } @Override protected Layout getFriendlyURLLayout(long scopeGroupId, boolean priv) throws SystemException, PortalException { return Mockito.mock(Layout.class); } }; request = Mockito.mock(RenderRequest.class); response = Mockito.mock(RenderResponse.class); actionRequest = Mockito.mock(ActionRequest.class); actionResponse = Mockito.mock(ActionResponse.class); modelMap = Mockito.mock(ModelMap.class); ThemeDisplay themeDisplay = Mockito.mock(ThemeDisplay.class); Mockito.when(request.getAttribute(WebKeys.THEME_DISPLAY)).thenReturn(themeDisplay); Mockito.when(actionRequest.getAttribute(WebKeys.THEME_DISPLAY)).thenReturn(themeDisplay); Mockito.when(themeDisplay.getScopeGroupId()).thenReturn(1l); User user = Mockito.mock(User.class); Mockito.when(themeDisplay.getUser()).thenReturn(user); Mockito.when(themeDisplay.getUserId()).thenReturn(1l); Layout layout = Mockito.mock(Layout.class); Mockito.when(layout.isPrivateLayout()).thenReturn(true); Mockito.when(themeDisplay.getLayout()).thenReturn(layout); }
From source file:se.vgregion.portal.innovationsslussen.idealist.controller.IdeaListViewController.java
License:Open Source License
/** * The default render method.//from www . ja v a 2s . co m * * @param request the request * @param response the response * @param model the model * @return the view */ @RenderMapping() public String showIdeaList(RenderRequest request, RenderResponse response, final ModelMap model) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long scopeGroupId = themeDisplay.getScopeGroupId(); long companyId = themeDisplay.getCompanyId(); long userId = themeDisplay.getUserId(); boolean isSignedIn = themeDisplay.isSignedIn(); String returnView = "view_open_ideas"; try { PortletPreferences prefs = request.getPreferences(); String ideaListType = prefs.getValue("ideaListType", "0"); int entryCount = Integer.valueOf(prefs.getValue("entryCount", "6")); Layout ideaLayout = getFriendlyURLLayout(scopeGroupId, themeDisplay.getLayout().isPrivateLayout()); long ideaPlid = ideaLayout.getPlid(); List<Idea> ideasFromService = new ArrayList<Idea>(); List<Idea> ideaList = new ArrayList<Idea>(); int currentPage = ParamUtil.getInteger(request, "pageNumber", PageIteratorConstants.PAGINATOR_START_DEFAULT); int ideaPhase = ParamUtil.getInteger(request, "ideaPhase", 0); int ideaVisible = ParamUtil.getInteger(request, "ideaVisible", 1); int ideaSort = ParamUtil.getInteger(request, "ideaSort", 0); String transporter = ParamUtil.getString(request, "transporter", "0"); int maxPages = PageIteratorConstants.MAX_PAGES_DEFAULT; long totalCount = 0; int start = (currentPage - 1) * entryCount; if (ideaListType.equals(IdeaPortletsConstants.IDEA_LIST_PORTLET_VIEW_OPEN_IDEAS)) { Map<String, Object> map = searchService.getPublicVisibleIdeas(companyId, scopeGroupId, start, entryCount, ideaSort, ideaPhase); ideasFromService = (List<Idea>) map.get("ideas"); totalCount = (Long) map.get("totalIdeasCount"); } else if (ideaListType.equals(IdeaPortletsConstants.IDEA_LIST_PORTLET_VIEW_USER_IDEAS)) { if (isSignedIn) { ideasFromService = ideaService.findIdeasByGroupIdAndUserId(companyId, scopeGroupId, userId, start, entryCount); totalCount = ideaService.findIdeasCountByGroupIdAndUserId(companyId, scopeGroupId, userId); } returnView = "view_user_ideas"; } else if (ideaListType.equals(IdeaPortletsConstants.IDEA_LIST_PORTLET_VIEW_USER_FAVORITED_IDEAS)) { if (isSignedIn) { ideasFromService = ideaService.findVisibleUserFavoritedIdeas(companyId, scopeGroupId, userId, start, entryCount); totalCount = ideaService.findVisibleUserFavoritedIdeasCount(companyId, scopeGroupId, userId); } returnView = "view_user_favorites"; } else if (ideaListType.equals(IdeaPortletsConstants.IDEA_LIST_PORTLET_VIEW_CLOSED_IDEAS)) { if (isSignedIn) { ideasFromService = ideaService.findVisibleIdeasByGroupId(companyId, scopeGroupId, IdeaStatus.PRIVATE_IDEA, start, entryCount); totalCount = ideaService.findVisibleIdeaCountByGroupId(companyId, scopeGroupId, IdeaStatus.PRIVATE_IDEA); } returnView = "view_closed_ideas"; } else if (ideaListType .equals(IdeaPortletsConstants.IDEA_LIST_PORTLET_VIEW_IDEAS_FOR_IDEATRANSPORTER)) { Map<String, Object> map = searchService.getVisibleIdeasForIdeaTransporters(companyId, scopeGroupId, start, entryCount, ideaSort, ideaPhase, ideaVisible, transporter); ideasFromService = (List<Idea>) map.get("ideas"); totalCount = (Long) map.get("totalIdeasCount"); // Collect all Idea transporters setIdeaTransporters(model, scopeGroupId, companyId, entryCount, start, ideaVisible); returnView = "view_transporter_ideas"; } for (Idea idea : ideasFromService) { /*int commentsCount = 0; if (idea.isPublic()) { commentsCount = ideaService.getPublicCommentsCount(idea); } else { commentsCount = ideaService.getPrivateCommentsCount(idea); } idea.setCommentsCount(commentsCount);*/ ideaList.add(idea); } PageIterator pageIterator = new PageIterator(totalCount, currentPage, entryCount, maxPages); model.addAttribute("ideaPlid", ideaPlid); model.addAttribute("ideaPortletName", IdeaPortletsConstants.PORTLET_NAME_IDEA_PORTLET); model.addAttribute("ideaList", ideaList); model.addAttribute("ideaListType", ideaListType); model.addAttribute("ideaPhase", ideaPhase); model.addAttribute("ideaSort", ideaSort); model.addAttribute("ideaVisible", ideaVisible); model.addAttribute("transporter", transporter); model.addAttribute("isSignedIn", isSignedIn); model.addAttribute("pageIterator", pageIterator); } catch (PortalException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } return returnView; }