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 web service object:

OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

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

ws.login(user, password);

Once you are logged in with the web services, the session is kept in the web service 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();
        }
    }
}

executeReport

Description:

MethodReturn valuesDescription

executeReport(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.executeReport(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();
        }
    }
}