Difference between revisions of "Retrieve Session information in Script (BIRT)"

From Eclipsepedia

Jump to: navigation, search
(New page: {{Backlink|Report Developer Examples (BIRT)}} This example is [https://bugs.eclipse.org/bugs/show_bug.cgi?id=182208 Bugzilla ID 182208]. If you would like to contribute an example see the...)
 
m
 
(4 intermediate revisions by 2 users not shown)
Line 19: Line 19:
 
  var request = reportContext.getHttpServletRequest();
 
  var request = reportContext.getHttpServletRequest();
 
  var requestAttrMap = new Packages.java.util.Hashtable();
 
  var requestAttrMap = new Packages.java.util.Hashtable();
  var attrNames = request.getAttributeNames();
+
  for (var attrNames = request.getAttributeNames(); attrNames.hasMoreElements(); ) {
do {
+
 
       var aName = attrNames.nextElement();
 
       var aName = attrNames.nextElement();
 
       requestAttrMap.put(aName, request.getAttribute(aName).toString());
 
       requestAttrMap.put(aName, request.getAttribute(aName).toString());
  } while (attrNames.hasMoreElements())
+
  }
 
  topMap.put("requestAttributes", requestAttrMap);
 
  topMap.put("requestAttributes", requestAttrMap);
+
 
  // Request Parameters
 
  // Request Parameters
 
  var requestParamMap = new Packages.java.util.Hashtable();
 
  var requestParamMap = new Packages.java.util.Hashtable();
  var paramIter = request.getParameterMap().entrySet().iterator();
+
  for (var paramIter = request.getParameterMap().entrySet().iterator();
do{
+
      paramIter.hasNext(); ) {
 
       var entry = paramIter.next();
 
       var entry = paramIter.next();
 
       requestParamMap.put(entry.getKey(), (entry.getValue()[0]));
 
       requestParamMap.put(entry.getKey(), (entry.getValue()[0]));
  } while (paramIter.hasNext())
+
  }
 
  topMap.put("requestParameters",requestParamMap);
 
  topMap.put("requestParameters",requestParamMap);
 
   
 
   
Line 43: Line 42:
 
  var sessionAttrNames = session.getAttributeNames();
 
  var sessionAttrNames = session.getAttributeNames();
 
  var i = 0;
 
  var i = 0;
  do  {
+
  while (sessionAttrNames.hasMoreElements()) {
 
       i ++;
 
       i ++;
 
       var aaa = sessionAttrNames.nextElement();
 
       var aaa = sessionAttrNames.nextElement();
 
       sessionAttrMap.put(aaa, session.getAttribute(aaa));
 
       sessionAttrMap.put(aaa, session.getAttribute(aaa));
  } while (sessionAttrNames.hasMoreElements())
+
  }  
 
  topMap.put("sessionAttributes", sessionAttrMap);
 
  topMap.put("sessionAttributes", sessionAttrMap);
 
 
 
 
Line 58: Line 57:
 
 
 
 
 
 
  '''Open'''
+
  '''Open Script for the Scripted Data Set'''
 
  aMap = reportContext.getPersistentGlobalVariable("topMap");
 
  aMap = reportContext.getPersistentGlobalVariable("topMap");
 
  topIter = aMap.entrySet().iterator();
 
  topIter = aMap.entrySet().iterator();
Line 69: Line 68:
  
  
  '''Fetch'''
+
  '''Fetch Script for the Scripted Data Set'''
  do
+
  while (!innerIter.hasNext())
 
  { // find an innerIter that has a new value
 
  { // find an innerIter that has a new value
       if (innerIter == null || innerIter.hasNext() == false)
+
       if (innerIter == null || !innerIter.hasNext())
 
       { // no value in the inner iterator, get the next Hashtable out of the toHashtable
 
       { // no value in the inner iterator, get the next Hashtable out of the toHashtable
 
               if (topIter.hasNext())
 
               if (topIter.hasNext())
Line 84: Line 83:
 
               }
 
               }
 
       }
 
       }
  }  
+
  }
  while (innerIter.hasNext() == false)
