Sunday, March 29, 2009

Polestar in the cloud Web Services API - Sample Codes Ted Ueda

If you're interested in Polestar in the cloud and the recently announced Polestar in the cloud API $20K IDEAtion Challenge, then this blog entry may be of interest to you. I'm going to present here a few sample codes for that API, so you'll quickly get up to speed and have a head start on the competition!

Each of the sample codes follow the same workflow: retrieve data, upload the dataset to OnDemand, then view it in Polestar in the cloud. What differs is the programming language used and the data source. The four samples are:

  1. Python script with inline dataSet.
  2. C# with data retrieved from Query as a Web Service
  3. Xcelsius SDK - Adobe Flex component.
  4. Java with RSS Feed data.
Polestar in the cloud API

Ty Miller, a Techical Director here, sent me email about a month ago asking whether I was interested in checking out a cool new Web Services API for the BusinessObjects Labs project called Polestar in the cloud. I figured whatever Ty's involved in is high on the hot-and-interesting scale - he's sent a few pretty interesting Customer Support cases my way in the past - but at the time I was busy helping customers and working with Crystal Reports for Eclipse 2.0 and Universe Data Access Driver Development Kit SDK, so I had to flag his email for later action.

Rob Horne, who's also into pretty interesting stuff, recently blogged about Polestar in the cloud. Reading his blog certainly encouraged me to check it out (although I have to say I'm far from a Steve Nash fan), and what I found was pretty impressive.

Polestar makes the relationship between you and your data highly personal - I've gotten tremendous insight, and seen relationships I've not thought of, merely by uploading data and working with it in Polestar. Having Polestar as part of the "Cloud" computing on Whohar - the http://create.ondemand.com/ portal - makes it that much more compelling. Now you can upload and store your data on Whohar, and analyze it using different dashboards as well as Polestar.

Programmatic dataset management is accomplished via the Whohar RESTful Web Services API - you can upload, download, update and delete datasets via simple HTTP calls. You can then invoke a URL to view a dataset in Polestar.

The beauty of the API is in its simplicity - you're able to code against it using most programming languages out there, and have a very elegant means to integrate your app with Polestar in the cloud.

Rob kindly sent me a preview of the Whohar API docs - it's now available publicly here - and I've been playing with the API since. I've cleaned up some of my sample codes and present it here for your enjoyment. I do hope it helps you in quickly working out the API workflow required to integrate your stuff with Polestar in the cloud.

Python Script with Inline DataSet

Here's a short Python script that I used to get a 'feel' for the API -

Python script uploading data to Polestar in the cloud

that shows the basics of uploading a dataSet and viewing it in Polestar: the required XML dataset format, setting up the HTTP Basic Authentication, retrieving the dataSet ID and session ID, and redirecting to Polestar in the cloud.

Edit the top of the file to insert your create.ondemand.com logon credentials, and modify the bottom to use either the webbrowser lib or explicit launching of a web browser, and run it using the Python interpreter.

You'll note how simple the API is - the advantage of using a RESTful Web Services design.

C# With Data Retrieved from Query as a Web Service

A bit more useful example, using C# - I wrote it on Visual Studio 2008 - that consumes data from Query as a Web Service (QaaWS), upload them to Whohar and view in Polestar in the cloud. Here's a screenshot of what you get, showing both the QaaWS client with the query, and the Polestar view of the data:

image

The query is based on the eFashion sample Universe, and Polestar is displaying the breakdown of sales revenue, quanitity of merchandise sold, and margin for stores by State. Texas is looking pretty good (more on Texas later)...

Here's the code:

C# 2008 to upload QaaWS-generated data to Polestar OnDemand

You'll note that much of the code is taken up by the QaaWS SOAP Web Service call - dynamically generating stub code from the WSDL, auto-compiling and loading the assembly, and using Reflection to invoke the service - and not by the OnDemand API.

It may be an unfair comparison, but this does suggest the simplicitly of a RESTful Web Service in comparison to SOAP.

Compile the code using Visual Studio 2008, and run it in the command-line:

QaaWS2Polestar.exe

and it'll launch Internet Explorer with Polestar OnDemand view of your QaaWS data.

A couple of comments about the sample code:

  1. It generates the QaaWS stubs from the WSDL using .NET Service Reference rather than Web Reference. A Service-Reference-generated-code makes for easier Reflection into the stub classes, since you can infer use from the generated property names.
  2. It currently doesn't set any QaaWS prompts - you can add to the Reflection routine near the end of the code to introspect any prompts.
