Пример #1
0
  protected void loadTree(
      HttpServletRequest request, String cteTree, String cteServiceTree, String start, int treeType)
      throws Exception {

    // Se obtiene la entidad
    Entidad entidad = new Entidad();
    entidad.setIdentificador(MultiEntityContextHolder.getEntity());

    String id = request.getParameter("id");

    boolean borraCookies = false;

    ServiceTree serviceTree = null;
    NaryTree tree;
    if (id == null) {
      LdapConnection ldapConn = new LdapConnection();

      // Obtener la información del servidor
      LdapConnCfg connCfg = UasConfigUtilLdap.createLdapConnConfig(entidad.getIdentificador());
      ldapConn.open(connCfg);

      // Obtener la ruta de búsqueda
      String startNode = start;

      // Obtener el rootDn
      LdapURL Ldap_url = new LdapURL(ldapConn.getUrl());
      String ldapRootDn = Ldap_url.getDN();
      String ldapRootGroupStartDn = Ldap_url.getDN();

      // Si el comienzo de grupos es distinto del rootDn cambiarlo
      if ((startNode != null) && (!"".equals(startNode))) {
        ldapRootGroupStartDn = startNode + "," + ldapRootGroupStartDn;
      }

      NodeImplLDAP nodoRaiz = new NodeImplLDAP();
      tree = new NaryTree(null, nodoRaiz);
      int maxChildrenLdap =
          ((Integer)
                  request
                      .getSession()
                      .getServletContext()
                      .getAttribute(Constantes.MAX_CHILDREN_LDAP))
              .intValue();

      serviceTree = new ServiceTreeLdap(tree, maxChildrenLdap, ldapRootDn, treeType);
      request.getSession(false).setAttribute(cteServiceTree, serviceTree);

      nodoRaiz.setCodigo(ldapRootGroupStartDn);

      // Obtener el objectClass del nodo raíz y establecer si es válido para seleccionar o no
      IeciTdShortTextArrayList arrayList =
          LdapBasicFns.findEntryAttributeValues(
              ldapConn, ldapRootGroupStartDn, LdapAttribute.getObjectClassAttributeName(ldapConn));
      nodoRaiz.setValidForSelection(
          ServiceTreeLdap.isValidForSelection(arrayList, ldapConn, treeType));
      nodoRaiz.setTitle(ServiceTreeLdap.getLdapTitle(ldapRootGroupStartDn));

      int hashCode = serviceTree.getHashCode(ldapRootGroupStartDn);
      nodoRaiz.setId(hashCode);
      LdapService ldapService = new LdapService(maxChildrenLdap, ldapRootDn, treeType);

      boolean hasChildren =
          ldapService.hasChildLdap(ldapRootGroupStartDn, entidad.getIdentificador());
      nodoRaiz.setHasChild(hasChildren);

      // Añadir los hijos al árbol
      serviceTree.addChildren(hashCode, null, entidad, 0, false);
      request.getSession(false).setAttribute(cteTree, tree);

      borraCookies = true;

    } else {

      // Obtener un nodo ya cargado y añadirle sus hijos
      tree = (NaryTree) request.getSession(false).getAttribute(cteTree);
      if (tree == null) {
        logger.error("La estructura de Arbol deberia estar en memoria");
        throw new Exception("La estructura de Arbol deberia estar en memoria");
      }

      serviceTree = (ServiceTree) request.getSession(false).getAttribute(cteServiceTree);

      serviceTree.addChildren(Integer.parseInt(id), null, entidad, 0, false);
    }

    String arbol =
        serviceTree.getTreeString(0, false, LocaleFilterHelper.getCurrentLocale(request));
    request.setAttribute(Constantes.TREE_STRING, arbol);
    Boolean b = new Boolean(borraCookies);

    request.setAttribute(Constantes.BORRA_COOKIES, b);
    request.setAttribute(Constantes.TYPE_TREE, String.valueOf(treeType));
  }