1 package com.calipso.reportgenerator.common; 2 3 import com.calipso.reportgenerator.reportdefinitions.*; 4 import com.calipso.reportgenerator.reportdefinitions.types.ReportDefinitionReportTypeType; 5 import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionLocationType; 6 import com.calipso.reportgenerator.reportdefinitions.types.FilterDefinitionFilterTypeType; 7 import com.calipso.reportgenerator.reportcalculator.CubeDefinition; 8 import com.calipso.reportgenerator.reportcalculator.DataTreeDefinition; 9 10 import java.util.*; 11 import java.io.Serializable ; 12 import java.math.BigDecimal ; 13 14 import org.apache.commons.collections.iterators.FilterIterator; 15 import org.apache.commons.collections.Predicate; 16 17 21 public class ReportSpec implements CubeDefinition, DataTreeDefinition, Serializable { 22 23 24 private Map dimensionSpecs; 25 private List dimensionsByIndex; 26 private Map metricSpecs; 27 private Map accumulableMetricSpecs; 28 private List metricsByIndex; 29 private List accumulableMetricsByIndex; 30 private Map posParamValues; 31 private Object [] dimensions; 32 private Object [] groupingDimensions; 33 private Object [] nonGroupingDimensions; 34 private Object [] metrics; 35 private Object [] accumulableMetrics; 36 private String description; 37 private String title; 38 private String pageHeader; 39 private String pageFooter; 40 private ReportDefinitionReportTypeType reportType; 41 private Collection preFilterSpecs; 42 private Collection filterSpecs; 43 private Collection dataSourceSpecs; 44 private boolean cached; 46 private String incrementalDimension; 47 private BigDecimal expiration; 48 private String sourceId; 49 private String definitionId; 50 private Map dataSourceIndexes; 51 private String localeLanguage; 52 private Map localizationMap; 53 private List drillDownSpecs; 54 private int sourceMaxRowCount; 55 private String sourceMaxRowsDimension = ""; 56 private int maxRowCount; 57 private String maxRowsDimension = ""; 58 private boolean visibleTotals; 59 private Map preParamValues; 60 private String LayoutDesign; 61 private String infoPage; 63 private boolean datawarehouseSaved; 64 private Map reportSourceIndexes; 65 66 67 70 public ReportSpec(ReportGeneratorConfiguration reportGeneratorConfiguration) { 71 setLocale(reportGeneratorConfiguration.getLocaleLanguage()); 73 } 75 76 81 public Object [] getDimensions() { 82 if (dimensions == null) { 83 dimensions = getDimensionsByIndex().toArray(); 84 } 85 return dimensions; 86 } 87 88 93 94 public Object [] getMetrics() { 95 if (metrics == null) { 96 metrics = getMetricsByIndex().toArray(); 97 } 98 return metrics; 99 } 100 101 106 107 public Object [] getAccumulableMetrics() { 108 if (accumulableMetrics == null) { 109 accumulableMetrics = getAccumulableMetricsByIndex().toArray(); 110 } 111 return accumulableMetrics; 112 } 113 114 118 119 public Map getDataSourceIndexes() { 120 if (dataSourceIndexes == null) { 121 dataSourceIndexes = new HashMap(); 122 } 123 return dataSourceIndexes; 124 } 125 126 132 private Object [] getDimensionsByGrouping(List dimensions, boolean grouping) { 133 List dims = new ArrayList(); 134 Iterator iter = dimensions.iterator(); 135 while (iter.hasNext()) { 136 ReportDimensionSpec dimensionSpec = (ReportDimensionSpec) iter.next(); 137 if (dimensionSpec.getReportIndex() >= 0 && dimensionSpec.getGroups() == grouping) { 138 dims.add(dimensionSpec); 139 } 140 } 141 return dims.toArray(); 142 } 143 144 148 public Object [] getGroupingDimensions() { 149 if (groupingDimensions == null) { 150 groupingDimensions = getDimensionsByGrouping(getDimensionsByIndex(), true); 151 } 152 return groupingDimensions; 153 } 154 155 159 public Object [] getNonGroupingDimensions() { 160 if (nonGroupingDimensions == null) { 161 nonGroupingDimensions = getDimensionsByGrouping(getDimensionsByIndex(), false); 162 } 163 return nonGroupingDimensions; 164 } 165 166 170 public Map getDimensionSpecs() { 171 if (dimensionSpecs == null) { 172 dimensionSpecs = new HashMap(); 173 } 174 return dimensionSpecs; 175 } 176 177 182 public List getDimensionsByIndex() { 183 if (dimensionsByIndex == null) { 184 dimensionsByIndex = new ArrayList(); 185 } 186 return dimensionsByIndex; 187 } 188 189 193 public Map getMetricSpecs() { 194 if (metricSpecs == null) { 195 metricSpecs = new HashMap(); 196 } 197 return metricSpecs; 198 } 199 200 204 public Map getAccumulableMetricSpecs() { 205 if (accumulableMetricSpecs == null) { 206 accumulableMetricSpecs = new HashMap(); 207 } 208 return accumulableMetricSpecs; 209 } 210 211 215 216 public List getMetricsByIndex() { 217 if (metricsByIndex == null) { 218 metricsByIndex = new ArrayList(); 219 } 220 return metricsByIndex; 221 } 222 223 227 228 public List getAccumulableMetricsByIndex() { 229 if (accumulableMetricsByIndex == null) { 230 accumulableMetricsByIndex = new ArrayList(); 231 } 232 return accumulableMetricsByIndex; 233 } 234 235 236 240 public void fillFrom(ReportSourceDefinition reportSourceDefinition) throws InfoException{ 241 int dataSourceIndex = 0; 242 int reportSourceIndex = 0; 243 cached = reportSourceDefinition.getCached(); 244 datawarehouseSaved = reportSourceDefinition.getDatawarehouseSaved(); 245 incrementalDimension = reportSourceDefinition.getIncrementalDimension(); 246 expiration = reportSourceDefinition.getExpiration(); 247 sourceId = reportSourceDefinition.getId(); 248 sourceMaxRowCount = reportSourceDefinition.getMaxRowCount(); 249 if (reportSourceDefinition.getMaxRowsDimensionReference() != null) { 250 sourceMaxRowsDimension = reportSourceDefinition.getMaxRowsDimensionReference(); 251 } 252 253 Enumeration dimEnum = reportSourceDefinition.getDimensionSourceDefinitions().enumerateDimensionSourceDefinition(); 254 while (dimEnum.hasMoreElements()) { 255 DimensionSourceDefinition dimensionSourceDefinition = (DimensionSourceDefinition) dimEnum.nextElement(); 256 String name = dimensionSourceDefinition.getName(); 257 ReportDimensionSpec dimensionSpec = new ReportDimensionSpec(name); 258 dimensionSpec.setReportSourceIndex(reportSourceIndex); 259 getReportSourceIndexes().put(name, new Integer (reportSourceIndex)); 260 dimensionSpec.setDataSourceIndexes(getDataSourceIndexes()); 263 dimensionSpec.setReportSourceIndexes(getReportSourceIndexes()); 264 reportSourceIndex++; 265 if (!dimensionSourceDefinition.getCalculated()) { 266 dimensionSpec.setDataSourceIndex(dataSourceIndex); 267 getDataSourceIndexes().put(name, new Integer (dataSourceIndex)); 268 dataSourceIndex++; 269 } 270 dimensionSpec.fillFrom(dimensionSourceDefinition, reportSourceDefinition.getMultilanguage(), getLocalizacionMap(reportSourceDefinition)); 271 addDimension(dimensionSpec); 272 } 273 274 Enumeration metEnum = reportSourceDefinition.getMetricSourceDefinitions().enumerateMetricSourceDefinition(); 275 while (metEnum.hasMoreElements()) { 276 MetricSourceDefinition metricSourceDefinition = (MetricSourceDefinition) metEnum.nextElement(); 277 String name = metricSourceDefinition.getName(); 278 ReportMetricSpec metricSpec = new ReportMetricSpec(name); 279 metricSpec.setReportSourceIndex(reportSourceIndex); 280 getReportSourceIndexes().put(name, new Integer (reportSourceIndex)); 281 metricSpec.setReportSourceIndexes(getReportSourceIndexes()); 282 metricSpec.setDataSourceIndexes(getDataSourceIndexes()); 283 reportSourceIndex++; 284 if (!metricSourceDefinition.getCalculated()) { 285 metricSpec.setDataSourceIndex(dataSourceIndex); 286 getDataSourceIndexes().put(name, new Integer (dataSourceIndex)); 287 dataSourceIndex++; 288 } 289 metricSpec.fillFrom(metricSourceDefinition, reportSourceDefinition.getMultilanguage(), getLocalizacionMap(reportSourceDefinition)); 290 addMetric(metricSpec); 291 } 292 preFilterSpecs = new ArrayList(); 293 fillReportFilters(reportSourceDefinition.getFilterDefinitions(), (List) preFilterSpecs); 294 preParamValues = ReportFilterBuilder.mergeParamValues(getPreParamValues(), reportSourceDefinition.getParameterValues()); 295 translateParamValues(preParamValues); 296 297 dataSourceSpecs = new ArrayList(); 298 Enumeration dataSourcesEnum = reportSourceDefinition.getDataSourceDefinitions().enumerateDataSourceDefinition(); 299 while (dataSourcesEnum.hasMoreElements()) { 300 DataSourceDefinition dataSourceDefinition = (DataSourceDefinition) dataSourcesEnum.nextElement(); 301 ReportDataSourceSpec dataSourceSpec = new ReportDataSourceSpec(); 302 dataSourceSpec.fillFrom(dataSourceDefinition); 303 dataSourceSpecs.add(dataSourceSpec); 304 } 305 } 306 307 private Map getReportSourceIndexes() { 308 if(reportSourceIndexes == null){ 309 reportSourceIndexes = new HashMap(); 310 } 311 return reportSourceIndexes; 312 } 313 314 private void translateParamValues(Map paramValues) throws InfoException{ 315 Iterator params = paramValues.entrySet().iterator(); 316 while(params.hasNext()){ 317 Map.Entry current = (Map.Entry)params.next(); 318 ReportFilterSpec filter = getFilterSpecFromParamName(current.getKey().toString()); 319 if ((filter!=null)&&(filter.getFilterType()!=FilterDefinitionFilterTypeType.IN)) { 320 ReportDimensionSpec dimension = getDimensionFromName(filter.getDimensionName()); 321 if(dimension!=null){ 322 Object obj = dimension.getValueFor(current.getValue()); 323 current.setValue(obj); 324 }else{ 325 Object obj = ReportDimensionSpec.getValueFor(current.getValue(), filter.getDataType().getType()); 326 current.setValue(obj); 327 } 329 } 330 } 331 } 332 333 public void setPosParamValues(Map paramValues) { 334 if (paramValues != null) { 335 this.posParamValues = paramValues; 336 } 337 } 338 339 343 private void addMetric(ReportMetricSpec metricSpec) { 344 getMetricSpecs().put(metricSpec.getName().toUpperCase(), metricSpec); 345 getMetricsByIndex().add(metricSpec); 346 } 347 348 352 353 private void addDimension(ReportDimensionSpec dimensionSpec) { 354 getDimensionSpecs().put(dimensionSpec.getName().toUpperCase(), dimensionSpec); 355 getDimensionsByIndex().add(dimensionSpec); 356 } 357 358 359 363 364 public void fillFrom(ReportDefinition reportDefinition) throws InfoException{ 365 definitionId = reportDefinition.getId(); 366 boolean isMultilanguege = reportDefinition.getMultilanguage(); 367 Map localizationMap = getLocalizacionMap(reportDefinition); 368 setDescription(traslate(isMultilanguege, localizationMap, reportDefinition.getDescription())); 369 setPageHeader(traslate(isMultilanguege, localizationMap, reportDefinition.getPageHeding())); 370 setPageFooter(traslate(isMultilanguege, localizationMap, reportDefinition.getPageFooter())); 371 setTitle(traslate(isMultilanguege, localizationMap, reportDefinition.getTitle())); 372 setReportType(reportDefinition.getReportType()); 373 maxRowCount = reportDefinition.getMaxRowCount(); 374 visibleTotals = reportDefinition.getVisibleTotals(); 375 setLayoutDesign(reportDefinition.getLayoutDesign()); 376 if (reportDefinition.getMaxRowsDimensionReference() != null) { 377 maxRowsDimension = reportDefinition.getMaxRowsDimensionReference(); 378 } 379 380 int reportIndex = 0; 381 Enumeration dimEnum = reportDefinition.getDimensionDefinitions().enumerateDimensionDefinition(); 382 while (dimEnum.hasMoreElements()) { 383 DimensionDefinition dimensionDefinition = (DimensionDefinition) dimEnum.nextElement(); 384 ReportDimensionSpec dimensionSpec = getDimensionFromName(dimensionDefinition.getName().toUpperCase()); 385 dimensionSpec.setReportIndex(reportIndex); 386 reportIndex++; 387 dimensionSpec.fillFrom(dimensionDefinition, reportDefinition.getMultilanguage(), getLocalizacionMap(reportDefinition)); 388 } 389 390 Enumeration metEnum = reportDefinition.getMetricDefinitions().enumerateMetricDefinition(); 391 while (metEnum.hasMoreElements()) { 392 MetricDefinition metricDefinition = (MetricDefinition) metEnum.nextElement(); 393 ReportMetricSpec metricSpec = getMetricFromName(metricDefinition.getName().toUpperCase()); 394 metricSpec.setReportIndex(reportIndex); 395 reportIndex++; 396 metricSpec.fillFrom(metricDefinition, reportDefinition.getMultilanguage(), getLocalizacionMap(reportDefinition)); 397 if (metricSpec.getAccumulable()) { 398 getAccumulableMetricSpecs().put(metricSpec.getName(), metricSpec); 399 getAccumulableMetricsByIndex().add(metricSpec); 400 } 401 } 402 403 filterSpecs = new ArrayList(); 404 fillReportFilters(reportDefinition.getFilterDefinitions(), (List) filterSpecs); 405 posParamValues = ReportFilterBuilder.mergeParamValues(getPosParamValues(), reportDefinition.getParameterValues()); 406 translateParamValues(posParamValues); 407 408 drillDownSpecs = new ArrayList(); 409 if (reportDefinition.getDrillDownDefinitions() != null) { 410 Enumeration drillDownEnum = reportDefinition.getDrillDownDefinitions().enumerateDrillDownDefinition(); 411 while (drillDownEnum.hasMoreElements()) { 412 DrillDownDefinition drillDownDefinition = (DrillDownDefinition) drillDownEnum.nextElement(); 413 DrillDownSpec drillDownSpec = new DrillDownSpec(); 414 drillDownSpec.fillFrom(drillDownDefinition); 415 drillDownSpecs.add(drillDownSpec); 416 } 417 } 418 this.infoPage = reportDefinition.getInfoPage(); 419 } 420 421 426 private Map getLocalizacionMap(ReportDefinition reportDefinition) { 427 if (localizationMap == null) { 428 Localization localization = getLocalizationFromLocale(reportDefinition.getLocalizations()); 429 if (localization != null) { 430 localizationMap = createMapLocazation(localization); 431 } 432 } 433 return localizationMap; 434 } 435 436 437 442 private Map getLocalizacionMap(ReportSourceDefinition reportSourceDefinition) { 443 Localization localization = getLocalizationFromLocale(reportSourceDefinition.getLocalizations()); 444 if (localization != null) { 445 return createMapLocazation(localization); 446 } 447 return null; 448 } 449 450 455 private Map createMapLocazation(Localization localization) { 456 Map localeMap = new Hashtable(); 457 for (int i = 0; i < localization.getLiteralsCount(); i++) { 458 localeMap.put(localization.getLiterals()[i].getCode(), localization.getLiterals()[i].getValue()); 459 } 460 return localeMap; 461 } 462 463 468 private Localization getLocalizationFromLocale(Localizations localizations) { 469 Localization localization; 470 if (localizations != null) { 471 for (int i = 0; i < localizations.getLocalizationCount(); i++) { 472 localization = localizations.getLocalization()[i]; 473 if (localization.getLocale().equalsIgnoreCase(getLocaleLanguage())) { 474 return localization; 475 } 476 ; 477 } 478 } 479 return null; 480 } 481 482 488 private void fillReportFilters(FilterDefinitions filterDefinitions, List filters) { 489 if (filterDefinitions != null) { 490 for (int i = 0; i < filterDefinitions.getFilterDefinitionCount(); i++) { 491 FilterDefinition filterDefinition = filterDefinitions.getFilterDefinition(i); 492 ReportFilterSpec reportFilterSpec = new ReportFilterSpec(); 493 reportFilterSpec.fillFrom(filterDefinition); 494 filters.add(reportFilterSpec); 495 } 496 } 497 } 498 499 504 public ReportMetricSpec getMetricFromName(String name) { 505 return (ReportMetricSpec) getMetricSpecs().get(name.toUpperCase()); 506 } 507 508 513 public ReportMetricSpec getMetricFromIndex(int index) { 514 return (ReportMetricSpec) getMetricsByIndex().get(index); 515 } 516 517 522 public ReportDimensionSpec getDimensionFromName(String name) { 523 return (ReportDimensionSpec) getDimensionSpecs().get(name.toUpperCase()); 524 } 525 526 531 public ReportDimensionSpec getDimensionFromIndex(int index) { 532 return (ReportDimensionSpec) getDimensionsByIndex().get(index); 533 } 534 535 539 public String getDescription() { 540 return description; 541 } 542 543 546 public void setDescription(String description) { 547 this.description = description; 548 } 549 550 554 public String getTitle() { 555 return title; 556 } 557 558 562 public void setTitle(String title) { 563 this.title = title; 564 } 565 566 570 public String getPageHeader() { 571 return pageHeader; 572 } 573 574 577 public void setPageHeader(String pageHeader) { 578 this.pageHeader = pageHeader; 579 } 580 581 585 586 public String getPageFooter() { 587 return pageFooter; 588 } 589 590 594 public void setPageFooter(String pageFooter) { 595 this.pageFooter = pageFooter; 596 } 597 598 603 public ReportDefinitionReportTypeType getReportType() { 604 return reportType; 605 } 606 607 611 public void setReportType(ReportDefinitionReportTypeType reportType) { 612 this.reportType = reportType; 613 } 614 615 620 public Map getParamValues(boolean sourceOnly) { 621 Map param = new HashMap(); 622 param = ReportFilterBuilder.mergeParamValues(param, getPreParamValues()); 623 if (!sourceOnly || !getCached()) { 624 param = ReportFilterBuilder.mergeParamValues(param, getPosParamValues()); 625 } 626 return param; 627 } 628 629 634 public ReportFieldSpec getFieldFromName(String name) { 635 ReportFieldSpec fieldSpec; 636 fieldSpec = getDimensionFromName(name); 637 if (fieldSpec == null) { 638 fieldSpec = getMetricFromName(name); 639 } 640 return fieldSpec; 641 } 642 643 649 public Collection getDimensionsByLocation(DimensionDefinitionLocationType location) { 650 Iterator iter = getDimensionsByIndex().iterator(); 651 ArrayList result = new ArrayList(); 652 while (iter.hasNext()) { 653 ReportDimensionSpec dimensionSpec = (ReportDimensionSpec) iter.next(); 654 if (dimensionSpec.getLocation() != null && dimensionSpec.getLocation().getType() == location.getType()) { 655 result.add(dimensionSpec); 656 } 657 } 658 return result; 659 } 660 661 665 public Collection getFilterSpecs() { 666 return filterSpecs; 667 } 668 669 673 public Collection getPreFilterSpecs() { 674 return preFilterSpecs; 675 } 676 677 681 public Collection getDataSourceSpecs() { 682 return dataSourceSpecs; 683 } 684 685 692 693 702 703 718 719 723 public boolean getCached() { 724 return cached; 725 } 726 727 731 public String getIncrementalDimension() { 732 return incrementalDimension; 733 } 734 735 739 public BigDecimal getExpiration() { 740 return expiration; 741 } 742 743 747 public String getSourceId() { 748 return sourceId; 749 } 750 751 755 public String getDefinitionId() { 756 return definitionId; 757 } 758 759 760 766 public Collection getDimensionsByGrouping(boolean groups) { 767 Iterator iter = getDimensionSpecs().values().iterator(); 768 ArrayList result = new ArrayList(); 769 while (iter.hasNext()) { 770 ReportDimensionSpec dimensionSpec = (ReportDimensionSpec) iter.next(); 771 if (dimensionSpec.getGroups() == groups) { 772 result.add(dimensionSpec); 773 } 774 } 775 return result; 776 } 777 778 782 public boolean getAccumulable() { 783 return getReportType().getType() == ReportDefinitionReportTypeType.ACCUM_TYPE; 784 } 785 786 790 public void setLocale(String localeLanguage) { 791 this.localeLanguage = localeLanguage; 792 } 793 794 798 public String getLocaleLanguage() { 799 return localeLanguage; 800 } 801 802 809 protected String traslate(boolean multilanguaje, Map localization, String value) { 810 if (multilanguaje && (localization != null) && (value != null) && localization.containsKey(value)) { 811 return localization.get(value).toString(); 812 } 813 else { 814 return value; 815 } 816 } 817 818 822 public List getDrillDownSpecs() { 823 return drillDownSpecs; 824 } 825 826 831 public ReportFilterSpec getFilterSpecFromName(String name) { 832 ReportFilterSpec result = doGetFilterSpecFromName(getFilterSpecs(), name); 833 if (result == null) { 834 result = doGetFilterSpecFromName(getPreFilterSpecs(), name); 835 } 836 return result; 837 } 838 839 protected ReportFilterSpec doGetFilterSpecFromName(Collection filters, String name) { 840 Iterator iterator = filters.iterator(); 841 while (iterator.hasNext()) { 842 ReportFilterSpec reportFilterSpec = (ReportFilterSpec) iterator.next(); 843 if (reportFilterSpec.getName().equalsIgnoreCase(name)) { 844 return reportFilterSpec; 845 } 846 } 847 return null; 848 } 849 850 855 public int getSourceMaxRowCount() { 856 return sourceMaxRowCount; 857 } 858 859 863 public String getSourceMaxRowsDimension() { 864 return sourceMaxRowsDimension; 865 } 866 867 871 public int getMaxRowCount() { 872 return maxRowCount; 873 } 874 875 876 880 public String getMaxRowsDimension() { 881 return maxRowsDimension; 882 } 883 884 889 public ReportFilterSpec getIncrementalFilterSpec(Date lastExecution) { 890 ReportFilterSpec filterSpec = null; 891 String incDim = getIncrementalDimension(); 892 if (!incDim.equals("") && lastExecution != null) { 893 filterSpec = new ReportFilterSpec(); 894 filterSpec.setName("INCREMENTAL"); 895 filterSpec.setFilterType(FilterDefinitionFilterTypeType.GREATERTHAN); 896 filterSpec.setVisual(false); 897 filterSpec.setDimensionName(incDim); 898 } 899 return filterSpec; 900 } 901 902 903 907 public ReportFilterSpec getSourceMaxRowsFilterSpec() { 908 ReportFilterSpec filterSpec = null; 909 String mxDim = getSourceMaxRowsDimension(); 910 if (!mxDim.equals("")) { 911 filterSpec = new ReportFilterSpec(); 912 filterSpec.setName("SOURCEMAXROWS"); 913 filterSpec.setFilterType(FilterDefinitionFilterTypeType.GREATERTHAN); 914 filterSpec.setVisual(true); 915 filterSpec.setDimensionName(mxDim); 916 } 917 return filterSpec; 918 } 919 920 923 924 public ReportFilterSpec getMaxRowsFilterSpec() { 925 ReportFilterSpec filterSpec = null; 926 String mxDim = getMaxRowsDimension(); 927 if (!mxDim.equals("")) { 928 filterSpec = new ReportFilterSpec(); 929 filterSpec.setName("MAXROWS"); 930 filterSpec.setFilterType(FilterDefinitionFilterTypeType.GREATERTHAN); 931 filterSpec.setVisual(true); 932 filterSpec.setDimensionName(mxDim); 933 } 934 return filterSpec; 935 } 936 937 private void collectEditFilterSpecs(Collection filterSpecs, List result) { 938 Iterator iterator = filterSpecs.iterator(); 939 while (iterator.hasNext()) { 940 ReportFilterSpec filterSpec = (ReportFilterSpec) iterator.next(); 941 if (filterSpec.getVisual()) { 942 result.add(filterSpec); 943 } 944 } 945 } 946 947 public Collection getEditFilterSpecs() { 948 List collection = new ArrayList(); 949 collectEditFilterSpecs(getFilterSpecs(), collection); 950 if (!getCached()) { 951 collectEditFilterSpecs(getPreFilterSpecs(), collection); 952 } 953 return collection; 954 } 955 956 public Collection getNotCalculatedDimensions() { 957 List notCalculatedDimensions = new ArrayList(); 958 964 Iterator iterator = getDimensionsByIndex().iterator(); 965 while(iterator.hasNext()){ 966 ReportDimensionSpec dim = (ReportDimensionSpec)iterator.next(); 967 if(!dim.getCalculated()){ 968 notCalculatedDimensions.add(dim); 969 } 970 } 971 return notCalculatedDimensions; 972 } 973 974 978 public boolean isVisibleTotals() { 979 return visibleTotals; 980 } 981 982 991 public List getColumnByIndex() { 992 List column = new ArrayList(); 993 column.addAll(getDimensionsByIndex()); 994 column.addAll(getMetricsByIndex()); 995 return column; 996 } 997 998 1006 public List getColumnTypesByIndex() { 1007 List columnTypes = new ArrayList(); 1008 Iterator itDimensions = getDimensionsByIndex().iterator(); 1009 Iterator itMetrics = getMetricsByIndex().iterator(); 1010 1011 while (itDimensions.hasNext()) { 1012 ReportDimensionSpec reportDimensionSpec = (ReportDimensionSpec) itDimensions.next(); 1013 if (!reportDimensionSpec.getCalculated()) { 1014 columnTypes.add(new Integer (reportDimensionSpec.getDataType().getType())); 1015 } 1016 } 1017 while (itMetrics.hasNext()) { 1018 ReportMetricSpec reportMetricSpec = (ReportMetricSpec) itMetrics.next(); 1019 if (!(reportMetricSpec.getCalculated())) { 1020 columnTypes.add(new Integer (2)); 1021 } 1022 } 1023 return columnTypes; 1024 } 1025 1026 1034 public Map getColumnTypesByName() { 1035 Map columnTypes = new HashMap(); 1036 Iterator itDimensions = getDimensionsByIndex().iterator(); 1037 Iterator itMetrics = getMetricsByIndex().iterator(); 1038 1039 while (itDimensions.hasNext()) { 1040 ReportDimensionSpec reportDimensionSpec = (ReportDimensionSpec) itDimensions.next(); 1041 if (!reportDimensionSpec.getCalculated()) { 1042 columnTypes.put(reportDimensionSpec.getName(), new Integer (reportDimensionSpec.getDataType().getType())); 1043 } 1044 } 1045 while (itMetrics.hasNext()) { 1046 ReportMetricSpec reportMetricSpec = (ReportMetricSpec) itMetrics.next(); 1047 if (!(reportMetricSpec.getCalculated())) { 1048 columnTypes.put(reportMetricSpec.getName(), new Integer (2)); 1049 } 1050 } 1051 return columnTypes; 1052 } 1053 1054 public Map getPosParamValues() { 1055 if (posParamValues == null) { 1056 posParamValues = new HashMap(); 1057 } 1058 return posParamValues; 1059 } 1060 1061 public Map getPreParamValues() { 1062 if (preParamValues == null) { 1063 preParamValues = new HashMap(); 1064 } 1065 return preParamValues; 1066 1067 } 1068 1069 1073 public Collection getNotCalculatedMetrics() { 1074 List notCalculatedMetrics = new ArrayList(); 1075 for (Iterator iterator = getMetricsByIndex().iterator(); iterator.hasNext();) { 1076 ReportMetricSpec metricSpec = (ReportMetricSpec) iterator.next(); 1077 if (!metricSpec.getCalculated()) { 1078 notCalculatedMetrics.add(metricSpec); 1079 } 1080 } 1081 return notCalculatedMetrics; 1082 } 1083 1084 1089 public String getDataSourceIndexNameByIndex(int index) { 1090 Iterator iter = getDataSourceIndexes().entrySet().iterator(); 1091 boolean find = false; 1092 String returnValue = ""; 1093 while (iter.hasNext() && !find) { 1094 Map.Entry entry = (Map.Entry) iter.next(); 1095 if (((Integer ) entry.getValue()).intValue() == index) { 1096 returnValue = entry.getKey().toString(); 1097 find = true; 1098 } 1099 } 1100 return returnValue; 1101 } 1102 1103 public void setLayoutDesign(String layoutDesign) { 1104 LayoutDesign = layoutDesign; 1105 } 1106 1107 public String getLayoutDesign() { 1108 return LayoutDesign; 1109 } 1110 1111 public ReportFilterSpec getFilterSpecFromParamName(String paramName) { 1112 ReportFilterSpec filterSpec = doGetFilterSpecFromParamName(getFilterSpecs(), paramName); 1113 if (filterSpec == null) { 1114 filterSpec = doGetFilterSpecFromParamName(getPreFilterSpecs(), paramName); 1115 } 1116 return filterSpec; 1117 } 1118 1119 1120 protected ReportFilterSpec doGetFilterSpecFromParamName(Collection filters, String paramName) { 1121 if(filters != null){ 1122 Iterator iterator = filters.iterator(); 1123 while (iterator.hasNext()) { 1124 ReportFilterSpec reportFilterSpec = (ReportFilterSpec) iterator.next(); 1125 if (reportFilterSpec.includesParam(paramName)) { 1126 return reportFilterSpec; 1127 } 1128 } 1129 } 1130 return null; 1131 } 1132 1133 public Object [] getVisibleDimensionsByGrouping(boolean grouping) { 1134 Collection result = new Vector(); 1135 Object [] dims; 1136 if(grouping){ 1137 dims = getGroupingDimensions(); 1138 }else{ 1139 dims = getNonGroupingDimensions(); 1140 } 1141 for(int i=0; i < dims.length; i++){ 1142 if(((ReportDimensionSpec)dims[i]).getLocation()!=null){ 1143 result.add(dims[i]); 1144 } 1145 } 1146 return result.toArray(); 1147 } 1148 1149 public String getInfoPage() { 1150 return infoPage; 1151 } 1152 1153 public void setInfoPage(String infoPage) { 1154 this.infoPage = infoPage; 1155 } 1156 1157 public boolean getDatawarehouseSaved() { 1158 return this.datawarehouseSaved; 1159 } 1160 1161 public Iterator getIndexedColumns() { 1162 Predicate predicate = new Predicate(){ 1163 public boolean evaluate(Object o){ 1164 return ((ReportDimensionSpec)o).isIndexed(); 1165 } 1166 }; 1167 return new FilterIterator(getDimensionsByIndex().iterator(), predicate); 1168 } 1169} 1170 1171 1172 | Popular Tags |