001: package com.calipso.reportgenerator.reportmanager;
002:
003: import com.calipso.reportgenerator.common.*;
004: import com.calipso.reportgenerator.reportdefinitions.types.ReportDefinitionReportTypeType;
005: import com.calipso.reportgenerator.reportdefinitions.types.FilterDefinitionFilterTypeType;
006: import com.calipso.reportgenerator.common.InfoException;
007:
008: import java.util.*;
009:
010: /**
011: *
012: * User: soliveri
013: * Date: Dec 15, 2003
014: * Time: 5:03:27 PM
015: *
016: */
017:
018: public class CubeReport extends Report {
019:
020: private transient ExecutedQueryCollection queryCollection;
021: private HeaderTableModel rowsModel;
022: private HeaderTableModel columnsModel;
023: private Vector dataVector;
024: private ReportQuery query;
025:
026: public CubeReport() throws InfoException {
027: }
028:
029: public CubeReport(ReportSpec reportSpec, ReportSource reportSource,
030: ReportGeneratorConfiguration configuration)
031: throws InfoException {
032: super (reportSpec, reportSource, configuration);
033: initialize();
034: }
035:
036: /**
037: * Ejecuta la inicialización, recolecta toda la información que necesita de la definición del reporte, inicializa
038: * los objetos encargados de resolver los cálculos y obtiene los valores de parámetros por defecto.
039: * @throws InfoException
040: */
041: private void initialize() throws InfoException {
042: try {
043: setReportData(new CubeReportData(getReportSpec()));
044: } catch (Exception e) {
045: throw new InfoException(LanguageTraslator.traslate("48"), e);
046: }
047: }
048:
049: public String getXml() throws InfoException {
050: ReportXmlWriter resultWriter = new CubeReportXmlWriter(
051: getReportData(), getReportSpec(), getQuery()
052: .getParamValues(), query);
053: return resultWriter.getXml().toString();
054: }
055:
056: public ReportResult ExecQuery(ReportQuery query)
057: throws InfoException {
058: if (query == null) {
059: throw new InfoException(LanguageTraslator.traslate("49"));
060: }
061: if (!getFiltersByType(getReportSpec(),
062: FilterDefinitionFilterTypeType.RANKING).isEmpty()) {
063: fillEnumeration(query);
064: }
065: if (!getFiltersByType(getReportSpec(),
066: FilterDefinitionFilterTypeType.EXCLUDEGROUP).isEmpty()) {
067: fillExcludedEnumeration(query);
068: }
069: if (query.isValid()) {
070: System.gc();
071: this .query = query;
072: setReportQuery(query);
073: ReportManagerLogger
074: .debug(LanguageTraslator.traslate("200"));
075: getReportData().setQuery(query, getPivot());
076: DataVectorBuilder dataVectorBuilder = null;
077: if (!(getExecutedQueryCollection().alreadyExists(query,
078: getConfiguration().queryCacheEnabled()))) {
079: DimensionValueTreeBuilder dimensionValueTreeBuilder = new DimensionValueTreeBuilder(
080: getReportData());
081: DimensionValueNode rowsRoot = dimensionValueTreeBuilder
082: .getRowsRoot();
083: DimensionValueNode columnsRoot = dimensionValueTreeBuilder
084: .getColumnsRoot();
085: dataVectorBuilder = getDataVectorBuilder(rowsRoot,
086: columnsRoot);
087: rowsModel = HeaderTableModel.newRowHeaderTableModel(
088: rowsRoot, getQuery().isVisibleTotals(),
089: dataVectorBuilder.getRowCount(), getQuery(),
090: getReportSpec());
091: columnsModel = HeaderTableModel
092: .newColumnHeaderTableModel(columnsRoot,
093: getQuery().isVisibleTotals(),
094: dataVectorBuilder.getColCount(),
095: getQuery(), getReportSpec());
096: dataVector = dataVectorBuilder.getDataVector();
097: registerReportQuery(query, rowsModel, columnsModel,
098: dataVector);
099: System.out.println(LanguageTraslator.traslate("496"));
100: } else if ((getReportSpec().getReportType().toString()
101: .equalsIgnoreCase(ReportDefinitionReportTypeType.CUBE
102: .toString()))
103: || (getReportSpec().getReportType().toString()
104: .equalsIgnoreCase(ReportDefinitionReportTypeType.CHARTCUBE
105: .toString()))) {
106: ExecutedQuery executedQuery = getExecutedQueryCollection()
107: .getExecutedQuery(query);
108: //Para recuperar del disco
109: //ExecutedQuery executedQuery = getExecutedQueryCollection().getExecutedQueryFromDisk(query);
110: rowsModel = executedQuery.getRowsModel();
111: columnsModel = executedQuery.getColumnsModel();
112: dataVector = executedQuery.getDataVector();
113: System.out.println(LanguageTraslator.traslate("497"));
114: }
115: } else {
116: throw new InfoException(LanguageTraslator.traslate("50"));
117: }
118: return new CubeReportResult(getReportSpec(), query, rowsModel,
119: columnsModel, dataVector);
120: }
121:
122: private ExecutedQueryCollection getExecutedQueryCollection() {
123: if (queryCollection == null) {
124: queryCollection = new ExecutedQueryCollection();
125: }
126: return queryCollection;
127: }
128:
129: private void registerReportQuery(ReportQuery query,
130: HeaderTableModel rowsModel, HeaderTableModel columnsModel,
131: Vector dataVector) {
132: if (getConfiguration().queryCacheEnabled()) {
133: ExecutedQuery executedQuery = null;
134: if (getExecutedQueryCollection().getCollectionSize() == 0) {
135: executedQuery = new ExecutedQuery(query, rowsModel,
136: columnsModel, dataVector, true);
137: } else {
138: executedQuery = new ExecutedQuery(query, rowsModel,
139: columnsModel, dataVector, false);
140: }
141: getExecutedQueryCollection().addExecutedQuery(query,
142: executedQuery);
143: //Para disco
144: //getExecutedQueryCollection().addExecutedQueryToDisk(query, executedQuery);
145: }
146: }
147:
148: public Vector getUpdatedDataModel(int mode, int row, int col,
149: boolean isDistributed) throws InfoException {
150: try {
151: boolean changed;
152: if (isDistributed) {
153: changed = false;
154: if (mode == HeaderTableModel.MODE_ROW) {
155: changed = rowsModel.changeNodeState(row, col);
156: } else {
157: changed = columnsModel.changeNodeState(row, col);
158: }
159: } else {
160: changed = true;
161: }
162: if (changed) {
163: DataVectorBuilder dataVectorBuilder = getDataVectorBuilder(
164: rowsModel.getDimensionValueNode(), columnsModel
165: .getDimensionValueNode());
166: return dataVectorBuilder.getDataVector();
167: } else {
168: return null;
169: }
170: } catch (InfoException e) {
171: throw new InfoException(LanguageTraslator.traslate("327"));
172: }
173: }
174:
175: }
|