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 ; 9 import java.util.Iterator ; 10 import java.util.Date ; 11 import java.util.List ; 12 import java.text.SimpleDateFormat ; 13 14 20 public class ReportViewBuilder { 21 public static ViewParameterValues getViewParameterValues(Map paramValues) { 22 paramValues = ReportMap.setParametersToSimpleType(paramValues); 23 ViewParameterValues values = new ViewParameterValues(); 24 Iterator it = paramValues.entrySet().iterator(); 25 while (it.hasNext()) { 26 Map.Entry entry = (Map.Entry ) it.next(); 27 ViewParameterValue param = new ViewParameterValue(); 28 param.setViewParamName(entry.getKey().toString()); 29 if(entry.getValue() instanceof Date ){ 30 SimpleDateFormat format = new SimpleDateFormat ("yyyyMMdd"); 31 param.setViewParamValue(format.format(((Date )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 ID, String userID, String 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 return reportView; 51 } 52 53 public static ReportView getDefaultReportView(String ID, String userID, String 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 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 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 112 public static DimensionPropertyLocationType getDimensionPropertyLocation(String 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 |