Introducing to reports based on Java

  • Install the iReport tool.
  • Execute iReport tool.

OpenKM comes with an specific JasperReports Library engine that supports older versions but now a newer one can be found. At Application version compatibility table you have correspondence list between OpenKM and JasperReports Library engine versions.

You can set specific output version from iReport tool:

  • Click on Tools menu > options.
  • From iReport > General tab click on Compatibility tab.
  • Set the Jasper version compatibility.
  • Click on OK button.

Testing Java sample report

Reports based on Java can not be previewed directly from iReport tool. Must be checked from an OpenKM.

For testing SQL Report sample you must have an OpenKM running.

 

  • Click on Designer tab.
  • Click on  report query button.

In this case in place of SQL query you can set a Java Scripting ( see also Scripting samples ).

The script must return a List<Map> object where each value into the map corresponds to a column value.

From this point you can add your jrxml file and register to your OpenKM at Administration > Reports .

Understanding the code sample

  • Create an empty list.
  • Iterate across all users calling the API method named AuthDAO.findAllUsers(false).
  • Create a Map for each User object where each value corresponds to a column.
  • Add each map into the list, where each map corresponds to a row.
import com.openkm.dao.*;
import com.openkm.dao.bean.*;

List al = new ArrayList();
for (User user : AuthDAO.findAllUsers(false)) {
    Map usr = new HashMap();
    usr.put("id", user.getId());
    usr.put("name", user.getName());
    usr.put("email", user.getEmail());
    usr.put("roles", user.getRoles().toString());
    al.add(usr);
}

return al;

Using in report

  • For each key in map create a field.
  • Use the field in report