Report samples

Basics

The table below shows how variables should be passed based on field type:

Field typeTypeDescription

Date

String

Use the pattern yyyy-MM-dd (year-month-day).

2018-10-04

Select multiple

String

Use ',' to separate each value.

"value1,value2,value3"

Suggested code sample

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

Then you should log in using the method "login". You can access the "login" method from the webservice object "ws" as shown below:

ws.login(user, password);

Once you are logged in with the webservices, the session is kept in the webservice object. Then you can use the other API methods.

At this point, you can use all the Report methods from the "report" class as shown below:

ws.report.getReports(true)

 Methods

getReports

Description:

MethodReturn valuesDescription

getReports(boolean active)

List<Report>

Returns a list of reports.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Report;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (Report rep : ws.report.getReports(true)) {
                System.out.println(rep);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getReport

Description:

MethodReturn valuesDescription

getReport(long rpId)

Report

Returns a report.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Report;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Report rep = ws.report.getReport(1);
            System.out.println(rep);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

generateDownloadReportToken

Description:

MethodReturn valuesDescription

generateDownloadReportToken(long rpId)

String

Returns the token for downloading the report.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            String token = ws.report.generateDownloadReportToken(1);
            System.out.println(token);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

execute

Description:

MethodReturn valuesDescription

execute(long rpId, Map<String, String> params, String format, String uuid)

InputStream

Returns a document resulting from executing a report.

Available formats:

  • Report.FORMAT_CSV
  • Report.FORMAT_DOCX
  • Report.FORMAT_HTML
  • Report.FORMAT_ODT
  • Report.FORMAT_PDF
  • Report.FORMAT_RTF
  • Report.FORMAT_TEXT

The parameter uuid is the UUID of a node (this parameter is optional; it is usually meaningful for reports executed from the user interface where the results depend on the selected node).

Example:

package com.openkm;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Report;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Map<String, String> params = new HashMap<>();
            params.put("from_date", "2021-01-01");
            params.put("to_date", "2021-05-01");

            long rpId = 1;
            String format = Report.FORMAT_PDF;
            String dstId = "c5c87bd3-0c03-4bba-ab2f-7184c23a26d8";
            String uuid = "";
            InputStream is = ws.report.execute(rpId, params, format, dstId, uuid);
            OutputStream fos = new FileOutputStream("/home/openkm/report/document Create.pdf");
            IOUtils.copy(is, fos);
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

executeSql

Description:

MethodReturn valuesDescription

executeSql(long rpId)

InputStream

Returns a document resulting from executing a report SQL query.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
import org.apache.commons.io.IOUtils;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);

            // executeReportSql
            long rpdId = 1;
            InputStream is = ws.report.executeSql(rpdId);
            OutputStream fos = new FileOutputStream("/home/openkm/report/activity.csv");
            IOUtils.copy(is, fos);
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

save

Description: 

MethodReturn values Description

save(long rpId, Map<String, String> params, String format, String dstId, docName, String uuid)

Document

Execute the report and save the resulting document.

Available formats:

  • Report.FORMAT_CSV
  • Report.FORMAT_DOCX
  • Report.FORMAT_HTML
  • Report.FORMAT_ODT
  • Report.FORMAT_PDF
  • Report.FORMAT_RTF
  • Report.FORMAT_TEXT

The values of the dstId parameter should be a folder or record UUID.

The parameter docName is the file name of the report.

The parameter uuid is the UUID of a node (this parameter is optional; it is usually meaningful for reports executed from the user interface where the results depend on the selected node).

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.bean.Report;
import com.openkm.sdk4j.impl.OKMWebservices;

import java.util.HashMap;
import java.util.Map;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Map<String, String> params = new HashMap<>();
            params.put("from_date", "2021-01-01");
            params.put("to_date", "2021-05-01");

            long rpId = 1;
            String format = Report.FORMAT_PDF;
            String dstId = "c5c87bd3-0c03-4bba-ab2f-7184c23a26d8";
            String docName = "Document create.pdf";
            String uuid = "";
            Document documenReport = ws.report.save(rpId, params, format, dstId, docName, uuid);
            System.out.println(documenReport);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

saveSql

Description: 

MethodReturn values Description

saveSql(long rpId, Map<String, String> params, String dstId, docName)

Document

Execute the report SQL and save the resulting CSV document.
The values of the dstId parameter should be a folder or record UUID.

The parameter docName is the file name of the report.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;

import java.util.HashMap;
import java.util.Map;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);

            // saveSql
            long rpId = 1;
            String dstId = "8f64d889-1600-4cbc-8245-de6fb62214eb";
            String docName = "activity.csv";
            Document documenReport = ws.report.saveSql(rpId, new HashMap<>(), dstId, docName);
            System.out.println(documenReport);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

getSqlReports

Description:

MethodReturn valuesDescription

getSqlReports(boolean active)

List<Report>

Returns a list of SQL reports.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.SqlReport;
import com.openkm.sdk4j.impl.OKMWebservices;

import java.util.List;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);

            // getSqlReports
            List<SqlReport> sqlReports = ws.report.getSqlReports(true);
            for (SqlReport sqlReport : sqlReports) {
                System.out.println(sqlReport);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}