Ejemplo n.º 1
0
  /**
   * Busca un documento o directorio en Alfresco
   *
   * @param space Referencia al espacio donde se buscara el elemento, si es null se buscará en
   *     /app:company_home (Raiz del repositorio de alfresco)
   * @param contentName Nombre del Contenido o directorio en Alfresco
   * @return Referencia al directorio o contenido, null si no se encuentra
   */
  public static Reference getContentReference(Reference space, String contentName) {
    // Se obtiene la referencia al directorio padre
    Reference parentReference;
    if (space != null) parentReference = ReferenceToParent(space);
    else parentReference = getCompanyHome();

    QueryResult queryResult = null;
    try {
      queryResult = WebServiceFactory.getRepositoryService().queryChildren(parentReference);
    } catch (Exception ex) {
      LOGGER.log(
          Level.SEVERE, "Error: no se puede acceder al espacio " + parentReference.getPath());
      return null;
    }
    ResultSet resultSet = queryResult.getResultSet();
    if (resultSet.getTotalRowCount() > 0) {
      // LOGGER.log(Level.INFO, "Encontradas {" + resultSet.getTotalRowCount() + "} referencias a "
      // + contentName + "} en {" + space.getPath() + "}");
      ResultSetRow[] rows = resultSet.getRows();

      // Recorriendo
      for (int x = 0; x < rows.length; x++) {
        ResultSetRowNode node = rows[x].getNode();
        Reference ref1 = new Reference(STOREREF, node.getId(), null);
        Query query = null;
        Node[] noderesult = null;
        try {
          noderesult =
              WebServiceFactory.getRepositoryService()
                  .get(new Predicate(new Reference[] {ref1}, STOREREF, query));
          if (noderesult != null) {
            for (Node rowi : noderesult) {
              NamedValue[] columns1 = rowi.getProperties();
              for (int y1 = 0; y1 < columns1.length; y1++) {
                if (rowi.getProperties(y1).getName().endsWith(Constants.PROP_NAME)) {
                  if (rowi.getProperties(y1).getValue().equals(contentName)) {
                    return rowi.getReference();
                  }
                }
              }
            }
          }
        } catch (Exception ex1) {
          LOGGER.log(Level.INFO, "No hay referencias al nodo {" + contentName + "}");
        }
      }
    } else {
      LOGGER.log(
          Level.SEVERE,
          "Error: Encontradas {"
              + resultSet.getTotalRowCount()
              + "} referencias a {"
              + contentName
              + "} en {"
              + parentReference.getPath()
              + "} (No hay una única referencia al nodo)");
    }
    return null;
  }
Ejemplo n.º 2
0
  /**
   * {@inheritDoc}
   *
   * @see org.prowim.dms.alfresco.ContentService#findFolderOrContent(String)
   */
  @Override
  @Interceptors(AuthenticationInterceptor.class)
  public String findFolderOrContent(String contentName) {
    Validate.notNull(contentName, "The name of content or a folder can not be null");

    String idReference = null;
    RepositoryServiceSoapBindingStub repoService = WebServiceFactory.getRepositoryService();
    try {
      QueryResult results =
          repoService.queryChildren(
              new Reference(DMSStoreRegistry.STORE_REF, DMSConstants.getCustomerFolderID(), null));
      ResultSetRow[] rows = results.getResultSet().getRows();
      ResultSetRow currentRow;
      NamedValue[] colums;
      String currentName;
      String currentValue;
      if (rows != null) {
        for (int i = 0; i < rows.length; i++) {
          currentRow = rows[i];
          colums = currentRow.getColumns();
          for (int y = 0; y < colums.length; y++) {
            currentName = colums[y].getName();
            if (currentName.equals(Constants.PROP_NAME)) {
              currentValue = colums[y].getValue();
              if (currentValue.equals(contentName)) {
                idReference = currentRow.getNode().getId();
              }
            }
          }
        }
      }
    } catch (RepositoryFault e) {
      LOG.error("RepositoryFault-Error by search a item in DMS", e);
    } catch (RemoteException e) {
      LOG.error("RemoteException-Error by search a item in DMS", e);
    }
    return idReference;
  }