Report samples

Basics

The table below shows how should be passed variables 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 split each value

"value1,value2,value3"

Suggested code sample

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

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

ws.login(user, password);

Once you are logged with the webservices the session is keep in the webservice Object. Then you can use the other API method

At this point you can use all the Report methods from "report" class as is 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 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);
            Report rep = ws.report.getReport(1);
            System.out.println(rep);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

saveReport

Description: 

MethodReturn valuesDescription

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

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 dstld parameter should be a folder or record UUID.

The parameter docName is the file name of the report.

Example:

package com.openkm;

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

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
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<>();
            String format = Report.FORMAT_PDF;
            Document doc = ws.report.saveReport(1, params, format, "8599eab7-ae61-4628-8010-1103d6950c63", "document.pdf");
            System.out.println(doc);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

generateDownloadReportToken

Description:

MethodReturn valuesDescription

generateDownloadReportToken(long rpId)

String

Return 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)

InputStream

Return a document result of executing a report.

Avaialble formats:

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

Example:

package com.openkm;

import java.io.FileOutputStream;
import java.io.InputStream;
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<>();
            String format = Report.FORMAT_PDF;
            InputStream is = ws.report.executeReport(1, params, format);
            FileOutputStream fos = new FileOutputStream("/home/openkm/out.pdf");
            IOUtils.copy(is, fos);
            is.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}