Friday, June 26, 2009

Kaleidoscope 2009 Hands on Lab - Oracle Essbase Java API - The Basics (S655)

The goal of this lab was to introduce the to Essbase Java API and teach the basics.  It walked through the following:

  • Setting up J-Developer to work with the Essbase Java API (check out my earlier blog on this topic)
  • Connecting to Essbase
  • Creating a grid view (grid API, similar to what the classic add-in uses)
  • Filling in and querying the grid view
  • Basic output of the results

The Essbase Java API objects covered in this lab:

  • IEssbase - The Essbase API instance object.
  • IEssOlapServer - The connection to the Essbase server.
  • IEssCube - The Essbase cube object.
  • IEssCubeView & IEssGridView - The Essbase grid API.

If you did not get a chance to sign up for this hands on lab or just want to try it you can get the lab here.

Please note that this lab was based on a pre-built image so some of the directories, URL's, username,etc. will vary.

Here is the complete code for the lab:

package myproject;

import com.essbase.api.base.*;
import com.essbase.api.dataquery.*;
import com.essbase.api.session.*;
import com.essbase.api.datasource.*;


public class Essbase {
private static String username = "admin";
private static String password = "password";
private static String essbaseServer = "localhost";
private static String provider = "http://localhost:13080/aps/JAPI";
private static String application = "Sample";
private static String database = "Basic";

public Essbase() {
}

public static void main(String[] args) {
IEssbase essbase = null;

try {
essbase = IEssbase.Home.create(IEssbase.JAPI_VERSION);
IEssOlapServer olapServer = essbase.signOn(username,password,
false,null,provider,essbaseServer);
IEssCube cube = olapServer.getApplication(application).getCube(database);
IEssCubeView cubeView = cube.openCubeView("default");
cubeView.setAliasNames(true);
cubeView.updatePropertyValues();

IEssGridView gridView = cubeView.getGridView();
gridView.setSize(3,5);
gridView.setValue(0,2,"Product");
gridView.setValue(0,3,"Market");
gridView.setValue(1, 2, "Jan");
gridView.setValue(1, 3, "Feb");
gridView.setValue(1, 4, "Mar");
gridView.setValue(2, 0, "Actual");
gridView.setValue(2, 1, "Sales");

IEssOperation essOp = cubeView.createIEssOpRetrieve();
cubeView.performOperation(essOp);

int rowCount = gridView.getCountRows();
int colCount = gridView.getCountColumns();
for (int i = 0; i < rowCount; i++) {
for (int j = 0; j < colCount; j++) {
System.out.print(gridView.getStringValue(i, j) + "\t");
}
System.out.print("\n");
}


}
catch(EssException e)
{
System.out.println("Error: " + e.getMessage());
}
finally
{
try
{
if (essbase != null && essbase.isSignedOn() == true) essbase.signOff();
}
catch (EssException e1)
{
System.err.println("Error: " + e1.getMessage());
}
}
}

}


You can download the lab here.

6 comments:

Robert said...

Matt, are you able to post the OutlineExtractor code? I need to do something very similar to support a downstream application from Essbase that relies on the hierarchy.

Thanks,
Robert

Matt Milella said...

I have that on the to do list for this week and hopefully I can get to it... It will get up here is just a matter of time.

Chuck said...

The sample code creates a "provider" variable that refers to some kind of web server on port 13080. What is this? I'm currently on Essbase 7X.

Matt Milella said...

This is the URL to provider services (APS) and it where the JAPI is located. If you use the 'embedded' method to connect to Essbase you do not need this.

GlennS said...

Matt,
the link to get the Lab code at the bottom of the post appears to be broken. Can you give us a good location to download it from?
Thanks
Glenn

Matt Milella said...

http://mmilella.startlogic.com/files/ODTUG/Hands-On%20Lab%20-%20Oracle%20Essbase%20Java%20API%20-%20The%20Basics.pdf

I updated the post sorry about the bad link.