class NodeCheckingPortfolioFilter implements PortfolioFilter {

  @Override
  public Portfolio generateRestrictedPortfolio(Portfolio portfolio) {

    PortfolioPermissionChecker checker = new PortfolioPermissionChecker(portfolio, _nodeChecker);
    PortfolioNode rootNode = portfolio.getRootNode();

    Optional<? extends PortfolioNode> newRoot = buildRestrictedRootNode(checker, rootNode);

    if (newRoot.isPresent()) {
      PortfolioNode node = newRoot.get();
      return node.equals(rootNode) ? portfolio : createPortfolioForNode(trimParents(node));
    } else {
      return new SimplePortfolio("Access Denied");
    }
  }

  public  NodeCheckingPortfolioFilter(NodeChecker nodeChecker);

}