Report samples
Basics
The table below shows how variables should be passed based on field type:
Field type | Type | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
executeReport(long rpId, Map<String, String> params, String format, String uuid) |
InputStream |
Returns a document resulting from executing a report. |
Available formats:
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();
}
}
}