import org.exoplatform.portal.mop.navigation.GenericScope; import org.exoplatform.portal.mop.navigation.Scope; import org.exoplatform.portal.mop.user.UserNavigation; import org.exoplatform.portal.mop.user.UserNode; import org.exoplatform.portal.mop.user.UserNodeFilterConfig; import org.exoplatform.portal.mop.user.UserPortal; import org.exoplatform.portal.mop.SiteType; import org.exoplatform.portal.mop.Visibility; import org.exoplatform.portal.webui.portal.UIPortal; import org.exoplatform.portal.webui.util.Util; import org.exoplatform.webui.application.WebuiRequestContext; public class PortalNavigation{ private final UserNodeFilterConfig NAVIGATION_FILTER_CONFIG; private static final int DEFAULT_LEVEL = 2; private Scope scope; public PortalNavigationImpl() { UserNodeFilterConfig.Builder filterConfigBuilder = UserNodeFilterConfig.builder(); filterConfigBuilder.withReadWriteCheck().withVisibility(Visibility.DISPLAYED, new Visibility[] { Visibility.TEMPORAL }); filterConfigBuilder.withTemporalCheck(); this.NAVIGATION_FILTER_CONFIG = filterConfigBuilder.build(); this.scope = GenericScope.treeShape(this.DEFAULT_LEVEL); } private UserNode getCurrentNavigation() throws SucursalVirtualException { UserNode rootNode = null; UserPortal userPortal = null; try { userPortal = Util.getPortalRequestContext().getUserPortalConfig().getUserPortal(); UserNavigation userNavigation = Util.getUIPortal().getUserNavigation(); rootNode = userPortal.getNode(userNavigation, this.scope, this.NAVIGATION_FILTER_CONFIG, null); } catch (Exception ex){ e.printStackTrace(); } return rootNode; } public UserNode getSelectedNode() throws SucursalVirtualException { UIPortal uiPortal = Util.getUIPortal(); if (uiPortal != null){ try { return uiPortal.getSelectedUserNode(); } catch (Exception e) { e.printStackTrace(); } } return null; } public List<UserNode> getNavigations() throws SucursalVirtualException { WebuiRequestContext context = (WebuiRequestContext)WebuiRequestContext.getCurrentInstance(); List<UserNode> nodes = new ArrayList<UserNode>(); UserPortal userPortal; if (context.getRemoteUser() != null) { UserNode currRootNode = getCurrentNavigation(); if (currRootNode != null) { nodes.add(currRootNode); } } else { userPortal = Util.getPortalRequestContext().getUserPortalConfig().getUserPortal(); List<UserNavigation> navigations = userPortal.getNavigations(); for (UserNavigation userNav : navigations) { if ( (userNav.getKey().getType().equals(SiteType.USER))) { continue; } UserNode rootNode = userPortal.getNode(userNav, this.scope, this.NAVIGATION_FILTER_CONFIG, null); if (rootNode != null) { nodes.add(rootNode); } } } return nodes; } public Scope getScope() { return scope; } public void setScope(Scope scope) { this.scope = scope; } }
Comments