Right Outer Join

7 May 2013

REST endpoint for Jaspersoft Query Executor

Filed under: JasperReports Server — Tags: , , , — mdahlman @ 10:58

Show me the data

Often, usually, nearly-always I want my report server to give me a nicely formatted view of my data. A “report”. But not always. Sometimes I just want my data. I’ll format it myself, thank you. JasperReports Server can do that, but I had never done it before. Here are my notes from figuring it out.

Prerequisites

  • JasperReports Server v5.1 or later is installed and working.
  • A data source and a domain are defined.
  • I have at least one query written to get started with.
  • (If you just want to follow along, you can use the sample domain included with JRS and the sample query provided below.)
  • A REST Client for testing. Use whatever you like. I recommend Advanced REST Client (a Chrome plugin).

Construct the URL

Here is the basic structure of the URL we need to create:

{scheme}://{host}:{port}/{contextPath}/rest_v2/queryExecutor/{resourceUri}?q={queryString}

In my case I’ll use the sample domain “Supermart Domain”. The URI path is “/public/Samples/Domains/supermartDomain”

Domain URI path

The domain URI path is part of its properties

I constructed a simple query using the Domain Expression Language (domEL) syntax. Refer to the JasperReports Server User Guide for details. Here’s the query in readable form:

<query>
  <queryFields>
    <queryField id="inv_store.inv_store__store_name" />
    <queryField id="inv_store.inv_store__store_type" />
    <queryField id="inv_store__store_contact.inv_store__store_contact__store_manager" />
  </queryFields>
  <queryFilterString>inv_store__region.inv_store__region__sales_state_province == 'CA'</queryFilterString>
</query>

Here’s the same query with spaces and carriage returns removed and url encoded:

%3Cquery%3E%3CqueryFields%3E%3CqueryField+id%3D%22inv_store.inv_store__store_name%22+%2F%3E%3CqueryField+id%3D%22inv_store.inv_store__store_type%22+%2F%3E%3CqueryField+id%3D%22inv_store__store_contact.inv_store__store_contact__store_manager%22+%2F%3E%3C%2FqueryFields%3E%3CqueryFilterString%3Einv_store__region.inv_store__region__sales_state_province+%3D%3D+'CA'%3C%2FqueryFilterString%3E%3C%2Fquery%3E

With the domain and the query identified, now I have everything I need to construct the url:

http://localhost/jasperserver-pro/rest_v2/queryExecutor/public/Samples/Domains/supermartDomain?q=%3Cquery%3E%3CqueryFields%3E%3CqueryField+id%3D%22inv_store.inv_store__store_name%22+%2F%3E%3CqueryField+id%3D%22inv_store.inv_store__store_type%22+%2F%3E%3CqueryField+id%3D%22inv_store__store_contact.inv_store__store_contact__store_manager%22+%2F%3E%3C%2FqueryFields%3E%3CqueryFilterString%3Einv_store__region.inv_store__region__sales_state_province+%3D%3D+'CA'%3C%2FqueryFilterString%3E%3C%2Fquery%3E

I’m ignoring authentication. For a quick test you can first login to JRS, then paste in this url. You’ll get a response in the default format: XML. Refer to the JasperReports Server Web Service Guide for details on how to securely authenticate programmatically.

Show me the data

But I want JSON rather than XML. No problem; I just add the header “Accept: application/json” to my request. Now my result set comes back in JSON.

This screenshot from the Advanced Rest Client shows the added header and the JSON result set.

This screenshot from the Advanced Rest Client shows the added header and the JSON result set.

Why is this cool? Now I have complete flexibility to render the data as I like, but I still get the benefits of the report server:

  • Security: I’ll only see the data that I should see)
  • Scalability: JRS does intelligent data caching
  • Consistency: I’ll continue to use the same data source for most of my data visualizations which get rendered as reports on the server.

28 November 2012

Amazon AWS Redshift

Filed under: JasperReports — mdahlman @ 09:49

Amazon puts on quite a show. There are lots of good technical sessions at re:Invent 2012.

The most exciting announcement directly related to Business Intelligence is their Redshift announcement. We were proud to have Jaspersoft included as part of it. Here’s a short demo of Jaspersoft 5.0 running on Redshift.

24 October 2012

Programming Quotes

Filed under: Quotes — mdahlman @ 21:44

“The type type object is also the mother of all types and is the default metaclass for all standard Python classes. It is perfectly fine if you do not understand this now.”

I quite like this firm reassurance that I shouldn’t get bogged down making sure I understand what he’s saying at this point.
p. 92 Core Python Programming, Wesley J Chu (Second Edition)

27 September 2012

JasperWorld 2012 favorite quote

Filed under: Quotes — Tags: — mdahlman @ 09:09

JasperWorld 2012

Yesterday was the last day of JasperWorld 2012, and it was a big success. Lots of customers, community members, and partners learned (and taught!) lots of new things.

Most of the general sessions were very interesting, but particularly near and dear to my heart was the big data panel.

  • Don DeLoach, Infobright
  • Billy Bosworth, DataStax
  • John Kreisa, HortonWorks
  • Mark Hydar, VoltDB
  • Moderator: Claudia Imhoff, Boulder BI Brain Trust (BBBT)

All panelists provided good insight into big data today and in the next 3 years. But as I’m looking back through my notes now, I found my second favorite quote from the session.

You’d be amazed at what a guy can do with 6 weeks, $50k, and the cloud.
- Billy Bosworth

My favorite quote came immediately after that:

IT hates those guys.
- Billy Bosworth

3 September 2012

Web services POST example

Filed under: JasperReports Server, JasperServer — Tags: , — mdahlman @ 13:49

JasperReports Server Web Services example

I don’t have a lot of experience working with web services and JasperReports Server. I have good knowledge of what they’re capable of achieving, and I know all about the what’s and wherefore’s of SOAP vs REST, but I don’t have a lot of hands-on knowledge from working with them.

And that’s exactly the reason I was so pleased to see this sample earlier today. It came from Java-guru and Jaspersoft-guru Lucian Chiriţă. The customer question which motivated it was someone having difficulties updating an existing user via a POST request. The elegance of the example is that it’s a single command runnable on nearly any system, and it uses a trivially short XML file to hold the sample information.

I hope that this sample makes its way into core JasperReports Server documentation someday soon. But until then, here’s a sample request in case it’s useful for more folks than just this one JasperReports Server customer. First create an XML with this content:

<user>
  <enabled>true</enabled>
  <externallyDefined>false</externallyDefined>
  <fullName>Updated Joe User</fullName>
  <password>secret</password>
  <roles>
    <externallyDefined>false</externallyDefined>
    <roleName>ROLE_USER</roleName>
  </roles>
  <roles>
    <externallyDefined>false</externallyDefined>
    <roleName>ROLE_DEMO</roleName>
  </roles>
 <tenantId>organization_1</tenantId>
 <username>joeuser</username>
</user>

I saved the file as user.data.xml. Then update the sample user “joeuser” using this command:

curl -X POST -u jasperadmin:jasperadmin -H "Content-Type: application/xml" --data-binary @/tmp/user.data.xml "http://localhost:8080/jasperserver-pro/rest/user/joeuser|organization_1"

Joeuser will find that he has a new password and a new fullname the next time he logs in. Starting from a simple example that immediately works, it should be relatively straightforward to develop a real application which uses the JasperReports Server web services REST API.

Older Posts »

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 32 other followers