Ubuntu 9.10,JDK1.6,Eclipse(Galileo),Maven 2.2.1,Alfresco V3.3,AlFresco SDK v3.3

INSTALACION DE ALFRESCO
Primeramente instalaremos Alfresco-Community-3.3-Linux-x86-Install, para estos descargamos el instalador desde:
http://wiki.alfresco.com/wiki/Download_Community_Edition?utm_source=www.alfresco.com&utm_medium=banner&utm_campaign=Community Edition 3.3
Una vez descargado, abrimos una consola de comandos y ejecutamos:
Para dar los permisos
sudo chmod 775 Alfresco-Community-3.3-Linux-x86-Install
sudo chown tuusuario:users Alfresco-Community-3.3-Linux-x86-Install
Luego para iniciar la instalacion, ejecutamos:
./Alfresco-Community-3.3-Linux-x86-Install






Para mi caso Open Office esta instaldo en :/usr/lib/openoffice


Una vez instalado, tenemos que hacer startup de Alfresco, para esto desde una consola de comandos vamos al lugar de instalacion de Alfresco y ejecutamos el comando sh alf_start.sh
Luego de esto vamos a http://localhost:8080/alfresco
Esperamos un momento
si damos click en login o vamos http://localhost:8080/alfresco/faces/jsp/login.jsp
Ingresamos nuestro nombre de usuario y clave (admin/root) podremos ingresar al menu de opciones

Ahora vamos a crear un Space, para eso, damos click sobre company_home(si no aparece se puede hacer logout y login de nuevo)
Ahi damos click en Create y luego "Create Space"

Creamos el Space con la siguiente información:

CONFIGURACION DE JAVA PARA TRABAJAR CON ALFRESCO
Para crear contenido en Alfresco, tenemos que descargar el SDK de: http://sourceforge.net/projects/alfresco/files/SDK/3.3%20Community%20Edition/alfresco-community-sdk-3.3.tar.gz/download
Descomprimimos el archivo y tenemos que registrar dos librerias en el repositorio de maven(Estas librerias se encuentran en el directorio lib del SDK de Alfresco)
mvn install:install-file -Dfile=
mvn install:install-file -Dfile=
Una vez hecho esto, abrimos Eclipse e importamos los proyectos del SDK, es decir




Luego creamos un nuevo proyecto llamado Proyecto1, hacemos que este proyecto dependa de SDK AlfrescoEmbedded y de SDKAlfrescoRemote.

CREACION DE CONTENIDO CON ALFRESCO DESDE JAVA
Creamos una nueva clase llamada ClienteCrearContenido
Esta clase lee un archivo del disco, le coloca ciertas propiedades(aspectos) y lo sube al space llamado Primero, que le debimos crear previamente en Alfresco.
con el siguiente código:
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.alfresco.repo.webservice.CMLUtil;
import org.alfresco.webservice.content.ContentServiceSoapBindingStub;
import org.alfresco.webservice.repository.UpdateResult;
import org.alfresco.webservice.types.CML;
import org.alfresco.webservice.types.CMLAddAspect;
import org.alfresco.webservice.types.CMLCreate;
import org.alfresco.webservice.types.ContentFormat;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.ParentReference;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.Utils;
import org.alfresco.webservice.util.WebServiceFactory;
public class ClienteCrearContenido {
private static final String USERNAME = "admin";
}

y si entramos al Space llamado Primero, encontraremos el archivo que subimos

CONSULTA DE CONTENIDO
Para este ejemplo vamos a crear un Space llamado ContenidoTXT en company_home.

En nuestro equipo vamos a crear un archivo de texto llamado mensaje.txt

Subimos este archivo en el space ContenidoTXT


