KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > dinamicchart > ChartQueryBuilder


1 package com.calipso.reportgenerator.userinterface.dinamicchart;
2
3 import com.calipso.reportgenerator.common.InfoException;
4 import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionLocationType;
5 import com.calipso.reportgenerator.userinterface.PivotTableProperties;
6 import com.calipso.reportgenerator.userinterface.ColumnProperties;
7 import com.calipso.reportgenerator.userinterface.MetricState;
8 import com.calipso.reportgenerator.common.ShowExceptionMessageDialog;
9 import com.calipso.reportgenerator.common.*;
10
11 import java.util.*;
12
13 /**
14  *
15  * User: soliveri
16  * Date: Jul 31, 2003
17  * Time: 5:51:39 PM
18  *
19  */

20 public class ChartQueryBuilder {
21
22   private IReportManager reportManager;
23   private String JavaDoc userId;
24   private int handler;
25
26   public ChartQueryBuilder(IReportManager reportManager, Map params, String JavaDoc userId, int handler) throws InfoException {
27     this.reportManager = reportManager;
28     this.userId = userId;
29     this.handler = handler;
30   }
31
32   public ReportResult buildNewQuery(PivotTableProperties tableProperties) throws InfoException {
33     ReportQuery reportQuery = reportManager.getDefaultReportQuery(handler, userId);
34     reportQuery = updateDimensionLocation(tableProperties, reportQuery);
35     reportQuery = buildNewQueryExcludeValue(tableProperties, reportQuery);
36     reportQuery = updateVisibleMetrics(tableProperties, reportQuery);
37     reportQuery.setVisibleTotals(false);
38     return reportManager.ExecReportQuery(handler, reportQuery);
39   }
40
41   private ReportQuery updateDimensionLocation(PivotTableProperties tableProperties, ReportQuery reportQuery) throws InfoException {
42     ColumnProperties columnProperties;
43     DimensionDefinitionLocationType location = DimensionDefinitionLocationType.PAGE;
44     QueryDimension queryDimension;
45     for (int i = 0; i < tableProperties.getColumnProperties().size(); i++) {
46       columnProperties = (ColumnProperties) tableProperties.getColumnProperties().get(i);
47       if (columnProperties.getLocation().equalsIgnoreCase(DimensionDefinitionLocationType.PAGE.toString())) {
48         location = DimensionDefinitionLocationType.PAGE;
49       }
50       else
51         if (columnProperties.getLocation().equalsIgnoreCase(DimensionDefinitionLocationType.ROW.toString())) {
52           location = DimensionDefinitionLocationType.ROW;
53         }
54       if (columnProperties.getLocation().equalsIgnoreCase(DimensionDefinitionLocationType.COLUMN.toString())) {
55         location = DimensionDefinitionLocationType.COLUMN;
56       }
57       queryDimension = reportQuery.getQueryDimensionFromName(columnProperties.getColumnName());
58       queryDimension.setLocation(location);
59       queryDimension.setLocationOrder(columnProperties.getUbication());
60       queryDimension.setRankMetricName(columnProperties.getRankMetricName());
61       queryDimension.setOrder(columnProperties.getOrder());
62     }
63     return reportQuery;
64   }
65
66   public ReportQuery buildNewQueryExcludeValue(PivotTableProperties tableProperties, ReportQuery reportQuery) {
67     try {
68       Iterator iterator = tableProperties.getMetricProperies().iterator();
69       while (iterator.hasNext()) {
70         MetricState state = (MetricState) iterator.next();
71         reportQuery.getQueryMetricFromName(state.getName()).setVisible(state.getVisible());
72       }
73       updateDimensionValues(tableProperties, reportQuery);
74       //reportResult = reportManager.ExecReportQuery(reportManager.PrepareReport(reportDefId, params), reportQuery);
75

76     }
77     catch (Exception JavaDoc e) {
78       ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e);
79     }
80     return reportQuery;
81   }
82
83   /**
84    * Actualiza los valores de metricas visibles de la reportquery de acuerdo a la pivot table properties
85    * @param tableProperties
86    * @param reportQuery
87    */

88   private ReportQuery updateVisibleMetrics(PivotTableProperties tableProperties, ReportQuery reportQuery) throws InfoException {
89     MetricState metricState;
90     for (int i = 0; i < tableProperties.getMetricProperies().size(); i++) {
91       metricState = (MetricState) tableProperties.getMetricProperies().get(i);
92       reportQuery.getQueryMetricFromName(metricState.getName()).setVisible(metricState.getVisible());
93     }
94     return reportQuery;
95   }
96
97   private void updateDimensionValues(PivotTableProperties tableProperties, ReportQuery reportQuery) throws InfoException {
98     Iterator iterator = tableProperties.getColumnProperties().iterator();
99     while (iterator.hasNext()) {
100       ColumnProperties properties = (ColumnProperties) iterator.next();
101       int dimensionIndex = reportQuery.getQueryDimensionFromName(properties.getColumnName()).getIndex();
102       reportQuery.setExcludedValues(dimensionIndex, properties.getExcludeValue());
103     }
104   }
105 }
106
Popular Tags