Introduction to reports based on Java
- Install the iReport tool.
- Execute the iReport tool.
OpenKM comes with a specific JasperReports Library engine that supports older versions, but a newer one can now be found. At Application version compatibility table you have a correspondence list between OpenKM and JasperReports Library engine versions.
You can set a specific output version from the iReport tool:
- Click on Tools menu > Options.
- From iReport > General tab, click on Compatibility tab.
- Set the Jasper version compatibility.
- Click on the OK button.
Testing the Java sample report
Reports based on Java cannot be previewed directly from the iReport tool. They must be checked from OpenKM.
For testing the SQL Report sample, you must have an OpenKM running.
- Download the JavaReportPattern.jrxml file.
- Open the file.
- Click on the Designer tab.
- Click on
the report query button.
In this case, in place of an SQL query, you can set a Java Scripting (see also Scripting samples).
The script must return a List<Map> object where each value in the map corresponds to a column value.
From this point you can add your jrxml file and register it in your OpenKM at Administration > Reports.
Understanding the code sample
- Create an empty list.
- Iterate through all users by calling the API method AuthDAO.findAllUsers(false).
- Create a Map for each User object where each value corresponds to a column.
- Add each map to the list, where each map corresponds to a row.
import com.openkm.db.service.*;
import com.openkm.bean.*;
import com.openkm.util.ContextWrapper;
import org.springframework.web.context.WebApplicationContext;
WebApplicationContext cc = (WebApplicationContext) ContextWrapper.getContext();
AuthSrv authSrv = cc.getBean(AuthSrv.class);
List al = new ArrayList();
for (CommonUser user : authSrv.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 the report
- For each key in the map, create a field.
- Use the field in the report.