Hi All,
I'm trying to convert and OLAPCube creation from MXML to ActionScript
and it's not working. Source code attached.
Any help?
+++++++++++++++++++++
xml file
++++++++++++++++++++
<?xml version="1.0" encoding="utf-8"?>
<RecapSelection>
<Recap name=" Recap by Line/Size Type/Status"
Dim1Attribute="Line" Dim1DataField="line" Dim2Attribute="Size"
Dim2DataField="size" Dim3Attribute="Status" Dim3DataField="status" >
</Recap>
<Recap name="Recap by Line/Size Type/Category"
Dim1Attribute="Line" Dim1DataField="line" Dim2Attribute="Size"
Dim2DataField="size" Dim3Attribute="Category"
Dim3DataField="category">
</Recap>
</RecapSelection>
+++++++++++++++++++++++++++++++++++++++++++
ActionScript Verison
+++++++++++++++++++++++++++++
?xml version="1.0"?>
<!-- olapdatagrid/OLAPDG_Intro.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script>
<![CDATA[
import mx.olap.OLAPCube;
import mx.olap.OLAPHierarchy;
import mx.collections.ICollectionView;
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.messaging.messages.ErrorMessage;
import mx.olap.OLAPQuery;
import mx.olap.OLAPSet;
import mx.olap.IOLAPQuery;
import mx.olap.IOLAPQueryAxis;
import mx.olap.IOLAPCube;
import mx.olap.OLAPResult;
import mx.events.CubeEvent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import mx.olap.OLAPDimension;
import mx.olap.OLAPAttribute;
import mx.olap.OLAPLevel;
import mx.olap.OLAPMeasure;
private var recapCube:OLAPCube =new OLAPCube(); ;
[Bindable]
private var flatData:ArrayCollection = new ArrayCollection(
[
{line:"A", size:"20", status:"F" },
{line:"C", size:"40", status:"F"},
{line:"Z", size:"60",status:"E"},
{line:"D",size:"20",status:"E"},
{line:"M", size:"20", status:"E"},
{line:"M", size:"40", status:"E"},
{line:"Z", size:"60",status:"F"},
{line:"D",size:"20",status:"F"},
{line:"Z", size:"40",status:"E"},
{line:"M", size:"45", status:"E"},
{line:"M", size:"30", status:"E"},
{line:"A", size:"20",status:"E"},
{line:"D",size:"20",status:"E"},
{line:"Z", size:"40",status:"F"},
{line:"A", size:"20", status:"F"},
{line:"A", size:"20", status:"F"}
]);
private function iniData():void
{
recapCube.dataProvider=flatData;
}
private function creationCompleteHandler():void {
/** You must initialize the cube before you
can execute a query on it. **/
iniData();
createCube();
}
[Bindable]
private var dim1Attribute :String;
[Bindable]
private var dim2Attribute :String;
[Bindable]
private var dim3Attribute :String;
/** Create the OLAP query. **/
private function getQuery(cube:IOLAPCube):IOLAPQuery {
/** Create an instance of OLAPQuery to represent the
query. **/
var query:OLAPQuery = new OLAPQuery;
/** Get the row axis from the query instance. **/
var rowQueryAxis:IOLAPQueryAxis =
query.getAxis(OLAPQuery.ROW_AXIS);
/** Create an OLAPSet instance to configure the axis.
**/
var lineSet:OLAPSet = new OLAPSet;
/** Add the line to the row to aggregate data
// by the Line dimension. **/
for (var i:int=0;i<cube.dimensions.length;i++){
trace("dimension "+cube.dimensions[i]);
}
lineSet.addElements(
cube.findDimension("Dim1").findAttribute(dim1Attribute).children);
/** Add the OLAPSet instance to the axis. **/
rowQueryAxis.addSet(lineSet);
/** Get the column axis from the query instance, and
configure it
// to aggregate the columns by the Size dimension. **/
var colQueryAxis:IOLAPQueryAxis =
query.getAxis(OLAPQuery.COLUMN_AXIS);
var sizeSet:OLAPSet= new OLAPSet;
sizeSet.addElements(cube.findDimension("Dim2").findAttribute(dim2Attribute).children);
var statusSet:OLAPSet= new
OLAPSet;statusSet.addElements(cube.findDimension("Dim3").findAttribute(dim3Attribute).children);
colQueryAxis.addSet(sizeSet.crossJoin(statusSet));
trace(" query "+query)
return query;
}
/** Handle a query fault. **/
private function showFault(error:ErrorMessage,
token:Object):void {
Alert.show(error.faultString);
}
/** Handle a successful query by passing the query results
to
// the OLAPDataGrid control.. **/
private function showResult(result:Object, token:Object):void
{
if (!result) {
Alert.show("No results from query.");
return;
}
// myOLAPDG2.dataProvider= result as OLAPResult;
}
private function showValue():void {
dim1Attribute
=recapselection.selectedit...@dim1attribute;
dim2Attribute
=recapselection.selectedit...@dim2attribute;
dim3Attribute
=recapselection.selectedit...@dim3attribute;
Alert.show(dim1Attribute);
}
private function createCube():void{
var ac:ArrayCollection = new ArrayCollection()
var dim1:OLAPDimension = new OLAPDimension("Dim1");
/** add attributes to the dimension **/
var attr1:OLAPAttribute = new
OLAPAttribute(dim1Attribute);
/** attr1.name="Line"; **/
attr1.dataField =
recapselection.selectedit...@dim1datafield;
dim1.attributes = new ArrayCollection([ attr1]);
trace("dim1.attributes "+dim1.attributes.length+"
"+dim1.attributes[0]);
var hier1:OLAPHierarchy = new OLAPHierarchy("Hier1");
hier1.hasAll = true;
/** define the levels of the hierarchy **/
var level1:OLAPLevel = new OLAPLevel();
level1.attributeName =
recapselection.selectedit...@dim1attribute;
/** add levels to the hierarchy **/
hier1.levels = new ArrayCollection([level1]);
/** add hierarchy to the dimension **/
dim1.hierarchies = new ArrayCollection([hier1]);
ac.addItem(dim1);
var dim2:OLAPDimension = new OLAPDimension("Dim2");
/** add attributes to the dimension **/
var attr2:OLAPAttribute = new
OLAPAttribute(dim2Attribute);
/** attr2.name='Size'; **/
attr2.dataField =
recapselection.selectedit...@dim2datafield;
dim2.attributes = new ArrayCollection([ attr2]);
trace("dim2.attributes "+dim2.attributes.length+"
"+dim2.attributes[0]);
var hier2:OLAPHierarchy = new OLAPHierarchy("Hier2");
hier2.hasAll = true;
/** define the levels of the hierarchy **/
var level2:OLAPLevel = new OLAPLevel();
level2.attributeName =
recapselection.selectedit...@dim2attribute;
/** add levels to the hierarchy **/
hier2.levels = new ArrayCollection([ level2]);
/** add hierarchy to the dimension **/
dim2.hierarchies = new ArrayCollection([ hier2 ]);
ac.addItem(dim2);
var dim3:OLAPDimension = new
OLAPDimension("Dim3");
/** add attributes to the dimension **/
var attr3:OLAPAttribute = new
OLAPAttribute(dim3Attribute);
/** attr3.name='Status'; ***/
attr3.dataField =
recapselection.selectedit...@dim3datafield;
dim3.attributes = new ArrayCollection([ attr3]);
trace("dim3.attributes "+dim3.attributes.length+"
"+dim3.attributes[0]);
var hier3:OLAPHierarchy = new OLAPHierarchy("Hier3");
hier3.hasAll = true;
/** define the levels of the hierarchy **/
var level3:OLAPLevel = new OLAPLevel();
level3.attributeName =
recapselection.selectedit...@dim3attribute;
/** add levels to the hierarchy **/
hier3.levels = new ArrayCollection([ level3]);
/** add hierarchy to the dimension **/
dim3.hierarchies = new ArrayCollection([ hier3 ]);
ac.addItem(dim3);
var measure:OLAPMeasure = new OLAPMeasure("Status");
measure.dataField =
recapselection.selectedit...@dim3datafield ;
measure.aggregator="COUNT";
trace("measure.dataField "+measure.dataField);
recapCube.dimensions= ac; //new
ArrayCollection([dim1,dim2,dim3]);
recapCube.measures= new ArrayCollection([measure]);
// recapCube.elements=[dim1,dim2,dim3,measure];
trace ("before running the query");
runQuery();
trace ("after running the query");
recapCube.refresh();
trace("dataprovider
"+recapCube.dataProvider.length);
}
private function runQuery():void {
// Get cube.
var cube:IOLAPCube = IOLAPCube(recapCube);
// Create a query instance.
var query:IOLAPQuery = getQuery(cube);
// Execute the query.
trace ("query "+query);
var token:AsyncToken = cube.execute(query);
// Setup handlers for the query results.
token.addResponder(new AsyncResponder(showResult,
showFault));
}
]]>
</mx:Script>
<mx:XML id="dp" source="RecapSelection.xml" format="e4x" />
<mx:ComboBox id="recapSelection" dataProvider="{dp.Recap}"
labelField="@name" selectedIndex="-1"
prompt="Recap By" change="showValue();creationCompleteHandler(); "/>
<mx:OLAPDataGrid id="myOLAPDG2" width="50%" height="251"
defaultCellString="0" />
</mx:Application>
--
You received this message because you are subscribed to the Google Groups "Flex
India Community" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/flex_india?hl=en.