public void createNavigation(
      String type, String owner, String prefix, int startIndex, int endIndex) {
    if (startIndex < endIndex) {
      SiteKey key = new SiteKey(type, owner);
      NavigationContext navCtx = navService.loadNavigation(key);
      if (navCtx != null) {
        LOG.error("Navigation type= " + type + " , owner= " + owner + " already exists");
      } else {
        try {
          if (dataStorage.getPortalConfig(type, owner) == null) {
            dataStorage.create(new PortalConfig(type, owner));
          }
        } catch (Exception ex) {
          LOG.error("Error while load/create site ( type= " + type + " , owner = " + owner, ex);
        }

        navService.saveNavigation(new NavigationContext(key, new NavigationState(0)));
        navCtx = navService.loadNavigation(key);
        NavNode rootNode =
            navService.loadNode(new NavNodeModel(), navCtx, Scope.CHILDREN, null).getNode();
        for (int i = startIndex; i < endIndex; i++) {
          rootNode.addChild(i, prefix + "_" + i);
        }
        navService.saveNode(rootNode.context, null);
      }
    }
  }
  public void createNavigation(String type, String owner, List<String> children) {
    SiteKey key = new SiteKey(type, owner);
    NavigationContext navCtx = navService.loadNavigation(key);
    if (navCtx != null) {
      LOG.error("Navigation type= " + type + " , owner= " + owner + " already exists");
    } else {
      try {
        if (dataStorage.getPortalConfig(type, owner) == null) {
          dataStorage.create(new PortalConfig(type, owner));
        }
      } catch (Exception ex) {
        LOG.error("Error while load/create site ( type= " + type + " , owner = " + owner, ex);
      }

      navCtx = new NavigationContext(key, new NavigationState(0));
      NavNode rootNode =
          navService.loadNode(new NavNodeModel(), navCtx, Scope.CHILDREN, null).getNode();
      int index = 0;
      for (String child : children) {
        rootNode.addChild(index, child);
        index++;
      }
      navService.saveNode(rootNode.context, null);
    }
  }
 @Managed
 @ManagedDescription("Delete node specified by path in existing navigation")
 @Impact(ImpactType.READ)
 public void deleteNode(
     @ManagedDescription("Type of target navigation") @ManagedName("navType") String navType,
     @ManagedDescription("Owner of target navigation") @ManagedName("navOwner") String navOwner,
     @ManagedDescription("Path from root to target node") @ManagedName("pathFromRoot")
         String pathFromRoot) {
   try {
     startTransaction();
     NavigationContext ctx = navService.loadNavigation(new SiteKey(navType, navOwner));
     if (ctx == null) {
       LOG.error("Navigation type= " + navType + " , owner= " + navOwner + " does not exist");
     } else {
       String[] path = pathFromRoot.split("/");
       NavNode rootNode =
           navService
               .loadNode(new NavNodeModel(), ctx, GenericScope.branchShape(path), null)
               .getNode();
       NavNode targetNode = rootNode.getDescendant(path);
       if (targetNode != null && targetNode != rootNode) {
         targetNode.remove();
       }
     }
   } finally {
     endTransaction();
   }
 }
 public void addNodes(
     String navType, String navOwner, String nodePrefix, int startIndex, int endIndex) {
   if (startIndex < endIndex) {
     SiteKey key = new SiteKey(navType, navOwner);
     NavigationContext navCtx = navService.loadNavigation(key);
     if (navCtx == null) {
       LOG.error("Navigation type= " + navType + " , owner= " + navOwner + " does not exist");
     } else {
       NavNode rootNode =
           navService.loadNode(new NavNodeModel(), navCtx, Scope.CHILDREN, null).getNode();
       int index = rootNode.getSize();
       for (int i = startIndex; i < endIndex; i++) {
         String nodeName = nodePrefix + "_" + i;
         if (rootNode.getChild(nodeName) != null) {
           LOG.debug(
               "Navigation node named " + nodeName + " already exist, will not add it anymore");
         } else {
           rootNode.addChild(index, nodeName);
           index++;
         }
       }
       navService.saveNode(rootNode.context, null);
     }
   }
 }
 /**
  * @param navType
  * @param navOwner
  * @param absolutePath path from root to targeted node
  * @param nodePrefix
  * @param startIndex
  * @param endIndex
  */
 public void addNodes(
     String navType,
     String navOwner,
     String absolutePath,
     String nodePrefix,
     int startIndex,
     int endIndex) {
   SiteKey key = new SiteKey(navType, navOwner);
   NavigationContext navCtx = navService.loadNavigation(key);
   if (navCtx == null) {
     LOG.error("Navigation type= " + navType + " , owner= " + navOwner + " does not exist");
   } else {
     String[] path = absolutePath.split("/");
     NavNode rootNode =
         navService
             .loadNode(new NavNodeModel(), navCtx, GenericScope.branchShape(path), null)
             .getNode();
     NavNode targetNode = rootNode.getDescendant(path);
     if (targetNode == null) {
       LOG.error(
           "Could not find node specified by path "
               + absolutePath
               + " under navigation type= "
               + navType
               + " , owner= "
               + navOwner);
     } else {
       int index = targetNode.getSize();
       for (int i = startIndex; i < endIndex; i++) {
         String nodeName = nodePrefix + "_" + i;
         if (targetNode.getChild(nodeName) == null) {
           targetNode.addChild(index, nodeName);
           index++;
         }
       }
       navService.saveNode(targetNode.context, null);
     }
   }
 }