@Override
  public ServiceResponse<NavigationElementTree> perform(ServiceRequest<NamedValues> request)
      throws Exception {
    String lookup = (String) request.getData().get("lookup");
    boolean lazyLoadResource = (Boolean) request.getData().get("lazyLoadResource");

    List<NavigationElementTree> navigationElementTrees = new ArrayList<NavigationElementTree>();
    if (ConfigContainer.isAppInstalled() && StringUtils.isNotBlank(lookup)) {
      String packageLookup = StringUtils.getPackageLookup(lookup);
      if (packageLookup == null) {
        logger.warn(MSG_WRONG_LOOKUP);
      } else {
        OPFContext context = OPFContext.getContext();
        INavElementContainer navElementContainer = context.getNavElementContainer();
        List<NavigationElement> navElementListByPackage =
            navElementContainer.getNavElementListByPackage(packageLookup);
        if (navElementListByPackage == null || navElementListByPackage.isEmpty()) {
          logger.warn(MSG_APPROPRIATE_NAVIGATION_ELEMENTS_WERE_FOUND);
        } else {
          NavigationElementTree navigationElementTree = null;
          NavigationElement parent = null;
          for (NavigationElement vo : navElementListByPackage) {
            if (vo.getLookup().equalsIgnoreCase(lookup)) {
              parent = vo;
              navigationElementTree = convert(parent);
              break;
            }
          }
          if (parent == null) {
            logger.warn(MSG_NO_SUCH_PARENT_NAVIGATION_WAS_FOUND);
          } else {
            buildTree(navigationElementTree, parent, navElementListByPackage, lazyLoadResource);
            navigationElementTrees = navigationElementTree.getChildren();
          }
        }
      }
    }
    return new ServiceResponse<NavigationElementTree>(
        navigationElementTrees, "Return tree navigation elements.", true);
  }
 private void buildTree(
     NavigationElementTree parentNavigationElementTree,
     NavigationElement parent,
     List<NavigationElement> navigationElementList,
     boolean lazyLoadResource) {
   List<NavigationElementTree> children = parentNavigationElementTree.getChildren();
   for (NavigationElement navigationElement : navigationElementList) {
     if (parent.getLookup().endsWith(navigationElement.getPath())) {
       OpenFlamePrincipal principal = OPFContext.getContext().getPrincipal();
       if (principal.checkUserPermission(navigationElement)) {
         if (!lazyLoadResource) {
           initResourceContents(navigationElement);
         }
         NavigationElementTree navigationElementTree = convert(navigationElement);
         children.add(navigationElementTree);
         buildTree(
             navigationElementTree, navigationElement, navigationElementList, lazyLoadResource);
       }
     }
   }
   Collections.sort(children, NavigationElementTree.SORT_POSITION);
 }