Report samples
Aspectos básicos
Sección titulada «Aspectos básicos»La siguiente tabla muestra cómo deben pasarse las variables según el tipo de campo:
| Tipo de campo | Tipo | Descripción |
|---|---|---|
| Date | String | Use el patrón yyyy-MM-dd ( año - mes - día ) 2018-10-04 |
| Select multiple | String | Use “,” para separar cada valor. “value1,value2,value3” |
Ejemplo de código sugerido
Sección titulada «Ejemplo de código sugerido»Primero debe crear el objeto webservice:
OKMWebservices ws = OKMWebservicesFactory.newInstance(host);A continuación, debe iniciar sesión mediante el método “login”. Puede acceder al método “login” desde el objeto webservice “ws”, tal y como se muestra a continuación:
ws.login(user, password);Llegados a este punto puede usar todos los métodos de Report desde la clase “report”, tal y como se muestra a continuación:
ws.report.getReports(true)Métodos
Sección titulada «Métodos»getReports
Sección titulada «getReports»Descripción:
| Método | Valores de retorno | Descripción |
|---|---|---|
| getReports(boolean active) | List |
Devuelve una lista de informes. |
Ejemplo:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{ public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try { ws.login(user, password); List<Report> reports = ws.report.getReports(true); foreach (Report rep in reports) { System.Console.WriteLine(rep.toString()); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getReport
Sección titulada «getReport»Descripción:
| Método | Valores de retorno | Descripción |
|---|---|---|
| getReport(long rpId) | Report | Devuelve un informe. |
Ejemplo:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{ public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try { ws.login(user, password); List<Report> reports = ws.report.getReports(true); Report report = new Report(); foreach (var rep in reports) { if (rep.fileName.Equals("DocumentCheckout.rep")) { // Get report report = ws.report.getReport(rep.id); break; } } System.Console.WriteLine(report.toString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}execute
Sección titulada «execute»Descripción:
| Método | Valores de retorno | Descripción |
|---|---|---|
| execute(long rpId, Dictionary<String, String> params, String format, String uuid) | Stream | Devuelve un documento resultante de ejecutar un informe. |
Ejemplo:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.util;
namespace OKMRest{ public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try { ws.login(user, password); List<Report> reports = ws.report.getReports(true); Report report = new Report(); foreach (var rep in reports) { if (rep.fileName.Equals("DocumentCheckout.rep")) { // Get report report = ws.report.getReport(rep.id); break; } }
Dictionary<String, String> param = new Dictionary<String, String>(); param.Add("from_date", "2016-01-01"); param.Add("to_date", "2016-12-23"); String uuid = ""; Stream stream = ws.report.execute(report.id, Report.FORMAT_PDF, param, uuid);
BeanHelper beanHelper = new BeanHelper(); Byte[] data = beanHelper.ReadToEnd(stream); FileStream fileStream = new FileStream(@"C:\Desktop\out.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite); foreach (byte b in data) { fileStream.WriteByte(b); } fileStream.Close(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}executeSql
Sección titulada «executeSql»Descripción:
| Método | Valores de retorno | Descripción |
|---|---|---|
| executeSql(long rpId) | Stream | Devuelve un documento resultante de ejecutar un informe SQL. |
Ejemplo:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{ public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try { ws.login(user, password); long rpdId = 1; Stream stream = ws.report.executeSql(rpdId); FileStream file = new FileStream("C:\\activity.csv", FileMode.OpenOrCreate, FileAccess.ReadWrite); stream.CopyTo(file); file.Close(); stream.Close(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getSqlReports
Sección titulada «getSqlReports»Descripción:
| Método | Valores de retorno | Descripción |
|---|---|---|
| getSqlReports(boolean active) | List |
Devuelve una lista de informes SQL. |
Ejemplo:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{ public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try { ws.login(user, password); List<SqlReport> sqlReports = ws.report.getSqlReports(true); foreach(SqlReport sqlr in sqlReports) { System.Console.WriteLine(sqlr.toString()); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}Descripción:
| Método | Valores de retorno | Descripción |
|---|---|---|
| save(long rpId, Dictionary<String, String> _params, String format, String dstId, String docName, String uuid) | Document | Ejecuta el informe y guarda el documento resultante. |
Ejemplo:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{ public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try { ws.login(user, password); long repId = 1; Dictionary<String, String> param = new Dictionary<String, String>(); param.Add("from_date", "2018-01-01"); param.Add("to_date", "2019-12-30"); String uuid = ""; Document doc = ws.report.save(repId, param, Report.FORMAT_PDF, "8599eab7-ae61-4628-8010-1103d6950c63", "REPORT-001.pdf", uuid); System.Console.WriteLine(doc.toString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}saveSql
Sección titulada «saveSql»Descripción:
| Método | Valores de retorno | Descripción | |
|---|---|---|---|
| saveSql(long rpId, Dictionary<String, String> _params, String dstId, String docName) | Document | Ejecuta el informe SQL y guarda el documento CSV resultante. |
Ejemplo:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{ public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try { ws.login(user, password); long rpId = 1; String dstId = 7f64d889-1600-4cbc-8134-ef6fb62287ec; String docName = "activity.csv"; Document document = ws.report.saveSql(rpId, new Dictionary<string, string>(), dstId, docName); System.Console.WriteLine(document.ToString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}generateDownloadReportToken
Sección titulada «generateDownloadReportToken»Descripción:
| Método | Valores de retorno | Descripción |
|---|---|---|
| generateDownloadReportToken(long rpId) | String | Devuelve el token para descargar el informe. |
Ejemplo:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{ public class Program { static void Main(string[] args) { String host = "http://localhost:8080/openkm"; String username = "okmAdmin"; String password = "admin"; OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try { ws.login(user, password); long repId = 1; String dwt = ws.report.generateDownloadReportToken(repId); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}