1 33 34 package it.businesslogic.ireport.data; 35 36 import it.businesslogic.ireport.FieldsProviderEditor; 37 import it.businesslogic.ireport.IReportConnection; 38 import it.businesslogic.ireport.connection.JRXMLADataSourceConnection; 39 import it.businesslogic.ireport.gui.ReportQueryDialog; 40 import java.util.Map ; 41 import net.sf.jasperreports.engine.JRDataset; 42 import net.sf.jasperreports.engine.JRException; 43 44 import net.sf.jasperreports.engine.JRField; 45 import net.sf.jasperreports.engine.design.JRDesignField; 46 47 51 public class CincomMDXFieldsProvider extends MDXFieldsProvider { 52 53 private final String axis0 = "Axis0"; 54 private final String axis1 = "Axis1"; 55 private final String slicer = "SlicerAxis"; 56 private final char leftPar='['; 57 private final char rightPar=']'; 58 public static java.util.ArrayList dimensionsList = new java.util.ArrayList (); 59 private boolean foundMeasure; 61 62 public CincomMDXFieldsProvider() { 63 super(); 64 } 65 66 public boolean supportsGetFieldsOperation() { 67 return true; 68 } 69 70 public boolean supportsAutomaticQueryExecution() { 71 return true; 72 } 73 74 public boolean hasEditorComponent() { 75 return false; 76 } 77 78 public FieldsProviderEditor getEditorComponent(ReportQueryDialog reportQueryDialog) { 79 80 return null; 81 } 82 83 public JRField[] getFields(IReportConnection con, JRDataset reportDataset, Map parameters) throws JRException, UnsupportedOperationException { 84 89 if (con instanceof it.businesslogic.ireport.connection.JRXMLADataSourceConnection) 90 { 91 try { 92 String query = reportDataset.getQuery().getText(); 93 94 java.util.ArrayList v_fields = getFields(query, (JRXMLADataSourceConnection)con); 95 96 JRField[] final_fields = new JRField[v_fields.size()]; 98 for (int i=0; i<v_fields.size(); ++i) 99 { 100 XmlaFieldNode f = (XmlaFieldNode)v_fields.get(i); 101 JRDesignField field = new JRDesignField(); 102 field.setName( f.getName() ); 103 field.setValueClassName( f.getClassType() ); 104 field.setDescription( f.getDescription() ); 105 final_fields[i] = field; 106 } 107 108 return final_fields; 109 110 111 } catch (Exception ex) 112 { 113 throw new JRException(ex); 114 } 115 } 116 else 117 { 118 throw new JRException("The active connection is not of type XMLA. Activate an XMLA connection first."); 119 } 120 } 121 122 123 134 public java.util.ArrayList getFields(String query, JRXMLADataSourceConnection con) throws java.lang.Exception 135 { 136 foundMeasure = false; 137 it.businesslogic.ireport.data.XmlaFieldNode fld2; 138 java.util.ArrayList fields = new java.util.ArrayList (); 139 rex.metadata.ServerMetadata smd = 140 new rex.metadata.ServerMetadata(con.getUrl(),null); 141 if (smd.isValidUrl() == false) { 142 return null; 143 } 144 rex.xmla.RexXMLAExecuteProperties rexProperties = new rex.xmla.RexXMLAExecuteProperties(); 145 rexProperties.setDataSourceInfo(con.getDatasource()); 146 rexProperties.setCatalog(con.getCatalog()); 147 this.dimensionsList.clear(); 148 try { 149 rex.metadata.ExecuteResult eResult = 150 new rex.metadata.ExecuteResult(smd.execute(query,rexProperties),null); 151 if (!addMDXAxisColumns(fields, eResult, axis0)){ 152 return null; 153 } 154 if (!addMDXAxisColumns(fields, eResult, axis1)){ 155 return null; 156 } 157 if (!addMDXAxisColumns(fields, eResult, slicer)){ 158 return null; 159 } 160 if (!foundMeasure) { 162 fld2 = new it.businesslogic.ireport.data.XmlaFieldNode( 163 "DefaultMeasure", 2); 164 fld2.setDescription("DefaultMeasure"); 165 166 fields.add(fld2); 167 } 168 eResult = null; 169 rexProperties = null; 170 smd = null; 171 } 172 173 catch(Exception e){ 174 throw e; 175 } 176 return fields; 177 } 178 179 191 private boolean addMDXAxisColumns(java.util.ArrayList fields, 192 rex.metadata.ExecuteResult eResult, 193 String axisName) 194 { 195 java.util.HashSet fSet = new java.util.HashSet (); 196 197 198 int axisNo=-1; 199 if (eResult == null || fields == null || axisName == null ){ 200 return false; 201 } 202 if ((axisName.compareTo(axis0) != 0) && 203 (axisName.compareTo(axis1) !=0) && 204 (axisName.compareTo(slicer) !=0)){ 205 return false; 206 } 207 rex.metadata.resultelements.Axis axis = 208 eResult.getAxis(axisName); 209 if (axis == null){ 210 return false; 211 } 212 rex.metadata.resultelements.HierarchyInfo hierInfo; 213 rex.metadata.resultelements.Tuple tuple; 214 215 216 if (axisName.compareTo(axis0) == 0) { 217 axisNo = 0; 218 } else { 219 axisNo = 1; 220 } 221 tuple = null; 222 223 it.businesslogic.ireport.data.XmlaFieldNode fld; 224 String longName= ""; 225 String shortName = ""; 226 227 int hierarchyCount = axis.getHierarchyInfoCount(); 228 for (int hierIndex=0;hierIndex<hierarchyCount;hierIndex++) { 229 hierInfo = axis.getHierarchyInfoAt(hierIndex); 230 if (hierInfo == null){ 231 return false; 232 } 233 234 int tupleCount = axis.getTupleCount(); for (int tupleIndex=0; tupleIndex< tupleCount; tupleIndex++){ 236 tuple = axis.getTupleAt(tupleIndex); 237 int tupleMemberCount = tuple.getMemberCount(); 240 for (int tupleMemberIndex=0;tupleMemberIndex<tupleMemberCount;tupleMemberIndex++) { 241 if (tuple.getMemberAt(tupleMemberIndex).isMeasure()) { 242 foundMeasure = true; 243 244 longName= tuple.getMemberAt(tupleMemberIndex).getUniqueName(); 245 246 shortName= longName.substring(longName.lastIndexOf(leftPar)+1, 247 longName.lastIndexOf(rightPar)); 248 249 250 252 253 if (!fSet.contains(shortName)) { 254 255 256 fld = new it.businesslogic.ireport.data.XmlaFieldNode( 257 shortName, axisNo); 258 fld.setDescription(longName); 259 fSet.add(shortName); 260 261 fields.add(fld); 264 } 268 } else{ 269 270 longName= tuple.getMemberAt(tupleMemberIndex).getLname(); 271 272 shortName= longName.substring(longName.lastIndexOf(leftPar)+1, 273 longName.lastIndexOf(rightPar)); 274 if (!fSet.contains(shortName)) { 275 fld = new it.businesslogic.ireport.data.XmlaFieldNode( 276 shortName,axisNo); 277 fld.setDescription(longName); 278 fSet.add(shortName); 279 280 282 fields.add(fld); 284 285 if(!this.dimensionsList.contains(fld)){ 286 this.dimensionsList.add(fld); 287 } 288 289 292 297 } 298 } 299 } 300 } 301 302 } 303 return true; 304 } 305 308 public static java.util.ArrayList getDimensions(){ 309 return dimensionsList; 310 } 311 } 312 | Popular Tags |