/** * Returns the Fields discovered for the MDX Query * * @param : Query String * @param : status is added to return the appropriate field values Reason : to handle the Wizard * Dialog and ReportQuery Dialog issue ReportQueryDialog looks for a jTable / ArrayList * WizardDialog looks for a jList / List status == true implies that the call is from * WizardDialog false imples that the call is from ReportQueryDialog. */ public java.util.ArrayList getFields(String query, JRXMLADataSourceConnection con) throws java.lang.Exception { foundMeasure = false; it.businesslogic.ireport.data.XmlaFieldNode fld2; java.util.ArrayList fields = new java.util.ArrayList(); rex.metadata.ServerMetadata smd = new rex.metadata.ServerMetadata(con.getUrl(), null); if (smd.isValidUrl() == false) { return null; } rex.xmla.RexXMLAExecuteProperties rexProperties = new rex.xmla.RexXMLAExecuteProperties(); rexProperties.setDataSourceInfo(con.getDatasource()); rexProperties.setCatalog(con.getCatalog()); this.dimensionsList.clear(); try { rex.metadata.ExecuteResult eResult = new rex.metadata.ExecuteResult(smd.execute(query, rexProperties), null); if (!addMDXAxisColumns(fields, eResult, axis0)) { return null; } if (!addMDXAxisColumns(fields, eResult, axis1)) { return null; } if (!addMDXAxisColumns(fields, eResult, slicer)) { return null; } // if no measure was explicitly parsed, then add one to pick up the default (ALL) measure: if (!foundMeasure) { fld2 = new it.businesslogic.ireport.data.XmlaFieldNode("DefaultMeasure", 2); fld2.setDescription("DefaultMeasure"); fields.add(fld2); } eResult = null; rexProperties = null; smd = null; } catch (Exception e) { throw e; } return fields; }
/** * Adds all the Dimensions and measures found on Rows, Columns and Slicer axis * * @param fields : All the dimension / measures discovered are added and returned * @param : status is added to return the appropriate field values Reason : to handle the Wizard * Dialog and ReportQuery Dialog issue ReportQueryDialog looks for a jTable / ArrayList * WizardDialog looks for a jList / List status == true implies that the call is from * WizardDialog false imples that the call is from ReportQueryDialog. */ private boolean addMDXAxisColumns( java.util.ArrayList fields, rex.metadata.ExecuteResult eResult, String axisName) { java.util.HashSet fSet = new java.util.HashSet(); int axisNo = -1; if (eResult == null || fields == null || axisName == null) { return false; } if ((axisName.compareTo(axis0) != 0) && (axisName.compareTo(axis1) != 0) && (axisName.compareTo(slicer) != 0)) { return false; } rex.metadata.resultelements.Axis axis = eResult.getAxis(axisName); if (axis == null) { return false; } rex.metadata.resultelements.HierarchyInfo hierInfo; rex.metadata.resultelements.Tuple tuple; if (axisName.compareTo(axis0) == 0) { axisNo = 0; } else { axisNo = 1; } tuple = null; it.businesslogic.ireport.data.XmlaFieldNode fld; String longName = ""; String shortName = ""; int hierarchyCount = axis.getHierarchyInfoCount(); for (int hierIndex = 0; hierIndex < hierarchyCount; hierIndex++) { hierInfo = axis.getHierarchyInfoAt(hierIndex); if (hierInfo == null) { return false; } int tupleCount = axis.getTupleCount(); // ham 9/11/06 for (int tupleIndex = 0; tupleIndex < tupleCount; tupleIndex++) { tuple = axis.getTupleAt(tupleIndex); // following loop for multiple dimensions in one (slicer) tuple // references within this loop to getMemberAt(0) were changed to // getMemberAt(tupleMemberIndex) int tupleMemberCount = tuple.getMemberCount(); for (int tupleMemberIndex = 0; tupleMemberIndex < tupleMemberCount; tupleMemberIndex++) { if (tuple.getMemberAt(tupleMemberIndex).isMeasure()) { foundMeasure = true; longName = tuple.getMemberAt(tupleMemberIndex).getUniqueName(); shortName = longName.substring( longName.lastIndexOf(leftPar) + 1, longName.lastIndexOf(rightPar)); // following IF and adding it to FSET added for duplicate fields in query problem if (!fSet.contains(shortName)) { fld = new it.businesslogic.ireport.data.XmlaFieldNode(shortName, axisNo); fld.setDescription(longName); fSet.add(shortName); // Checking the status and add the appropirte values to fields // if (status.booleanValue()){ //this incase of WizardDialog fields.add(fld); // } else{ //case of ReportQueryDialog // fields.add(new Object[]{fld,fld.getClassType(),fld.getDescription()}); // } } } else { longName = tuple.getMemberAt(tupleMemberIndex).getLname(); shortName = longName.substring( longName.lastIndexOf(leftPar) + 1, longName.lastIndexOf(rightPar)); if (!fSet.contains(shortName)) { fld = new it.businesslogic.ireport.data.XmlaFieldNode(shortName, axisNo); fld.setDescription(longName); fSet.add(shortName); // Checking the status and add the appropirte values to fields // if (status.booleanValue()){ //this incase of WizardDialog fields.add(fld); if (!this.dimensionsList.contains(fld)) { this.dimensionsList.add(fld); } // } else{ //case of ReportQueryDialog // fields.add(new Object[]{fld,fld.getClassType(),fld.getDescription()}); // if(!this.dimensionsList.contains(fld)){ // this.dimensionsList.add(new // Object[]{fld,fld.getClassType(),fld.getDescription()}); // } // } } } } } } return true; }