Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Scripted Data Set
kosta
Hello BIRT community,<br />
<br />
one question about scripted data set:<br />
<br />
how can I convert nested objects list into scripted data set?<br />
<br />
I want to be sure that the data set must have flat structure.<br />
<br />
For example:<br />
java class A hast list of objects B and class B hast list of objets C.<br />
What I know is that the data set should be flat means I need to convert this nested structure into a flat list.<br />
<br />
some pseudo code here:<br />
<br />
<strong class='bbc'>from</strong><br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
name A
name B1
name C1
name C2
name B2
name C1
name C2
</pre>
<strong class='bbc'>to</strong><br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
name A name B1 name C1
name A name B1 name C2
name A name B2 name C1
name A name B2 name C2
</pre>
<br />
Is there better solution for this case were I dont need to do this kind of conversion?<br />
<br />
For any suggestions thanks in advance.
Find more posts tagged with
Comments
mwilliams
I would assume you'd just have to step through each nested object as you go, storing the outer object values in temporary variables as you define rows in the most inner object loop. What are you trying to do? How are your objects linked? Can you define a similar nested set of objects that you can send to me that I can help you set up? For simplification, you could create a report and define objects with dummy data in the open method of a scripted dataSet, so we can easily pass the report on here. If I'm misunderstanding something, let me know.
kosta
With nested objects I thought list in list nothing more. I dont know the right syntax for some scripting example but I ll post some java code here.<br />
<br />
<strong class='bbc'>class C</strong>:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
package myCollection;
public class C {
private String name;
public C(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
</pre>
<br />
<strong class='bbc'>class B</strong>:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
package myCollection;
import java.util.ArrayList;
import java.util.List;
public class B {
private String name;
private List<C> cObjectList = new ArrayList<C>();
public B(String name, List<C> cObjectList) {
super();
this.name = name;
this.cObjectList = cObjectList;
}
public List<C> getbObjectList() {
return cObjectList;
}
public void setbObjectList(List<C> bObjectList) {
this.cObjectList = bObjectList;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
</pre>
<br />
<strong class='bbc'>class A</strong>:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
package myCollection;
import java.util.ArrayList;
import java.util.List;
public class A {
private String name;
private List<B> bObjectList = new ArrayList<B>();
public A(String name, List<B> bObjectList) {
super();
this.name = name;
this.bObjectList = bObjectList;
}
public List<B> getbObjectList() {
return bObjectList;
}
public void setbObjectList(List<B> bObjectList) {
this.bObjectList = bObjectList;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
</pre>
<br />
<strong class='bbc'>class Main</strong>:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
package myCollection;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
A objA0 = new A("nameA0", getBList(getCList()));
A objA1 = new A("nameA1", getBList(getCList()));
A objA2 = new A("nameA2", getBList(getCList()));
List<A> objAList = new ArrayList<A>();
objAList.add(objA0);
objAList.add(objA1);
objAList.add(objA2);
for (A a : objAList) {
for (B b : a.getbObjectList()) {
for (C c : b.getbObjectList()) {
System.out.println(a.getName() + " " + b.getName() + " " + c.getName());
}
}
}
}
public static List<C> getCList() {
C objC0 = new C("cName0");
C objC1 = new C("cName1");
C objC2 = new C("cName2");
List<C> objCList = new ArrayList<C>();
objCList.add(objC0);
objCList.add(objC1);
objCList.add(objC2);
return objCList;
}
public static List<B> getBList(List<C> objCList) {
B objB0 = new B("nameB0", objCList);
B objB1 = new B("nameB1", objCList);
B objB2 = new B("nameB2", objCList);
List<B> objBList = new ArrayList<B>();
objBList.add(objB0);
objBList.add(objB1);
objBList.add(objB2);
return objBList;
}
}
</pre>
<br />
Its a simple example of nested objects as lists.<br />
How would you create the scripted data for this objects so they should be presented as table or list with groups.<br />
<br />
The objects that I use have also sorting number and data which are used for grouping. These objects here have only one property and that is the name.<br />
<br />
Thanks in advance.
mwilliams
From just looking at it and not being able to test, it looks like you'd probably want to flatten the object in your open script before stepping through the flattened object in your fetch script. This would probably make things much easier on you.
sbhayani
Hi Williams,
I have the same structure for POJO as describe above,
I want to generate report from this structure using "ScriptedDataSetEventAdapter" with scripted data source .
Can you please help in this ?
I am new to BIRT .
Thanks .
mwilliams
The way I did it, that made the fetch script the easiest, was to flatten out the lists into an array of arrays to make the rows out of in the open script, then I simply stepped through my array in the fetch script assigning the correct row value to the correct row, out of the inner array.
sbhayani
Ok ,
Can you please add here your fetch and open script (code)?
Thanks .....
mwilliams
Sure. Here you go:<br />
<br />
open:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.myCollection);
myData = new Array(3);
myData[0] = new A("nameA0", Main.getBList(Main.getCList()));
myData[1] = new A("nameA1", Main.getBList(Main.getCList()));
myData[2] = new A("nameA2", Main.getBList(Main.getCList()));
dsData = [];
for (a=0; a < myData.length; a++){
for (b=0; b < myData[a].getbObjectList().size(); b++){
for (c=0; c < myData[a].getbObjectList().get( b ).getbObjectList().size(); c++){
temp = [];
temp[0] = myData[a].getName();
temp[1] = myData[a].getbObjectList().get( b ).getName();
temp[2] = myData[a].getbObjectList().get( b ).getbObjectList().get(c).getName();
dsData[dsData.length] = temp;
}
}
}
currentRow = 0;
totalRows = dsData.length;
</pre>
<br />
fetch:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if (currentRow < totalRows){
row["A"] = dsData[currentRow][0];
row["B"] = dsData[currentRow][1];
row["C"] = dsData[currentRow][2];
currentRow++;
return(true);
}
return(false);
</pre>
<br />
Hopefully this helps.
Pandiyan
Hi,<br />
<br />
Thanks for your response...(i am also having same problem)<br />
<br />
the solution could be help for sample but the solution can't help for real time problems because the data fetching from DB we can't not image the data volume. please suggest any other way..<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="107001" data-time="1341597678" data-date="06 July 2012 - 11:01 AM"><p>
Sure. Here you go:<br />
<br />
open:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.myCollection);
myData = new Array(3);
myData[0] = new A("nameA0", Main.getBList(Main.getCList()));
myData[1] = new A("nameA1", Main.getBList(Main.getCList()));
myData[2] = new A("nameA2", Main.getBList(Main.getCList()));
dsData = [];
for (a=0; a < myData.length; a++){
for (b=0; b < myData[a].getbObjectList().size(); b++){
for (c=0; c < myData[a].getbObjectList().get( b ).getbObjectList().size(); c++){
temp = [];
temp[0] = myData[a].getName();
temp[1] = myData[a].getbObjectList().get( b ).getName();
temp[2] = myData[a].getbObjectList().get( b ).getbObjectList().get(c).getName();
dsData[dsData.length] = temp;
}
}
}
currentRow = 0;
totalRows = dsData.length;
</pre>
<br />
fetch:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
if (currentRow < totalRows){
row["A"] = dsData[currentRow][0];
row["B"] = dsData[currentRow][1];
row["C"] = dsData[currentRow][2];
currentRow++;
return(true);
}
return(false);
</pre>
<br />
Hopefully this helps.<br /></p></blockquote>
mwilliams
Can you explain your issue in a little more detail?
Pandiyan
Hi MWilliams,<br />
<br />
Please refer my issues on the URL, <a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/index.php/topic/28516-subreports-with-scripted-dataset-using-handiler-class/page__pid__112832__st__0&#entry112832'>http://www.birt-exchange.org/org/forum/index.php/topic/28516-subreports-with-scripted-dataset-using-handiler-class/page__pid__112832__st__0&#entry112832</a><br
/>
<br />
The post has one subrepot and its handler classes but now i am able to generate one the report data with one subreprot.<br />
<br />
Actually my requirement has 5 more subreprot for a main transaction. I am getting first subreprot result only remaining subreport details are not generator in output pdf file.<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="112824" data-time="1356715766" data-date="28 December 2012 - 10:29 AM"><p>
Can you explain your issue in a little more detail?<br /></p></blockquote>