Coverage Report - ar.com.fdvs.dj.domain.DynamicReport
 
Classes in this File Line Coverage Branch Coverage Complexity
DynamicReport
76%
120/157
83%
5/6
1.04
 
 1  
 /*
 2  
  * DynamicJasper: A library for creating reports dynamically by specifying
 3  
  * columns, groups, styles, etc. at runtime. It also saves a lot of development
 4  
  * time in many cases! (http://sourceforge.net/projects/dynamicjasper)
 5  
  *
 6  
  * Copyright (C) 2008  FDV Solutions (http://www.fdvsolutions.com)
 7  
  *
 8  
  * This library is free software; you can redistribute it and/or
 9  
  * modify it under the terms of the GNU Lesser General Public
 10  
  *
 11  
  * License as published by the Free Software Foundation; either
 12  
  *
 13  
  * version 2.1 of the License, or (at your option) any later version.
 14  
  *
 15  
  * This library is distributed in the hope that it will be useful,
 16  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17  
  *
 18  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19  
  *
 20  
  * Lesser General Public License for more details.
 21  
  *
 22  
  * You should have received a copy of the GNU Lesser General Public
 23  
  * License along with this library; if not, write to the Free Software
 24  
  *
 25  
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 26  
  *
 27  
  *
 28  
  */
 29  
 
 30  
 package ar.com.fdvs.dj.domain;
 31  
 
 32  
 import ar.com.fdvs.dj.core.DJConstants;
 33  
 import ar.com.fdvs.dj.domain.builders.StyleBuilder;
 34  
 import ar.com.fdvs.dj.domain.constants.Stretching;
 35  
 import ar.com.fdvs.dj.domain.entities.DJVariable;
 36  
 import ar.com.fdvs.dj.domain.entities.Entity;
 37  
 import ar.com.fdvs.dj.domain.entities.Parameter;
 38  
 import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;
 39  
 import ar.com.fdvs.dj.domain.entities.columns.ExpressionColumn;
 40  
 import ar.com.fdvs.dj.domain.entities.columns.SimpleColumn;
 41  
 
 42  
 import java.util.*;
 43  
 
 44  
 /**
 45  
  * One of the main classes of this product. It represents the report itself.
 46  
  */
 47  
 public class DynamicReport extends DJBaseElement {
 48  
 
 49  
         private static final long serialVersionUID = Entity.SERIAL_VERSION_UID;
 50  
         
 51  
         private String reportName;
 52  
 
 53  
 
 54  
     /**
 55  
      Sets the language of the expressions used in the report
 56  
      * (can be one of java, groovy, or javascript).
 57  
      *
 58  
      * Default is DJConstants#REPORT_LANGUAGE_JAVA
 59  
      *
 60  
      * @see DJConstants#REPORT_LANGUAGE_JAVA
 61  
      *      DJConstants#REPORT_LANGUAGE_GROOVY
 62  
      *      DJConstants#REPORT_LANGUAGE_JAVASCRIPT
 63  
      *
 64  
      */
 65  165
     private String language = DJConstants.REPORT_LANGUAGE_JAVA;
 66  
 
 67  
     private String title;
 68  165
         private boolean titleIsJrExpression = false;
 69  
         
 70  
         private String subtitle;
 71  165
         private Style titleStyle = new StyleBuilder(false,"reportTitleStyle")
 72  
                                                                 .setStretching(Stretching.NO_STRETCH)
 73  
                                                                 .build();
 74  165
         private Style subtitleStyle = new StyleBuilder(false,"reportSubtitleStyle")
 75  
                                                                         .setStretching(Stretching.NO_STRETCH)
 76  
                                                                         .build();
 77  
 
 78  165
         private Locale reportLocale = Locale.getDefault();
 79  165
         private String resourceBundle = null;
 80  
 
 81  165
         protected Map fontsMap = new HashMap(); //<String, java.awt.Font>
 82  
 
 83  165
         private List<AbstractColumn> columns = new ArrayList<AbstractColumn>();
 84  
 
 85  
         //<ColumnsGroup>
 86  165
         private List columnsGroups = new ArrayList();
 87  
 
 88  
         //<DJChart>
 89  165
         private List charts = new ArrayList();
 90  
 
 91  
         //<DJChart>
 92  165
         private List newCharts = new ArrayList();
 93  
         
 94  
         private DynamicReportOptions options;
 95  
 
 96  
         /**
 97  
          * List of ColumnProperty
 98  
          * Other fields to register, not necessary assigned to columns
 99  
          */
 100  165
         private List fields = new ArrayList();
 101  
 
 102  
         //Other parameters needed (E.g. Subreports)
 103  165
         private List parameters = new ArrayList();
 104  
         
 105  165
         private List<DJVariable> variables = new ArrayList<DJVariable>();
 106  
 
 107  165
         private Map properties = new HashMap();
 108  
 
 109  165
         private String templateFileName = null;
 110  165
         private boolean templateImportDatasets = false;
 111  165
         private boolean templateImportFields = false;
 112  165
         private boolean templateImportVariables = false;
 113  165
         private boolean templateImportParameters = true;
 114  
 
 115  165
         private List autoTexts = new ArrayList();
 116  
 
 117  165
         private Map styles = new LinkedHashMap();
 118  
 
 119  
         private DJQuery query;
 120  
 
 121  
         private String whenNoDataText;
 122  
         private Style  whenNoDataStyle;
 123  165
         private boolean whenNoDataShowTitle = true;
 124  165
         private boolean whenNoDataShowColumnHeader = true;
 125  
 
 126  165
         private boolean allowDetailSplit = true;
 127  
 
 128  
         /**
 129  
          * Defines the behaviour when the datasource is empty.
 130  
          * Valid values are:
 131  
          * DJConstants.WHEN_NO_DATA_TYPE_NO_PAGES
 132  
          * DJConstants.WHEN_NO_DATA_TYPE_BLANK_PAGE
 133  
          * DJConstants.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL
 134  
          * DJConstants.WHEN_NO_DATA_TYPE_NO_DATA_SECTION
 135  
          *
 136  
          * Defatul is: DJConstants.WHEN_NO_DATA_TYPE_NO_PAGES
 137  
          */
 138  165
         private byte whenNoDataType = DJConstants.WHEN_NO_DATA_TYPE_NO_PAGES;
 139  
 
 140  
         /**********************
 141  
          * Defines what to show if a missing resource is referenced
 142  
          * Possible values are:<br>
 143  
          * DJConstants.WHEN_RESOURCE_MISSING_TYPE_EMPTY: Leaves and empty field.<br/>
 144  
          * DJConstants.WHEN_RESOURCE_MISSING_TYPE_ERROR: Throwns and exception.<br/>
 145  
          * DJConstants.WHEN_RESOURCE_MISSING_TYPE_KEY: Shows the key of the missing resource.<br/>
 146  
          * DJConstants.WHEN_RESOURCE_MISSING_TYPE_NULL: returns NULL
 147  
          **********************/
 148  165
         private byte whenResourceMissing = DJConstants.WHEN_RESOURCE_MISSING_TYPE_KEY;
 149  
 
 150  
 
 151  
         public void addStyle(Style style) {
 152  2
                 styles.put(style.getName(), style);
 153  2
         }
 154  
 
 155  
         public Map getStyles() {
 156  116
                 return styles;
 157  
         }
 158  
 
 159  
         public void setStyles(Map styles) {
 160  0
                 this.styles = styles;
 161  0
         }
 162  
 
 163  
         public void setProperty(String name, String value) {
 164  2
                 properties.put(name, value);
 165  2
         }
 166  
 
 167  330
         public DynamicReport() {}
 168  
 
 169  0
         public DynamicReport(String title, List columns, List columnsGroups, List charts, DynamicReportOptions options) {
 170  0
                 this.title = title;
 171  0
                 this.columns = columns;
 172  0
                 this.columnsGroups = columnsGroups;
 173  0
                 this.charts = charts;
 174  0
                 this.options = options;
 175  0
         }
 176  
 
 177  
         public String getTitle() {
 178  208
                 return title;
 179  
         }
 180  
 
 181  
         public void setTitle(String title) {
 182  89
                 this.title = title;
 183  89
         }
 184  
 
 185  
         public List<AbstractColumn> getColumns() {
 186  1965
                 return columns;
 187  
         }
 188  
 
 189  
         public void setColumns(List<AbstractColumn> columns) {
 190  0
                 this.columns = columns;
 191  0
         }
 192  
 
 193  
         public List getColumnsGroups() {
 194  3024
                 return columnsGroups;
 195  
         }
 196  
 
 197  
         public void setColumnsGroups(List columnsGroups) {
 198  0
                 this.columnsGroups = columnsGroups;
 199  0
         }
 200  
 
 201  
         public DynamicReportOptions getOptions() {
 202  4237
                 return options;
 203  
         }
 204  
 
 205  
         public void setOptions(DynamicReportOptions options) {
 206  111
                 this.options = options;
 207  111
         }
 208  
 
 209  
         public String getSubtitle() {
 210  160
                 return subtitle;
 211  
         }
 212  
 
 213  
         public void setSubtitle(String subtitle) {
 214  69
                 this.subtitle = subtitle;
 215  69
         }
 216  
 
 217  
         public Style getSubtitleStyle() {
 218  67
                 return subtitleStyle;
 219  
         }
 220  
 
 221  
         public void setSubtitleStyle(Style subtitleStyle) {
 222  7
                 this.subtitleStyle = subtitleStyle;
 223  7
         }
 224  
 
 225  
         public Style getTitleStyle() {
 226  161
                 return titleStyle;
 227  
         }
 228  
 
 229  
         public void setTitleStyle(Style titleStyle) {
 230  34
                 this.titleStyle = titleStyle;
 231  34
         }
 232  
 
 233  
         public void setTitleStyle(Style titleStyle, boolean isExp) {
 234  0
                 this.titleStyle = titleStyle;
 235  0
                 this.titleIsJrExpression = isExp;
 236  0
         }
 237  
 
 238  
         public String getTemplateFileName() {
 239  140
                 return templateFileName;
 240  
         }
 241  
 
 242  
         public void setTemplateFileName(String templateFileName) {
 243  7
                 this.templateFileName = templateFileName;
 244  7
         }
 245  
 
 246  
         public List getFields() {
 247  154
                 return fields;
 248  
         }
 249  
 
 250  
         public void setFields(List fields) {
 251  0
                 this.fields = fields;
 252  0
         }
 253  
 
 254  
         public List getCharts() {
 255  160
                 return charts;
 256  
         }
 257  
 
 258  
         public void setCharts(List charts) {
 259  0
                 this.charts = charts;
 260  0
         }
 261  
 
 262  
         public List getNewCharts() {
 263  333
                 return newCharts;
 264  
         }
 265  
 
 266  
         public void setNewCharts(List charts) {
 267  0
                 this.newCharts = charts;
 268  0
         }
 269  
         
 270  
         public List getAutoTexts() {
 271  310
                 return autoTexts;
 272  
         }
 273  
 
 274  
         public void setAutoTexts(List autoTexts) {
 275  111
                 this.autoTexts = autoTexts;
 276  111
         }
 277  
 
 278  
         public Locale getReportLocale() {
 279  351
                 return reportLocale;
 280  
         }
 281  
 
 282  
         public void setReportLocale(Locale reportLocale) {
 283  3
                 this.reportLocale = reportLocale;
 284  3
         }
 285  
 
 286  
         public String getResourceBundle() {
 287  116
                 return resourceBundle;
 288  
         }
 289  
 
 290  
         public void setResourceBundle(String resourceBundle) {
 291  0
                 this.resourceBundle = resourceBundle;
 292  0
         }
 293  
 
 294  
         public DJQuery getQuery() {
 295  130
                 return query;
 296  
         }
 297  
 
 298  
         public void setQuery(DJQuery query) {
 299  4
                 this.query = query;
 300  4
         }
 301  
 
 302  
         public Map getFontsMap() {
 303  0
                 return fontsMap;
 304  
         }
 305  
 
 306  
         public void setFontsMap(Map fontsMap) {
 307  0
                 this.fontsMap = fontsMap;
 308  0
         }
 309  
 
 310  
         public byte getWhenNoDataType() {
 311  116
                 return whenNoDataType;
 312  
         }
 313  
 
 314  
         public void setWhenNoDataType(byte whenNoDataType) {
 315  7
                 this.whenNoDataType = whenNoDataType;
 316  7
         }
 317  
 
 318  
         public byte getWhenResourceMissing() {
 319  116
                 return whenResourceMissing;
 320  
         }
 321  
 
 322  
         public void setWhenResourceMissing(byte whenResourceMissing) {
 323  0
                 this.whenResourceMissing = whenResourceMissing;
 324  0
         }
 325  
 
 326  
         public String getWhenNoDataText() {
 327  116
                 return whenNoDataText;
 328  
         }
 329  
 
 330  
         public void setWhenNoDataText(String whenNoDataText) {
 331  2
                 this.whenNoDataText = whenNoDataText;
 332  2
         }
 333  
 
 334  
         public Style getWhenNoDataStyle() {
 335  116
                 return whenNoDataStyle;
 336  
         }
 337  
 
 338  
         public void setWhenNoDataStyle(Style whenNoDataStyle) {
 339  2
                 this.whenNoDataStyle = whenNoDataStyle;
 340  2
         }
 341  
 
 342  
         public boolean isWhenNoDataShowTitle() {
 343  3
                 return whenNoDataShowTitle;
 344  
         }
 345  
 
 346  
         public void setWhenNoDataShowTitle(boolean whenNoDataShowTitle) {
 347  1
                 this.whenNoDataShowTitle = whenNoDataShowTitle;
 348  1
         }
 349  
 
 350  
         public boolean isWhenNoDataShowColumnHeader() {
 351  3
                 return whenNoDataShowColumnHeader;
 352  
         }
 353  
 
 354  
         public void setWhenNoDataShowColumnHeader(boolean whenNoDataShowColumnHeader) {
 355  1
                 this.whenNoDataShowColumnHeader = whenNoDataShowColumnHeader;
 356  1
         }
 357  
 
 358  
         public List getParameters() {
 359  116
                 return parameters;
 360  
         }
 361  
         
 362  
         public void addParameter(String name, String className){
 363  2
                 this.parameters.add(new Parameter(name, className));
 364  2
         }
 365  
 
 366  
         public void setParameters(List parameters) {
 367  0
                 this.parameters = parameters;
 368  0
         }
 369  
 
 370  
         public boolean isAllowDetailSplit() {
 371  108
                 return allowDetailSplit;
 372  
         }
 373  
 
 374  
         public void setAllowDetailSplit(boolean allowDetailSplit) {
 375  0
                 this.allowDetailSplit = allowDetailSplit;
 376  0
         }
 377  
 
 378  
    public boolean isTemplateImportDatasets() {
 379  8
                 return templateImportDatasets;
 380  
         }
 381  
 
 382  
         public void setTemplateImportDatasets(boolean templateImportDatasets) {
 383  1
                 this.templateImportDatasets = templateImportDatasets;
 384  1
         }
 385  
 
 386  
         public boolean isTemplateImportFields() {
 387  8
                 return templateImportFields;
 388  
         }
 389  
 
 390  
         public void setTemplateImportFields(boolean templateImportFields) {
 391  1
                 this.templateImportFields = templateImportFields;
 392  1
         }
 393  
 
 394  
         public boolean isTemplateImportVariables() {
 395  8
                 return templateImportVariables;
 396  
         }
 397  
 
 398  
         public void setTemplateImportVariables(boolean templateImportVariables) {
 399  1
                 this.templateImportVariables = templateImportVariables;
 400  1
         }
 401  
 
 402  
         public boolean isTemplateImportParameters() {
 403  8
                 return templateImportParameters;
 404  
         }
 405  
 
 406  
         public void setTemplateImportParameters(boolean templateImportParameters) {
 407  1
                 this.templateImportParameters = templateImportParameters;
 408  1
         }
 409  
 
 410  
         public Map getProperties() {
 411  109
                 return properties;
 412  
         }
 413  
 
 414  
         /**
 415  
          * Must be a Map<String, String>
 416  
          * @param properties
 417  
          */
 418  
         public void setProperties(Map properties) {
 419  0
                 this.properties = properties;
 420  0
         }
 421  
 
 422  
         public String getReportName() {
 423  117
                 return reportName;
 424  
         }
 425  
 
 426  
         public void setReportName(String reportName) {
 427  1
                 this.reportName = reportName;
 428  1
         }
 429  
         
 430  
         /**
 431  
          * 
 432  
          * @return List<ColumnProperty>
 433  
          */
 434  
         public List getAllFields(){
 435  10
                 ArrayList l = new ArrayList();
 436  10
                 for (Iterator iter = this.columns.iterator(); iter.hasNext();) {
 437  60
                         Object o = iter.next();
 438  60
                         ColumnProperty columnProperty = null;
 439  
 
 440  60
                         if (o instanceof SimpleColumn && !(o instanceof ExpressionColumn)) {
 441  50
                                 SimpleColumn propcol = (SimpleColumn)o;
 442  50
                                 columnProperty = propcol.getColumnProperty();
 443  50
                                 l.add(columnProperty);
 444  
                         }
 445  60
                 }
 446  
                 
 447  10
                 l.addAll(this.getFields());
 448  
 
 449  10
                 return l;
 450  
                 
 451  
         }
 452  
 
 453  
         public boolean isTitleIsJrExpression() {
 454  93
                 return titleIsJrExpression;
 455  
         }
 456  
 
 457  
         public void setTitleIsJrExpression(boolean titleIsJrExpression) {
 458  1
                 this.titleIsJrExpression = titleIsJrExpression;
 459  1
         }
 460  
 
 461  
         public List<DJVariable> getVariables() {
 462  117
                 return variables;
 463  
         }
 464  
 
 465  
         public void setVariables(List<DJVariable> variables) {
 466  0
                 this.variables = variables;
 467  0
         }
 468  
 
 469  
     public String getLanguage() {
 470  216
         return language;
 471  
     }
 472  
 
 473  
     /**
 474  
      * @see DynamicReport#language
 475  
      * @param language
 476  
      */
 477  
     public void setLanguage(String language) {
 478  1
         this.language = language;
 479  1
     }
 480  
 
 481  
 }