Beispiel #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));
  }
  public ActionForward executeAction(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    ISicresServicioRPAdmin oServicio = new ISicresServicioRPAdminAdapter();

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

    String id = request.getParameter("idSelect");
    String isNodoSelected = request.getParameter("nodoSelected");
    String idUnidadSeleccionada = (String) request.getSession(false).getAttribute("idUnidad");
    try {
      // Tipo departamento
      if (isLdapMethod(entidad.getIdentificador())) {
        String nodeDn = null;
        ServiceTree serviceTree =
            (ServiceTree)
                request.getSession(false).getAttribute(Constantes.LDAP_SERVICE_GROUP_TREE);

        if (serviceTree != null) {
          boolean enc = serviceTree.searchNode(serviceTree.getTree(), Integer.parseInt(id));
          if (enc) {
            NodeImplLDAP nodo = (NodeImplLDAP) serviceTree.fin.getRoot();
            nodeDn = nodo.getCodigo(); // Sacar el dn a partir del id del árbol
          } else {
            // TODO OMAR Cambiar esta excepción
            throw new ISicresRPAdminException("No se ha encontrado el nodo en el árbol");
          }
        } else {
          // TODO OMAR Cambiar esta excepción
          throw new ISicresRPAdminException("No se ha encontrado el árbol en sesión");
        }
        int maxChildrenLdap =
            ((Integer)
                    request
                        .getSession()
                        .getServletContext()
                        .getAttribute(Constantes.MAX_CHILDREN_LDAP))
                .intValue();
        oServicio.importarGruposLdap(
            nodeDn,
            maxChildrenLdap,
            LdapConstants.LDAP_TYPE_TREE_GROUP,
            Boolean.valueOf(isNodoSelected).booleanValue(),
            idUnidadSeleccionada,
            entidad);
      } else
        oServicio.importarDepartamentos(
            Integer.parseInt(id),
            Boolean.valueOf(isNodoSelected).booleanValue(),
            idUnidadSeleccionada,
            entidad);
    } catch (ISicresRPAdminException e) {
      logger.error("Error en la aplicación", e);
      ActionErrors errores = new ActionErrors();
      ActionError error = new ActionError("ieci.tecdoc.sgm.rpadmin.error.mensaje", e.getMessage());
      errores.add("Error interno", error);
      saveErrors(request, errores);
      return mapping.findForward("error");
    }
    return mapping.findForward("success");
  }