Creating Custom Reports Based on the SPARQL Endpoint
Creating Custom Reports Based on the SPARQL Endpoint
PoolParty offers the ability to easily generate reports. Choose from several default reports or create custom reports using SPARQL queries and the Velocity template engine.
Prerequisites for a Custom Report
A SPARQL query for selecting the data.
A Velocity template for formatting the query results.
A report entry in the PoolParty configuration file SesameSetup.xml
1. SPARQL Query
First you need to write your query selecting the data for the report. You can test your query with the SPARQL endpoint of your project (the endpoint will also be used for the reports).
The query has to be a SELECT query in the syntax specified by the W3C.
You can use variables in your query by marking them with %%% before and after the variable name (e.g. %%%Language%%%)
In the next step you need to add your query to the SesameSetup.xml (located in the Configuration folder of the PoolParty installation):
Look for the
<namedQueries>
node in theconfig/SesameSetup.xml
Add a new
<entry>
node under the<namedQueries>
node for your query (anywhere before or after an existing entry) :<entry> <key>{Your Query Name}</key> <value> <sparqlQueryParameterMap> <entry> <key>{Variable Name}</key> <value>{Default Value}</value> </entry> </sparqlQueryParameterMap> <sparqlQueryTemplate> {Your SPARQL Query} </sparqlQueryTemplate> </value> </entry>
Replace the following parts with your query details:
Your Query Name - name of the query
(The sparqlQueryParameterMap node is optional and only necessary if you use variables in your query)
Variable Name (optional) - name of the variable used in the SPARQL query (The one marked with %%%Variable Name%%% in the query)
Default Value (optional) - default value for the variable if no value is specified
Your SPARQL Query - the SPARQL query for data selection
Necessary character replacements
Greater-than (>) and less-than (<) characters have to be XML-encoded:
< and >
Logical AND (&&) has to be converted to:
&&
Quotation marks have to be converted to:
"
2. Velocity Template
For detailed information on how to write Velocity templates, please visit the Apache Velocity user guide .
Within the template you can access the following variables:
$bindings - A list of strings containing the binding names
$result - A list of the result "rows" of your query.
Check out the SPARQL Endpoint documentation for more information about the result structure and how to access the rows.
Put your template file in the following folder:
/opt/poolparty/data/resourceRoot (GNU/Linux)
C:\Users\Public\PoolParty\data\resourceRoot (Windows)
3. The Report Entry - Glueing It Together
With the <reports>
entry in the SesameSetup.xml you are weaving together the query and the template and assigning a name for the report.
Look for the
<reports>
node in the SesameSetup.xmlAdd a new
<entry>
node under the<report>
node for your report (anywhere before or after an existing entry) :<entry> <key>Your Report Name</key> <value> <contentType>Content Type</contentType> <namedQuery>Your Query Name</namedQuery> <template>Template Filename</template> </value> </entry>
Replace the following parts with your report details:
Your Report Name - name of the report as displayed in the report dialog
Content Type - The content-type of the generated report (e.g. application/xml, text/plain, etc.)
Your Query Name - name of the your SPARQL query as defined in the
entry
undernamedQueries
Template Filename - name of the template file in the velocity folder
After the next restart of the web application (the setup has to be refreshed), the report will be available from the Project -> Reports menu entry.
When you click on the "Generate Report" button a call to the SPARQL endpoint is made using the following pattern:
http.//<server>/PoolParty/SPARQLEndPoint/<project-id>?queryname=<queryname>&template=<template>&content-type=<content-type>&<variable>=<value>
This will produce the report.