/**
  * Valorizza un nodo in base alle informazioni specificate..
  *
  * @param nodeToValue Il nodo da valorizzare.
  * @param parent Il nodo parente.
  * @param realNode Il nodo dal quela estrarre le info.
  */
 protected void fillTreeNode(TreeNode nodeToValue, TreeNode parent, ITreeNode realNode) {
   nodeToValue.setCode(realNode.getCode());
   if (null == parent) {
     nodeToValue.setParent(nodeToValue);
   } else {
     nodeToValue.setParent(parent);
   }
   Set<Object> codes = realNode.getTitles().keySet();
   Iterator<Object> iterKey = codes.iterator();
   while (iterKey.hasNext()) {
     String key = (String) iterKey.next();
     String title = realNode.getTitles().getProperty(key);
     nodeToValue.getTitles().put(key, title);
   }
 }
 private void addTreeWrapper(TreeNode currentNode, TreeNode parent, ITreeNode currentTreeNode) {
   ITreeNode[] children = currentTreeNode.getChildren();
   for (int i = 0; i < children.length; i++) {
     ITreeNode newCurrentTreeNode = children[i];
     TreeNode newNode = new TreeNode();
     this.fillTreeNode(newNode, currentNode, newCurrentTreeNode);
     currentNode.addChild(newNode);
     this.addTreeWrapper(newNode, currentNode, newCurrentTreeNode);
   }
 }
 protected Query createQuery(
     SearchEngineFilter[] filters,
     Collection<ITreeNode> categories,
     Collection<String> allowedGroups) {
   BooleanQuery mainQuery = new BooleanQuery();
   if (filters != null && filters.length > 0) {
     for (int i = 0; i < filters.length; i++) {
       SearchEngineFilter filter = filters[i];
       Query fieldQuery = this.createQuery(filter);
       mainQuery.add(fieldQuery, BooleanClause.Occur.MUST);
     }
   }
   if (allowedGroups == null) {
     allowedGroups = new HashSet<String>();
   }
   if (!allowedGroups.contains(Group.ADMINS_GROUP_NAME)) {
     if (!allowedGroups.contains(Group.FREE_GROUP_NAME)) {
       allowedGroups.add(Group.FREE_GROUP_NAME);
     }
     BooleanQuery groupsQuery = new BooleanQuery();
     Iterator<String> iterGroups = allowedGroups.iterator();
     while (iterGroups.hasNext()) {
       String group = iterGroups.next();
       TermQuery groupQuery = new TermQuery(new Term(IIndexerDAO.CONTENT_GROUP_FIELD_NAME, group));
       groupsQuery.add(groupQuery, BooleanClause.Occur.SHOULD);
     }
     mainQuery.add(groupsQuery, BooleanClause.Occur.MUST);
   }
   if (null != categories && !categories.isEmpty()) {
     BooleanQuery categoriesQuery = new BooleanQuery();
     Iterator<ITreeNode> cateIter = categories.iterator();
     while (cateIter.hasNext()) {
       ITreeNode category = cateIter.next();
       String path = category.getPath(IIndexerDAO.CONTENT_CATEGORY_SEPARATOR, false);
       TermQuery categoryQuery =
           new TermQuery(new Term(IIndexerDAO.CONTENT_CATEGORY_FIELD_NAME, path));
       categoriesQuery.add(categoryQuery, BooleanClause.Occur.MUST);
     }
     mainQuery.add(categoriesQuery, BooleanClause.Occur.MUST);
   }
   return mainQuery;
 }
 @Override
 public Set<String> checkTargetNodesOnClosing(
     String nodeToCloseCode, Set<String> lastOpenedNodes, Collection<String> groupCodes)
     throws ApsSystemException {
   ITreeNode nodeToClose = this.getTreeNode(nodeToCloseCode);
   if (null == nodeToCloseCode || null == nodeToClose) {
     return this.checkTargetNodes(null, lastOpenedNodes, groupCodes);
   }
   Set<String> checkedTargetNodes = new HashSet<String>();
   try {
     if (nodeToClose.isRoot()) {
       return checkedTargetNodes;
     }
     if (null != lastOpenedNodes) {
       Iterator<String> iter = lastOpenedNodes.iterator();
       while (iter.hasNext()) {
         String code = (String) iter.next();
         if (null != code
             && this.checkNode(code, groupCodes)
             && !code.equals(nodeToCloseCode)
             && !this.getTreeNode(code).isChildOf(nodeToCloseCode)) {
           checkedTargetNodes.add(code);
         }
       }
     }
     if (null != nodeToClose
         && null != nodeToClose.getParent()
         && this.checkNode(nodeToClose.getParent().getCode(), groupCodes)) {
       checkedTargetNodes.add(nodeToClose.getParent().getCode());
     }
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "checkTargetNodesOnClosing");
     throw new ApsSystemException("Error check target nodes on closing tree", t);
   }
   return checkedTargetNodes;
 }
 protected void buildCheckNodes(
     ITreeNode treeNode, Set<String> checkNodes, Collection<String> groupCodes) {
   checkNodes.add(treeNode.getCode());
   ITreeNode parent = treeNode.getParent();
   if (parent != null
       && parent.getParent() != null
       && !parent.getCode().equals(treeNode.getCode())) {
     this.buildCheckNodes(parent, checkNodes, groupCodes);
   }
 }
 private void builShowableTree(
     TreeNodeWrapper currentNode,
     TreeNodeWrapper parent,
     ITreeNode currentTreeNode,
     Set<String> checkNodes) {
   if (checkNodes.contains(currentNode.getCode())) {
     currentNode.setOpen(true);
     ITreeNode[] children = currentTreeNode.getChildren();
     for (int i = 0; i < children.length; i++) {
       ITreeNode newCurrentTreeNode = children[i];
       TreeNodeWrapper newNode = new TreeNodeWrapper(newCurrentTreeNode);
       newNode.setParent(currentNode);
       currentNode.addChild(newNode);
       this.builShowableTree(newNode, currentNode, newCurrentTreeNode, checkNodes);
     }
   }
 }