maia_modificado/.svn/pristine/c4/c4d100440bda922836232f9225b...

152 lines
5.0 KiB
Plaintext
Executable File

/**
*
*/
package com.fp.alfresco.client;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.apache.commons.io.IOUtils;
/**
* Clases test de Alfresco api client
* @author bpt
*
*/
public class Prueba {
/**
* Método principal
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
subirActualizarDocumento();
}
/**
* Actualiza documentos
* @throws Exception
*/
public static void subirActualizarDocumento() throws Exception{
AlfrescoApi api = new AlfrescoApi("ejemplo");
File f = new File("/home/james/DAVID/xpathAlfBujias.pdf");
DocumentoAlfresco doc = api.findOneByXPathLocation("/app:company_home/st:sites/cm:ejemplo/cm:documentLibrary/cm:Carga_Archivos_Prueba/cm:xpathAlfBujias.pdf");
//DocumentoAlfresco doc = api.findOneByXPathLocation("/app:company_home/st:sites/cm:spj/cm:documentLibrary/cm:INTENDENCIAS/cm:INTENDENCIA DE CUENCA/cm:2015/cm:OCTUBRE/cm:torneo_futbol.xlsx");
doc.setModificadoPor("dcruz");
doc.setFile(f);
doc.setNombre(f.getName());
doc = api.uploadUpdateDocument(doc);
}
/**
* Sube documentos
* @throws Exception
*/
public static void subirDocumento() throws Exception{
AlfrescoApi api = new AlfrescoApi("ejemplo");
File f = new File("/home/james/DAVID/xpathAlfBujias.pdf");
DocumentoAlfresco doc = new DocumentoAlfresco(f.getName(), "dcruz");
// doc.setTipo("sbspjd:providenciasJudiciales");
doc.setModificadoPor("dcruz");
doc.setFile(f);
// doc.setPropiedadCampo("sbspjd:numeroCircular", "SG-2015-3612", EnumDataType.STRING);
// doc.setPropiedadCampo("sbspjd:fechaPubliSist", new Date(), EnumDataType.DATE);
// doc.setPropiedadCampo("sbsgen:remitente", "COACTIVAS DEL SRI DEL NORTE", EnumDataType.STRING);
// doc.setPropiedadCampo("sbspjd:numFojas", 3.0, EnumDataType.NUMBER);
doc.setNombre(f.getName());
doc = api.uploadNewDocument("cm:Carga_Archivos_Prueba", doc);
}
/**
* Descarga documentos
* @throws Exception
*/
public static void descargarDocumento() throws Exception{
AlfrescoApi api = new AlfrescoApi("ejemplo");
DocumentoAlfresco doc =api.findById("workspace://SpacesStore/90e9b3d1-cb64-45ca-bd99-087b87052cf7");
InputStream inputStream = api.downloadDocumentById(doc.getId());
OutputStream outputStream = new FileOutputStream("/home/james/DAVID/alf_cat_bujias_2011.pdf");
IOUtils.copy(inputStream, outputStream);
IOUtils.closeQuietly(outputStream);
}
/**
* Descarga ayudas
* @throws Exception
*/
public static void descargarDocumentoAyudas() throws Exception{
AlfrescoApi api = new AlfrescoApi("ejemplo");
// InputStream inputStream = api.downloadDocumentByXPathLocation("/app:company_home/st:sites/cm:seo/cm:documentLibrary/cm:ayudas/cm:parametro.pdf");
InputStream inputStream = api.downloadDocumentByXPathLocation("/app:company_home/st:sites/cm:{0}/cm:documentLibrary/cm:Carga_Archivos_Prueba/cm:"+"cat_bujias_2011"+".pdf", true);
OutputStream outputStream = new FileOutputStream("/home/james/DAVID/xpathAlfBujias.pdf");
IOUtils.copy(inputStream, outputStream);
outputStream.close();
}
/**
* busca por xpath
* @throws Exception
*/
public static void buscarPorXpathLocation() throws Exception{
AlfrescoApi api = new AlfrescoApi("jep");
DocumentoAlfresco doc = api.findOneByXPathLocation("/app:company_home/st:sites/cm:jep/cm:documentLibrary/cm:Carga_Archivos_Plantilla/cm:cat_bujias_2011.pdf");
System.out.println(doc);
// if(doc!=null){
//doc.getxPathLocation();
// }
}
/**
* Busca por id
* @throws Exception
*/
public static void buscarPorId() throws Exception{
AlfrescoApi api = new AlfrescoApi("seo");
DocumentoAlfresco doc = api.findById("workspace://SpacesStore/6b502f0b-39f4-47a8-915d-071cacc953cf");
System.out.println(doc);
}
/**
* Busca por contenido
* @throws Exception
*/
public static void buscarPorContenido() throws Exception{
AlfrescoApi api = new AlfrescoApi("seo");
List<DocumentoAlfresco> ldoc = api.findByContent("fines pertinentes");
System.out.println(ldoc);
}
/**
* Busca por atributos
* @throws Exception
*/
public static void buscarPorAtributo() throws Exception{
AlfrescoApi api = new AlfrescoApi("seo");
DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String string = "2013-12-23";
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(string);
String ds = iso8601.format(date);
List<DocumentoAlfresco> ldoc = api.findByAttribute("sbspjd:fechaFRecepcion", ds);
System.out.println(ldoc);
}
/**
* Elimina por id
* @throws Exception
*/
public static void eliminarDocumentoPorId() throws Exception{
AlfrescoApi api = new AlfrescoApi("ejemplo");
api.deleteDocument("workspace://SpacesStore/c358fb30-a001-49dc-9ef9-b2b185f48325");
}
}