Xcelsius SDK - Adobe Flex Component

I created this sample using Adobe Flex Builder 3 and the Xcelsius SDK. Implementation uses MXML that subclasses a mx:Button component that, when clicked, reads a bound 2D Array, constructs the Whohar dataSet XML, uploads the data and displays it in Polestar in the cloud.

You can use it within an Adobe Flash application or embedded in Xcelsius. Here's a screenshot of it embedded within Xcelsius, showing both the Polestar and Xcelsius views of the data:

image

When you click on the "To Polestar OnDemand" button you see on the Xcelsius view, the Polestar OnDemand view is displayed.The data is just some test data I entered into Excel in the Xcelsius designer - in actual practise, you'd be using 'real' Excel data, or a Web Service data source.

Here's the MXML code:

PolestarOnDemand.xml - uploads bound Array to Polestar in the cloud

and the MXML for the Logon dialog box it uses to collect the OnDemand logon credentials:

PolestarOnDemandLogon.xml - Logon dialog box for PolestarOnDemand.xml

Note that the data the component uploads is bound to an 2D array. Here's a very simple Xcelsius Property Sheet MXML that will allow you to do the binding to Excel cell ranges from within Xcelsius:

PolestarOnDemandPropertySheet.mxml - Xcelsius Property Sheet for PolestarOnDemand.xml

You can also use the component outside of Xcelsius and within a Flex application. Here's a short sample of how you'd invoke PolestarOnDemand.mxml from a mx:Application:

PolestarOnDemandApp.mxml - embedding PolestarOnDemand.mxml component

Some comments:

  1. The code passes the parameter suppress_response_codes in the Whohar URL to have responses always return HTTP 200 (other than HTTP 5xx errors). This feature was added specifically for Flex running in Internet Explorer. The normal RESTful HTTP 201 (Created) return on new dataset creation throws an exception in Internet Explorer, preventing Flex from reading the returned new resource location.
  2. Xcelsius SDK currently supports Flex 2 only - so in Flex Builder 3, ensure you set the compiler for your project to use version 2 rather than 3.
  3. Flex 2 does not contain a library class for Base64 encoding - I used one of the many open source Base64 implementations for ActionScript available on the web.
  4. Xcelsius supports MXML components via the Xcelsius SDK only starting with FixPack 1.1 (previously, you had to code using ActionScript). I tested this component using Service Pack 1 + FixPack 1.2.
  5. I didn't Style the component for Xcelsius - if you want to specify fonts and colors for the component in Xcelsius, you'd need to specify styling in the code. I recommend looking at the ComboBox sample for an example on how to property style a Xcelsius SDK component.
Java With RSS Feed Data

Last example - retrieve data from Yahoo! HotJobs RSS Feed, upload and view in PoleStar OnDemand. I always wanted to be a spaceman, so I enter 'astronaut' for the HotJobs keyword, and this is the Polestar in the cloud result:

image

All the astronaut-related jobs are located in Texas! Most in Houston (as in "Houston, we've got a problem") and a couple in Galveston. So that means I have to be willing to relocate if I want to fulfill my childhood career aspiration. Oh, well, I think I better stick to more realistic keywords like 'programmer', 'developer', or 'cowboy'. Maybe I should learn to ride a horse first...

Anyways, here's the Java code:

JobLocationPolestar.java - Polestar in the cloud with data from Yahoo! HotJobs RSS Feed

It's a command-line app where the first argument is the HotJobs keyword and second and third arguments are the OnDeman logon credentials.

It uses the Project ROME RSS Java library to retrieve the feed.

Whohar itself has a RSS feed reader, so you don't necessarily have to use the API to upload RSS entry data into Whohar. For this task, however, I wanted to post-process the data after retrieving it from Yahoo! and before uploading. Specifically, I wanted to parse the Job Title fields to derive the job location city and State.

Summary

The Polestar in the cloud and Whohar API has such ease-of-use that you can call it from almost any application. In this blog entry, I illustrated how you'd upload data and display it in Polestar using four different programming languages.

I'm sure you'll be able to think of much more compelling uses for it than the examples I've given above. If so, I highly recommend immediately going to the Polestar in the cloud API $20K IDEAtion Challenge site and signing yourself up for a chance to win some recognition for your idea! The cash would be a nice bonus, too...

Hope you find this entry informative, and the sample codes allow you to quickly get up-to-speed with the Polestar in the cloud API.

Ted Ueda is a Senior Engineer with Technical Customer Assurance, SAP Business Objects.