Difference between revisions of "Reports"

From OpenKM Documentation
Jump to: navigation, search
(Created page with 'In Report view you can found several pdf reports like locked documents, documents with subscriptions and registered users. Reports are in pdf format. <center>[[File:Okm_admin_0…')
 
(Script Report)
 
(26 intermediate revisions by 3 users not shown)
Line 1: Line 1:
In Report view you can found several pdf reports like locked documents, documents with subscriptions and registered users. Reports are in pdf format.
+
{{TOCright}} __TOC__
  
 +
In the report section you can create and use your own Jasper Reports. Reports are generated in [[wikipedia:PDF|PDF]] format. Starting from OpenKM 5.1, other formats can be generated.
  
<center>[[File:Okm_admin_017.jpeg]]</center>
+
{{Note|The JasperReports version included in OpenKM 6.2 works best with [[http://jasperforge.org/plugins/espnews/browse.php?group_id=83&news_id=256 iReport 3.7.6.]].}}
  
 +
[[File:Okm_admin_061.jpeg|center]]
 +
 +
Reports usually make use of certain TTF fonts that need to be installed in your server. For example, the Arial font. These fonts are included in Windows but not in Linux distros. To install these fonts under Debian / Ubuntu:
 +
 +
$ sudo aptitude install msttcorefonts
 +
 +
To install under CentOS run these commands as root:
 +
 +
$ yum install cabextract rpm-build
 +
$ wget http://corefonts.sourceforge.net/msttcorefonts-2.0-1.spec
 +
$ rpmbuild -ba msttcorefonts-2.0-1.spec
 +
$ rpm -ivh /usr/src/redhat/RPMS/noarch/msttcorefonts-2.0-1.noarch.rpm
 +
$ /sbin/service xfs reload
 +
 +
== Add new report ==
 +
Then click on the [[File:add.png]] '''new report icon'''
 +
 +
 +
[[File:Okm_admin_062.jpeg|center]]
 +
 +
 +
Reports can use internal Scripting or SQL. The file to upload must be a '''.jrxml''' JasperReport source file. Starting with OpenKM 5.1 you can also upload compiled reports (files with '''.jasper''' extension).
 +
 +
== Types of reports ==
 +
=== SQL Report ===
 +
Usually you have a database and want to generate a report extracting data from it. In this case you should know the table relationships. Tools like [http://www.aquafold.com/ Aqua Data Studio] can help you to create a ER diagram. In this example, we will query the database to generate a report with information related to workflow execution:
 +
 +
<source lang="sql">
 +
select ti.actorid_ as ti_actorid, pd.name_ as pd_name, ti.name_ as ti_name, ti.start_ as ti_start, ti.end_ as ti_end
 +
from JBPM_TASKINSTANCE as ti, JBPM_PROCESSINSTANCE as pi, JBPM_PROCESSDEFINITION as pd
 +
where ti.procinst_ = pi.id_ and pi.processdefinition_ = pd.id_
 +
order by ti_actorid, pd_name, ti_name, ti_start, ti_end
 +
</source>
 +
 +
Full report is available at [[File:WorkflowWorkload.jrxml]].
 +
 +
=== Script Report ===
 +
Other times, the data is not extracted from a database but another source. In this case we will query the OpenKM API to obtain a list of registered users.
 +
 +
<source lang="java">
 +
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;
 +
</source>
 +
 +
This means that not only database-managed users are shown but also external users if you have configured OpenKM to use an external LDAP server to handle user management.
 +
 +
Full report is available at [[File:RegisteredUsers.jrxml]].
 +
 +
=== XPath Report ===
 +
{{Note|This feature is only available in OpenKM 5.1.}}
 +
 +
If you want to create a report which uses an XPath query, use scripting. This code will query for locked documents:
 +
 +
<source lang="java">
 +
import javax.jcr.*;
 +
import javax.jcr.query.*;
 +
import org.apache.jackrabbit.*;
 +
import com.openkm.module.direct.*;
 +
 +
List al = new ArrayList ();
 +
String statement = "/jcr:root/okm:root//element(*,okm:document)[@jcr:lockOwner]/@jcr:lockOwner";
 +
String type = "xpath";
 +
Session jcrSession = DirectRepositoryModule.getSystemSession();
 +
Workspace workspace = jcrSession.getWorkspace();
 +
QueryManager queryManager = workspace.getQueryManager();
 +
Query query = queryManager.createQuery(statement, type);
 +
QueryResult result = query.execute();
 +
 +
for (RowIterator it = result.getRows(); it.hasNext();) {
 +
  Map ld = new HashMap();
 +
  javax.jcr.query.Row row = it.nextRow();
 +
  javax.jcr.Value v = row.getValue(JcrConstants.JCR_LOCKOWNER);
 +
  ld.put("owner", v==null?"NULL":v.getString());
 +
  v = row.getValue(JcrConstants.JCR_PATH);
 +
  ld.put("path", v==null?"NULL":v.getString());
 +
  al.add(ld);
 +
}
 +
 +
return al;
 +
</source>
 +
 +
You can find the whole report at [[File:LockedDocuments.jrxml]] and [[File:SubscribedDocuments.jrxml]].
 +
 +
== Reports with parameters ==
 +
Since OpenKM 5.1.7, the reports feature has been improved and now you can create reports with parameters. This enables the possibility of creating more dynamic reports.
 +
 +
To achieve this you need to package the report in an archive with a '''rep''' extension. This archive will contain the report itself and an XML file called '''params.xml''' which describes the report parameters. This file must be called '''params.xml''' or this won't work. You can create a ZIP archive from these files and rename the extension to "rep".
 +
 +
Let's see a sample '''params.xml''' file:
 +
 +
<source lang="xml">
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<!DOCTYPE report-parameters PUBLIC "-//OpenKM//DTD Report Parameters 2.0//EN"
 +
                                  "http://www.openkm.com/dtd/report-parameters-2.0.dtd">
 +
<report-parameters>
 +
  <input label="Path" name="path" type="folder"/>
 +
</report-parameters>
 +
</source>
 +
 +
In this XML you can see an "input" parameter called "path". The "type" field specifies what kind of "input" will be used (for more info read [[Report Parameters description]]) in this piece of the script inside the report. Let's see how this parameter can be used:
 +
 +
<source lang="java">
 +
List al = new ArrayList ();
 +
Session jcrSession = DirectRepositoryModule.getSystemSession();
 +
System.out.println("Parameter 'path': " + path);
 +
Node root = jcrSession.getRootNode().getNode(path.substring(1));
 +
nodeIterator(root);
 +
</source>
 +
 +
As you can see, the parameter "path" is automatically injected and can be used as a local variable.
 +
 +
You can download the sample report at [[File:FolderDocuments.rep]].
  
 
[[Category: Administration Guide]]
 
[[Category: Administration Guide]]

Latest revision as of 19:01, 26 June 2013

In the report section you can create and use your own Jasper Reports. Reports are generated in PDF format. Starting from OpenKM 5.1, other formats can be generated.


Nota clasica.png The JasperReports version included in OpenKM 6.2 works best with [iReport 3.7.6.].

Okm admin 061.jpeg

Reports usually make use of certain TTF fonts that need to be installed in your server. For example, the Arial font. These fonts are included in Windows but not in Linux distros. To install these fonts under Debian / Ubuntu:

$ sudo aptitude install msttcorefonts

To install under CentOS run these commands as root:

$ yum install cabextract rpm-build
$ wget http://corefonts.sourceforge.net/msttcorefonts-2.0-1.spec
$ rpmbuild -ba msttcorefonts-2.0-1.spec
$ rpm -ivh /usr/src/redhat/RPMS/noarch/msttcorefonts-2.0-1.noarch.rpm
$ /sbin/service xfs reload

Add new report

Then click on the Add.png new report icon


Okm admin 062.jpeg


Reports can use internal Scripting or SQL. The file to upload must be a .jrxml JasperReport source file. Starting with OpenKM 5.1 you can also upload compiled reports (files with .jasper extension).

Types of reports

SQL Report

Usually you have a database and want to generate a report extracting data from it. In this case you should know the table relationships. Tools like Aqua Data Studio can help you to create a ER diagram. In this example, we will query the database to generate a report with information related to workflow execution:

select ti.actorid_ as ti_actorid, pd.name_ as pd_name, ti.name_ as ti_name, ti.start_ as ti_start, ti.end_ as ti_end
from JBPM_TASKINSTANCE as ti, JBPM_PROCESSINSTANCE as pi, JBPM_PROCESSDEFINITION as pd
where ti.procinst_ = pi.id_ and pi.processdefinition_ = pd.id_
order by ti_actorid, pd_name, ti_name, ti_start, ti_end

Full report is available at File:WorkflowWorkload.jrxml.

Script Report

Other times, the data is not extracted from a database but another source. In this case we will query the OpenKM API to obtain a list of registered users.

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;

This means that not only database-managed users are shown but also external users if you have configured OpenKM to use an external LDAP server to handle user management.

Full report is available at File:RegisteredUsers.jrxml.

XPath Report


Nota clasica.png This feature is only available in OpenKM 5.1.

If you want to create a report which uses an XPath query, use scripting. This code will query for locked documents:

import javax.jcr.*;
import javax.jcr.query.*;
import org.apache.jackrabbit.*;
import com.openkm.module.direct.*;

List al = new ArrayList ();
String statement = "/jcr:root/okm:root//element(*,okm:document)[@jcr:lockOwner]/@jcr:lockOwner";
String type = "xpath";
Session jcrSession = DirectRepositoryModule.getSystemSession();
Workspace workspace = jcrSession.getWorkspace();
QueryManager queryManager = workspace.getQueryManager();
Query query = queryManager.createQuery(statement, type);
QueryResult result = query.execute();

for (RowIterator it = result.getRows(); it.hasNext();) {
  Map ld = new HashMap();
  javax.jcr.query.Row row = it.nextRow();
  javax.jcr.Value v = row.getValue(JcrConstants.JCR_LOCKOWNER);
  ld.put("owner", v==null?"NULL":v.getString());
  v = row.getValue(JcrConstants.JCR_PATH);
  ld.put("path", v==null?"NULL":v.getString());
  al.add(ld);
}

return al;

You can find the whole report at File:LockedDocuments.jrxml and File:SubscribedDocuments.jrxml.

Reports with parameters

Since OpenKM 5.1.7, the reports feature has been improved and now you can create reports with parameters. This enables the possibility of creating more dynamic reports.

To achieve this you need to package the report in an archive with a rep extension. This archive will contain the report itself and an XML file called params.xml which describes the report parameters. This file must be called params.xml or this won't work. You can create a ZIP archive from these files and rename the extension to "rep".

Let's see a sample params.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE report-parameters PUBLIC "-//OpenKM//DTD Report Parameters 2.0//EN"
                                   "http://www.openkm.com/dtd/report-parameters-2.0.dtd">
<report-parameters>
  <input label="Path" name="path" type="folder"/>
</report-parameters>

In this XML you can see an "input" parameter called "path". The "type" field specifies what kind of "input" will be used (for more info read Report Parameters description) in this piece of the script inside the report. Let's see how this parameter can be used:

List al = new ArrayList ();
Session jcrSession = DirectRepositoryModule.getSystemSession();
System.out.println("Parameter 'path': " + path);
Node root = jcrSession.getRootNode().getNode(path.substring(1));
nodeIterator(root);

As you can see, the parameter "path" is automatically injected and can be used as a local variable.

You can download the sample report at File:FolderDocuments.rep.