001: package com.calipso.reportgenerator.userinterface.dinamicchart;
002:
003: import com.calipso.reportgenerator.common.InfoException;
004: import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionLocationType;
005: import com.calipso.reportgenerator.userinterface.PivotTableProperties;
006: import com.calipso.reportgenerator.userinterface.ColumnProperties;
007: import com.calipso.reportgenerator.userinterface.MetricState;
008: import com.calipso.reportgenerator.common.ShowExceptionMessageDialog;
009: import com.calipso.reportgenerator.common.*;
010:
011: import java.util.*;
012:
013: /**
014: *
015: * User: soliveri
016: * Date: Jul 31, 2003
017: * Time: 5:51:39 PM
018: *
019: */
020: public class ChartQueryBuilder {
021:
022: private IReportManager reportManager;
023: private String userId;
024: private int handler;
025:
026: public ChartQueryBuilder(IReportManager reportManager, Map params,
027: String userId, int handler) throws InfoException {
028: this .reportManager = reportManager;
029: this .userId = userId;
030: this .handler = handler;
031: }
032:
033: public ReportResult buildNewQuery(
034: PivotTableProperties tableProperties) throws InfoException {
035: ReportQuery reportQuery = reportManager.getDefaultReportQuery(
036: handler, userId);
037: reportQuery = updateDimensionLocation(tableProperties,
038: reportQuery);
039: reportQuery = buildNewQueryExcludeValue(tableProperties,
040: reportQuery);
041: reportQuery = updateVisibleMetrics(tableProperties, reportQuery);
042: reportQuery.setVisibleTotals(false);
043: return reportManager.ExecReportQuery(handler, reportQuery);
044: }
045:
046: private ReportQuery updateDimensionLocation(
047: PivotTableProperties tableProperties,
048: ReportQuery reportQuery) throws InfoException {
049: ColumnProperties columnProperties;
050: DimensionDefinitionLocationType location = DimensionDefinitionLocationType.PAGE;
051: QueryDimension queryDimension;
052: for (int i = 0; i < tableProperties.getColumnProperties()
053: .size(); i++) {
054: columnProperties = (ColumnProperties) tableProperties
055: .getColumnProperties().get(i);
056: if (columnProperties.getLocation().equalsIgnoreCase(
057: DimensionDefinitionLocationType.PAGE.toString())) {
058: location = DimensionDefinitionLocationType.PAGE;
059: } else if (columnProperties.getLocation().equalsIgnoreCase(
060: DimensionDefinitionLocationType.ROW.toString())) {
061: location = DimensionDefinitionLocationType.ROW;
062: }
063: if (columnProperties.getLocation().equalsIgnoreCase(
064: DimensionDefinitionLocationType.COLUMN.toString())) {
065: location = DimensionDefinitionLocationType.COLUMN;
066: }
067: queryDimension = reportQuery
068: .getQueryDimensionFromName(columnProperties
069: .getColumnName());
070: queryDimension.setLocation(location);
071: queryDimension.setLocationOrder(columnProperties
072: .getUbication());
073: queryDimension.setRankMetricName(columnProperties
074: .getRankMetricName());
075: queryDimension.setOrder(columnProperties.getOrder());
076: }
077: return reportQuery;
078: }
079:
080: public ReportQuery buildNewQueryExcludeValue(
081: PivotTableProperties tableProperties,
082: ReportQuery reportQuery) {
083: try {
084: Iterator iterator = tableProperties.getMetricProperies()
085: .iterator();
086: while (iterator.hasNext()) {
087: MetricState state = (MetricState) iterator.next();
088: reportQuery.getQueryMetricFromName(state.getName())
089: .setVisible(state.getVisible());
090: }
091: updateDimensionValues(tableProperties, reportQuery);
092: //reportResult = reportManager.ExecReportQuery(reportManager.PrepareReport(reportDefId, params), reportQuery);
093:
094: } catch (Exception e) {
095: ShowExceptionMessageDialog.initExceptionDialogMessage(
096: LanguageTraslator.traslate("214"), e);
097: }
098: return reportQuery;
099: }
100:
101: /**
102: * Actualiza los valores de metricas visibles de la reportquery de acuerdo a la pivot table properties
103: * @param tableProperties
104: * @param reportQuery
105: */
106: private ReportQuery updateVisibleMetrics(
107: PivotTableProperties tableProperties,
108: ReportQuery reportQuery) throws InfoException {
109: MetricState metricState;
110: for (int i = 0; i < tableProperties.getMetricProperies().size(); i++) {
111: metricState = (MetricState) tableProperties
112: .getMetricProperies().get(i);
113: reportQuery.getQueryMetricFromName(metricState.getName())
114: .setVisible(metricState.getVisible());
115: }
116: return reportQuery;
117: }
118:
119: private void updateDimensionValues(
120: PivotTableProperties tableProperties,
121: ReportQuery reportQuery) throws InfoException {
122: Iterator iterator = tableProperties.getColumnProperties()
123: .iterator();
124: while (iterator.hasNext()) {
125: ColumnProperties properties = (ColumnProperties) iterator
126: .next();
127: int dimensionIndex = reportQuery.getQueryDimensionFromName(
128: properties.getColumnName()).getIndex();
129: reportQuery.setExcludedValues(dimensionIndex, properties
130: .getExcludeValue());
131: }
132: }
133: }
|