KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > common > ReportViewBuilder


1 package com.calipso.reportgenerator.common;
2
3 import com.calipso.reportgenerator.reportdefinitions.*;
4 import com.calipso.reportgenerator.reportdefinitions.types.DimensionPropertyOrderType;
5 import com.calipso.reportgenerator.reportdefinitions.types.DimensionPropertyLocationType;
6 import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionOrderType;
7
8 import java.util.Map JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.Date JavaDoc;
11 import java.util.List JavaDoc;
12 import java.text.SimpleDateFormat JavaDoc;
13
14 /**
15  * Calipso Software
16  * User: jbassino
17  * Date: 02-dic-2005
18  * Time: 15:02:54
19  */

20 public class ReportViewBuilder {
21   public static ViewParameterValues getViewParameterValues(Map JavaDoc paramValues) {
22     paramValues = ReportMap.setParametersToSimpleType(paramValues);
23     ViewParameterValues values = new ViewParameterValues();
24     Iterator JavaDoc it = paramValues.entrySet().iterator();
25     while (it.hasNext()) {
26       Map.Entry JavaDoc entry = (Map.Entry JavaDoc) it.next();
27       ViewParameterValue param = new ViewParameterValue();
28       param.setViewParamName(entry.getKey().toString());
29       if(entry.getValue() instanceof Date JavaDoc){
30         SimpleDateFormat JavaDoc format = new SimpleDateFormat JavaDoc("yyyyMMdd");
31         param.setViewParamValue(format.format(((Date JavaDoc)entry.getValue())));
32       }else{
33         param.setViewParamValue(entry.getValue().toString());
34       }
35       values.addViewParameterValue(param);
36     }
37     return values;
38   }
39
40   public static ReportView getDefaultReportViewHeader(String JavaDoc ID, String JavaDoc userID, String JavaDoc description, ReportResult reportResult){
41     ReportView reportView = new ReportView();
42     reportView.setId(ID);
43     reportView.setUserName(userID);
44     reportView.setUserID(userID);
45     reportView.setVisibleTotals(reportResult.getReportSpec().isVisibleTotals());
46     reportView.setReportDefinitionId(reportResult.getReportSpec().getDefinitionId());
47     reportView.setViewParameterValues(ReportViewBuilder.getViewParameterValues(reportResult.getParamValues()));
48     reportView.setDescription(description);
49     //reportView.setDefault();
50
return reportView;
51   }
52
53   public static ReportView getDefaultReportView(String JavaDoc ID, String JavaDoc userID, String JavaDoc description, ReportResult reportResult){
54     ReportView reportView = getDefaultReportViewHeader(ID, userID, description, reportResult);
55     buildDimensionsProperties(reportView, reportResult);
56     buildMetricsProperties(reportView, reportResult);
57     return reportView;
58   }
59
60   private static void buildDimensionsProperties(ReportView reportView, ReportResult reportResult) {
61     List JavaDoc dimensions = reportResult.getReportQuery().getDimensions();
62     DimensionProperties dimensionsProperties = new DimensionProperties();
63     reportView.setDimensionProperties(dimensionsProperties);
64     DimensionProperty dimensionProperty;
65     QueryDimension queryDimension;
66     for (int i = 0; i < dimensions.size(); i++){
67       queryDimension = (QueryDimension)dimensions.get(i);
68       dimensionProperty = new DimensionProperty();
69       dimensionsProperties.addDimensionProperty(dimensionProperty);
70       dimensionProperty.setDimensionName(queryDimension.getName());
71       dimensionProperty.setWidth(75);
72       dimensionProperty.setOrder(getDimensionPropertyOrder(queryDimension.getOrder()));
73       dimensionProperty.setLocation(getDimensionPropertyLocation(queryDimension.getLocation().toString()));
74       dimensionProperty.setUbication(queryDimension.getIndex());
75       dimensionProperty.setRankMetricName(queryDimension.getRankMetricName());
76     }
77   }
78
79   private static void buildMetricsProperties(ReportView reportView, ReportResult result) {
80     List JavaDoc metrics = result.getReportQuery().getMetrics();
81     MetricProperties metricProperties = new MetricProperties();
82     reportView.setMetricProperties(metricProperties);
83     MetricProperty metricProperty;
84     QueryMetric queryMetric;
85     for (int i = 0; i < metrics.size();i++){
86       queryMetric = (QueryMetric) metrics.get(i);
87       metricProperty = new MetricProperty();
88       metricProperties.addMetricProperty(metricProperty);
89       metricProperty.setMetricName(queryMetric.getName());
90       metricProperty.setVisible(queryMetric.getVisible());
91     }
92   }
93
94   public static DimensionPropertyOrderType getDimensionPropertyOrder(DimensionDefinitionOrderType order) {
95     if (order== null){
96       return DimensionPropertyOrderType.A;
97     } else {
98       if (order.toString().equalsIgnoreCase(DimensionPropertyOrderType.A.toString())){
99         return DimensionPropertyOrderType.A;
100       } else if ( order.toString().equalsIgnoreCase(DimensionPropertyOrderType.D.toString())){
101         return DimensionPropertyOrderType.D;
102       }
103     }
104     return null;
105   }
106
107   /**
108    * Cnvierte un Location a otro Location del tipo destino
109    * @param location
110    * @return
111    */

112   public static DimensionPropertyLocationType getDimensionPropertyLocation(String JavaDoc location) {
113     if (location.equalsIgnoreCase(DimensionPropertyLocationType.COLUMN.toString())){
114       return DimensionPropertyLocationType.COLUMN;
115     } else if (location.equalsIgnoreCase(DimensionPropertyLocationType.PAGE.toString())){
116       return DimensionPropertyLocationType.PAGE;
117     }else if (location.equalsIgnoreCase(DimensionPropertyLocationType.ROW.toString())){
118       return DimensionPropertyLocationType.ROW;
119     }
120     return null;
121   }
122
123
124 }
125
Popular Tags