Luego en Eclipse creamos una clase llamada ClienteConsulta, con el siguiente código fuente:
import org.alfresco.webservice.types.Predicate;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.content.Content;
import org.alfresco.webservice.content.ContentServiceSoapBindingStub;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.ContentUtils;
import org.alfresco.webservice.util.WebServiceFactory;
public class ClienteConsulta {
private static final String USERNAME = "admin";
private static final String PASSWORD = "root";
private static final String url = "http://localhost:8080/alfresco/api";
private static final String ruta = "/app:company_home/cm:ContenidoTXT/cm:mensaje.txt";
public static void main(String[] args) throws Exception {
WebServiceFactory.setEndpointAddress(url);
AuthenticationUtils.startSession(USERNAME, PASSWORD);
Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
// vamos a leer contenido del repositorio
ContentServiceSoapBindingStub contentService = WebServiceFactory
.getContentService();
Reference ref = new Reference();
ref.setStore(STORE);
//Podemos tambien usar el Uuid del documeto //ref.setUuid("3b5b8116-46c0-403f-a721-d3552eeb2cf0");
ref.setPath(ruta);
Content[] readResult = contentService.read(new Predicate(
new Reference[] { ref }, STORE, null), Constants.PROP_CONTENT);
System.out.println(readResult.length);
Content content = readResult[0];
System.out.println("Contenido:");
System.out.println(ContentUtils.getContentAsString(content));
System.out.println(content.getProperty());
System.out.println(content.getNode().getPath());
System.out.println(content.getUrl());
AuthenticationUtils.endSession();
}
}
Al ejecutar tenemos la siguiente salida:
1
Contenido:
ESTA ES UNA PRUEBA DE
UN ARCHIVO DE TEXTO SIMPLE
PARA PROBAR LA CONSULTA DE ARCHIVOS
DESDE ALFRESCO :)
{http://www.alfresco.org/model/content/1.0}content
/app:company_home/cm:ContenidoTXT/cm:mensaje.txt
http://localhost:8080/alfresco/download/direct/workspace/SpacesStore/fca946a9-b9dc-45b7-88b2-8492571c5016/mensaje.txt
BORRADO DE CONTENIDO
Vamos a borrar el mensaje.txt de el space ContenidoTXT, que hicimos en la sección anterior
Para borrar contenido debemos utilizar el siguiente código:
import org.alfresco.webservice.repository.QueryResult;
import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
import org.alfresco.webservice.repository.UpdateResult;
import org.alfresco.webservice.types.CML;
import org.alfresco.webservice.types.CMLDelete;
import org.alfresco.webservice.types.Predicate;
import org.alfresco.webservice.types.Query;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.ResultSet;
import org.alfresco.webservice.types.ResultSetRow;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.WebServiceFactory;
public class ClienteLimpiar {
private static final String USERNAME = "admin";
private static final String PASSWORD = "root";
private static final String url = "http://localhost:8080/alfresco/api";
private static final String ruta = "PATH:\"/app:company_home/cm:ContenidoTXT/cm:mensaje.txt\"";
/**
* @param args
*/
public static void main(String[] args) throws Exception {
String timeStamp = new Long(System.currentTimeMillis()).toString();
WebServiceFactory.setEndpointAddress(url);
AuthenticationUtils.startSession(USERNAME, PASSWORD);
try {
Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory
.getRepositoryService();
String queryString = ruta;
Query query = new Query(Constants.QUERY_LANG_LUCENE, queryString);
QueryResult queryResult = repositoryService.query(storeRef, query,
false);
ResultSet resultSet = queryResult.getResultSet();
ResultSetRow[] rows = resultSet.getRows();
if (rows != null) {
System.out.println("Encontradas " + rows.length
+ " coincidencias a borrar.");
CMLDelete[] deleteCMLArray = new CMLDelete[rows.length];
for (int index = 0; index < rows.length; index++) {
ResultSetRow row = rows[index];
deleteCMLArray[index] = new CMLDelete(new Predicate(
new Reference[] { new Reference(storeRef, row
.getNode().getId(), null) }, null, null));
}
CML cml = new CML();
cml.setDelete(deleteCMLArray);
UpdateResult[] results = WebServiceFactory
.getRepositoryService().update(cml);
}
} catch (Throwable e) {
e.printStackTrace();
} finally {
AuthenticationUtils.endSession();
}
AuthenticationUtils.endSession();
}
}
No hay comentarios:
Publicar un comentario