Home
Analytics
Handling Hashmap for grouped report
Anil Misra
Hi All,
I am a newbie and am am trying to generate a BIRT report using scripted dataset to access a POJO.
The BIRT version i am using is 2.6.2 . The report design is as following:
label1 label2 label3 label4
Key1
value1 , value 2, value 3
key2
value1, value 2, value3
In the fetch script how would i use a Java HashMap to fill in the values in the report. Any help is greatly appreciated.
Thanks,
-Anil
Find more posts tagged with
Comments
mwilliams
Anil,
You would just step through your hash map and assign the different properties of each key to different row["fieldName"] variables. Then the dataSet would be used to feed data to your table in your design.
Anil Misra
Hi Michael,
i am attaching the report design and the java objects i am trying to use in the report. I am stuck at how to iterate and fill the report elements with the hashmap of reportbean. Look forward to comments.
Thanks,
-Anil
Anil Misra
Hi Michael,
I made some progress in writing the fetch script , The following helped in getting some data :
===========================
<property name="dataSource">MyDataSource</property>
<method name="open"><![CDATA[favoritesClass = new Packages.NewSimpleClass();
favorites = favoritesClass.readData();
iter = favorites.entrySet().iterator();
iter1 = favorites.keySet().iterator();]]></method>
<method name="fetch"><![CDATA[if( iter1.hasNext() ){
myObject = iter1.next();
row["VENDOR"] = myObject;
newObject = favorites.get(myObject);
iter2 = newObject.iterator();
if( iter2.hasNext()){
someObject = iter2.next();
row["SERVICE"] = someObject.getServiceName();
row["BIWEEKLY"] = someObject.getBiweekly();
row["YEARLY"] = someObject.getYearly();
row["WEEKLY"] = someObject.getWeekly();
}
return true;
}else{
return false;
}]]></method>
<method name="close"><![CDATA[favoritesClass = null;
favorites = null;]]></method>
</script-data-set>
</data-sets>
=====================================
but now it does not show the second level of data in the hashmap. What do i need to do to get the second and beyond data shown. Your comments appreciated.
Thanks,
-Anil
mwilliams
So, you're essentially only getting 1 row of data with the current code? If so, you may need to determine the size of the hashmap in your open script to help you loop through it.
Anil Misra
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="77863" data-time="1306953363" data-date="01 June 2011 - 11:36 AM"><p>
So, you're essentially only getting 1 row of data with the current code? If so, you may need to determine the size of the hashmap in your open script to help you loop through it.<br /></p></blockquote>
<br />
Hi Michael,<br />
<br />
I am able to get the following view :<br />
<br />
Report Header <br />
Vendor Service Biweekly Yearly Weekly <br />
FirstWeb <br />
Web2 20 2000 200 <br />
<br />
SecondWeb <br />
Web4 40 4000 400 <br />
<br />
ThirdWeb <br />
Web6 20 2000 200 <br />
<br />
I am able to loop trough the keylist but it is not looping through the "ReportBean" array that is set as the value for each key value pair. It is overwriting the row <br />
<br />
like it should print :<br />
FirstWeb <br />
Web1 4 1000 10 ( this row is Missing ) <br />
<br />
Web2 20 2000 200<br />
<br />
and so on.<br />
<br />
i am not able to figure out how to loop in the arraylist that is inside the hashmap. Look forward to your comments. <br />
<br />
Thanks,<br />
-Anil
mwilliams
Anil,
If they're always going to be in pairs, you could handle this with another variable that is checked for you to display the first of the pairs, increment your variable, fetch runs again, goes through the second loop, then reset your variable and increment your key value. Hope this makes sense. If they're not always in pairs, you'd do something similar, but dynamically check the length and handle the check on the value in your fetch script. Let me know if I'm misunderstanding.
althi
<blockquote class='ipsBlockquote' data-author="'anilmisra'" data-cid="77868" data-time="1306956329" data-date="01 June 2011 - 12:25 PM"><p>
Hi Michael,<br />
<br />
I am able to get the following view :<br />
<br />
Report Header <br />
Vendor Service Biweekly Yearly Weekly <br />
FirstWeb <br />
Web2 20 2000 200 <br />
<br />
SecondWeb <br />
Web4 40 4000 400 <br />
<br />
ThirdWeb <br />
Web6 20 2000 200 <br />
<br />
I am able to loop trough the keylist but it is not looping through the "ReportBean" array that is set as the value for each key value pair. It is overwriting the row <br />
<br />
like it should print :<br />
FirstWeb <br />
Web1 4 1000 10 ( this row is Missing ) <br />
<br />
Web2 20 2000 200<br />
<br />
and so on.<br />
<br />
i am not able to figure out how to loop in the arraylist that is inside the hashmap. Look forward to your comments. <br />
<br />
Thanks,<br />
-Anil<br /></p></blockquote>
<br />
Hi Anil / Michael,<br />
<br />
I am new to birt reporting.. I would like to know to include a java code in "Fetch" script.<br />
For example I would like store the variables in Hash Map and need to get information from map.<br />
I am able to add the java code in Before Factory script method. Could you please share me sample code where I can add java code in birt script.<br />
<br />
Thanks in advance<br />
<br />
Thanks<br />
Anaand
mwilliams
Hi Anaand,
When you're using a scripted dataSet, your steps are essentially this:
In the open method, connect to your data and bring it into BIRT. Next, create a variable called totalRows that checks the size or length of your object. Then, create a variable called currentRow and set it to 0.
In your fetch method, you then step through your object with code something like:
if (currentRow < totalRows){
row["property1"] = myArray[currentRow].property1;
row["property2"] = myArray[currentRow].property2;
currentRow++;
return (true);
}
else{
return (false);
}
Hope this answers your question. Let me know if I'm not understanding!