+
   
 
+
 
  // we must have another innerIter
 
  // we must have another innerIter
 
  innerObject = innerIter.next();
 
  innerObject = innerIter.next();
 
+
 
  row["propName"] = innerObject.getKey();
 
  row["propName"] = innerObject.getKey();
 
  row["propValue"] = innerObject.getValue().toString();
 
  row["propValue"] = innerObject.getValue().toString();
 
  row["propType"] = outerObject.getKey();
 
  row["propType"] = outerObject.getKey();
  return true;
+
  return true;
 
+
  
 
== Comments ==  
 
== Comments ==  

Latest revision as of 17:50, 27 March 2010

< To: Report Developer Examples (BIRT)
This example is Bugzilla ID 182208. If you would like to contribute an example see the example contribution guidelines.

Contents

[edit] Introduction

This example illustrates retrieving data from session.

[edit] BIRT Version Compatibility

Enter the version of BIRT that was used to build the example.

[edit] Example Files

Add a URL to your bugzilla attachment. eg. Example Report Zipped

[edit] Description

This example collects information from the session in the beforeFactory EventHandler using JavaScript. This information is loaded into a Map. The Map is then parsed in a Scripted Data Source and the results are displayed in the report.

Before Factory
// Create a hash table which will contain lists of other lists
var topMap = new Packages.java.util.Hashtable();

	
// Request Attributes
var request = reportContext.getHttpServletRequest();
var requestAttrMap = new Packages.java.util.Hashtable();
for (var attrNames = request.getAttributeNames(); attrNames.hasMoreElements(); ) {
      var aName = attrNames.nextElement();
      requestAttrMap.put(aName, request.getAttribute(aName).toString());
}
topMap.put("requestAttributes", requestAttrMap);
	
// Request Parameters
var requestParamMap = new Packages.java.util.Hashtable();
for (var paramIter = request.getParameterMap().entrySet().iterator();
     paramIter.hasNext(); ) {
      var entry = paramIter.next();
      requestParamMap.put(entry.getKey(), (entry.getValue()[0]));	
}
topMap.put("requestParameters",requestParamMap);

	
// Session Attributes
var sessionAttrMap = new Packages.java.util.Hashtable();
var session = request.getSession();
// Insert a variable on the session
session.setAttribute("ReportAttribute", "arbitrary value to pass to container");
var sessionAttrNames = session.getAttributeNames();
var i = 0;
while (sessionAttrNames.hasMoreElements()) {
      i ++;
      var aaa = sessionAttrNames.nextElement();
      sessionAttrMap.put(aaa, session.getAttribute(aaa));
} 
topMap.put("sessionAttributes", sessionAttrMap);	
	

// Get the system properties
topMap.put("systemProps", Packages.java.lang.System.getProperties());

// Store top map as a global
reportContext.setPersistentGlobalVariable("topMap", topMap);
	
Open Script for the Scripted Data Set
aMap = reportContext.getPersistentGlobalVariable("topMap");
topIter = aMap.entrySet().iterator();
if (topIter == null)
{
     topIterator = new Packages.java.util.Iterator();
     Packages.java.util.logging.Logger.getLogger("").info("OPEN NULL " );
}
innerIter = null;	


Fetch Script for the Scripted Data Set
while (!innerIter.hasNext()) 
{ // find an innerIter that has a new value
      if (innerIter == null || !innerIter.hasNext())
      { 	// no value in the inner iterator, get the next Hashtable out of the toHashtable
             if (topIter.hasNext())
             {	
                   outerObject = topIter.next(); 
                   innerIter = outerObject.getValue().entrySet().iterator();
             }
             else
             { // no more top hash tables. close things up
                   return false;
             }
      }
}

// we must have another innerIter
innerObject = innerIter.next();

row["propName"] = innerObject.getKey();
row["propValue"] = innerObject.getValue().toString();
row["propType"] = outerObject.getKey();
return true;

[edit] Comments

Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.