/**
   * 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;
  }
Example #2
0
 /**
  * {@inheritDoc}
  *
  * @see org.prowim.dms.alfresco.ContentService#deleteContent(java.lang.String)
  */
 @Interceptors(AuthenticationInterceptor.class)
 public void deleteContent(String uuid) throws DMSException {
   Validate.notNull(uuid);
   this.getContentService();
   final Reference reference = new Reference(DMSStoreRegistry.STORE_REF, uuid, null);
   final Predicate predicate = new Predicate(new Reference[] {reference}, null, null);
   final CMLDelete delete = new CMLDelete(predicate);
   final CML cml = new CML();
   cml.setDelete(new CMLDelete[] {delete});
   try {
     WebServiceFactory.getRepositoryService().update(cml);
   } catch (RepositoryFault e) {
     String message = "Could not delete content: ";
     LOG.error(message, e);
     DMSFault dmsFault = new DMSFault();
     dmsFault.setMessage(message);
     throw new DMSException(message, dmsFault, e.getCause());
   } catch (RemoteException e) {
     String message = "Could not create connection: ";
     LOG.error(message, e);
     DMSFault dmsFault = new DMSFault();
     dmsFault.setMessage(message);
     throw new DMSException(message, dmsFault, e.getCause());
   }
 }
 /**
  * Muestra los store de alfresco por la salida estandar
  *
  * @return
  * @throws
  */
 public static void getStores() {
   RepositoryServiceSoapBindingStub repoService = WebServiceFactory.getRepositoryService();
   Store[] stores;
   try {
     stores = repoService.getStores();
     for (Store s : stores) {
       System.out.println(s.getScheme() + "://" + s.getAddress());
     }
   } catch (RepositoryFault e) {
     e.printStackTrace();
   } catch (RemoteException e) {
     e.printStackTrace();
   }
 }
Example #4
0
  /**
   * {@inheritDoc}
   *
   * @see org.prowim.dms.alfresco.ContentService#createNewVersion(java.lang.String,
   *     java.lang.String, java.lang.String)
   */
  @Interceptors(AuthenticationInterceptor.class)
  public VersionResult createNewVersion(String name, String username, String uuid)
      throws OntologyErrorException, DMSException {
    // get the user
    String userID = organizationEntity.getUser(username).getID();

    AuthoringServiceSoapBindingStub authoringService = WebServiceFactory.getAuthoringService();
    final Reference reference = new Reference(DMSStoreRegistry.STORE_REF, uuid, null);
    final Predicate predicate = new Predicate(new Reference[] {reference}, null, null);
    NamedValue[] comments =
        new NamedValue[] {
          Utils.createNamedValue("description", "User description"),
          Utils.createNamedValue("versionType", "MINOR"),
          Utils.createNamedValue(DMSConstants.Content.AUTHOR_PROP, userID)
        };
    VersionResult vr;
    try {
      vr = authoringService.createVersion(predicate, comments, true);
      String descriptionNew = "This is a sample description for " + name;
      Predicate pred = new Predicate(vr.getNodes(), null, null);

      NamedValue[] titledProps = new NamedValue[2];
      titledProps[0] = Utils.createNamedValue(Constants.PROP_NAME, name);
      titledProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, descriptionNew);

      CMLUpdate update = new CMLUpdate(titledProps, pred, null);
      CML cml = new CML();
      cml.setUpdate(new CMLUpdate[] {update});

      WebServiceFactory.getRepositoryService().update(cml);

      return vr;
    } catch (AuthoringFault e) {
      LOG.error(
          "Could not create new version in DMS for user " + username + " and UUID " + uuid, e);
    } catch (RemoteException e) {
      LOG.error(
          "Could not create new version in DMS for user " + username + " and UUID " + uuid, e);
    }

    return null;
  }
Example #5
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;
  }