1 package com.calipso.reportgenerator.reportmanager; 2 3 import com.calipso.reportgenerator.common.*; 4 import com.calipso.reportgenerator.reportdefinitions.types.ReportDefinitionReportTypeType; 5 import com.calipso.reportgenerator.reportdefinitions.types.FilterDefinitionFilterTypeType; 6 import com.calipso.reportgenerator.common.InfoException; 7 8 import java.util.*; 9 10 17 18 public class CubeReport extends Report { 19 20 private transient ExecutedQueryCollection queryCollection; 21 private HeaderTableModel rowsModel; 22 private HeaderTableModel columnsModel; 23 private Vector dataVector; 24 private ReportQuery query; 25 26 public CubeReport() throws InfoException{ 27 } 28 29 public CubeReport(ReportSpec reportSpec, ReportSource reportSource, ReportGeneratorConfiguration configuration) throws InfoException { 30 super(reportSpec, reportSource, configuration); 31 initialize(); 32 } 33 34 39 private void initialize() throws InfoException { 40 try { 41 setReportData(new CubeReportData(getReportSpec())); 42 } catch (Exception e) { 43 throw new InfoException(LanguageTraslator.traslate("48"), e); 44 } 45 } 46 47 public String getXml() throws InfoException { 48 ReportXmlWriter resultWriter = new CubeReportXmlWriter(getReportData(), getReportSpec(), getQuery().getParamValues(), query); 49 return resultWriter.getXml().toString(); 50 } 51 52 public ReportResult ExecQuery(ReportQuery query) throws InfoException { 53 if (query == null) { 54 throw new InfoException(LanguageTraslator.traslate("49")); 55 } 56 if(!getFiltersByType(getReportSpec(),FilterDefinitionFilterTypeType.RANKING).isEmpty()){ 57 fillEnumeration(query); 58 } 59 if(!getFiltersByType(getReportSpec(), FilterDefinitionFilterTypeType.EXCLUDEGROUP).isEmpty()){ 60 fillExcludedEnumeration(query); 61 } 62 if (query.isValid()) { 63 System.gc(); 64 this.query = query; 65 setReportQuery(query); 66 ReportManagerLogger.debug(LanguageTraslator.traslate("200")); 67 getReportData().setQuery(query, getPivot()); 68 DataVectorBuilder dataVectorBuilder=null; 69 if (!(getExecutedQueryCollection().alreadyExists(query, getConfiguration().queryCacheEnabled()))){ 70 DimensionValueTreeBuilder dimensionValueTreeBuilder = new DimensionValueTreeBuilder(getReportData()); 71 DimensionValueNode rowsRoot = dimensionValueTreeBuilder.getRowsRoot(); 72 DimensionValueNode columnsRoot = dimensionValueTreeBuilder.getColumnsRoot(); 73 dataVectorBuilder = getDataVectorBuilder(rowsRoot,columnsRoot); 74 rowsModel = HeaderTableModel.newRowHeaderTableModel(rowsRoot,getQuery().isVisibleTotals(), dataVectorBuilder.getRowCount(), getQuery(), getReportSpec()); 75 columnsModel = HeaderTableModel.newColumnHeaderTableModel(columnsRoot, getQuery().isVisibleTotals(), dataVectorBuilder.getColCount(), getQuery(), getReportSpec()); 76 dataVector = dataVectorBuilder.getDataVector(); 77 registerReportQuery(query, rowsModel, columnsModel, dataVector); 78 System.out.println(LanguageTraslator.traslate("496")); 79 } else if((getReportSpec().getReportType().toString().equalsIgnoreCase(ReportDefinitionReportTypeType.CUBE.toString()))||(getReportSpec().getReportType().toString().equalsIgnoreCase(ReportDefinitionReportTypeType.CHARTCUBE.toString()))) { 80 ExecutedQuery executedQuery = getExecutedQueryCollection().getExecutedQuery(query); 81 rowsModel = executedQuery.getRowsModel(); 84 columnsModel = executedQuery.getColumnsModel(); 85 dataVector = executedQuery.getDataVector(); 86 System.out.println(LanguageTraslator.traslate("497")); 87 } 88 } else { 89 throw new InfoException(LanguageTraslator.traslate("50")); 90 } 91 return new CubeReportResult(getReportSpec(), query, rowsModel, columnsModel, dataVector); 92 } 93 94 private ExecutedQueryCollection getExecutedQueryCollection() { 95 if(queryCollection == null) { 96 queryCollection = new ExecutedQueryCollection(); 97 } 98 return queryCollection; 99 } 100 101 private void registerReportQuery(ReportQuery query, HeaderTableModel rowsModel, 102 HeaderTableModel columnsModel, Vector dataVector) { 103 if(getConfiguration().queryCacheEnabled()) { 104 ExecutedQuery executedQuery = null; 105 if(getExecutedQueryCollection().getCollectionSize() == 0) { 106 executedQuery = new ExecutedQuery(query, rowsModel, columnsModel, dataVector, true); 107 } else { 108 executedQuery = new ExecutedQuery(query, rowsModel, columnsModel, dataVector, false); 109 } 110 getExecutedQueryCollection().addExecutedQuery(query, executedQuery); 111 } 114 } 115 116 public Vector getUpdatedDataModel(int mode, int row, int col, boolean isDistributed) throws InfoException { 117 try { 118 boolean changed; 119 if (isDistributed){ 120 changed = false; 121 if (mode == HeaderTableModel.MODE_ROW) { 122 changed = rowsModel.changeNodeState(row,col); 123 } else { 124 changed = columnsModel.changeNodeState(row, col); 125 } 126 }else{ 127 changed = true; 128 } 129 if (changed) { 130 DataVectorBuilder dataVectorBuilder = getDataVectorBuilder(rowsModel.getDimensionValueNode(), columnsModel.getDimensionValueNode()); 131 return dataVectorBuilder.getDataVector(); 132 } 133 else { 134 return null; 135 } 136 } catch (InfoException e) { 137 throw new InfoException(LanguageTraslator.traslate("327")); 138 } 139 } 140 141 } 142 | Popular Tags |